SHRI. G.P.M. DEGREE COLLEGE 2025 - 2026 Name:.________________________________________________________ Std:.___________________________________________________________ Department:.____________________________________________________ Branch:.________________________________________________________ Div:.__________________________________________________________ Rollno:.________________________________________________________ SHRI G.P.M. DEGREE COLLEGE MG Road, Vile Parle (E), Mumbai - 400057 Tel.: 8928387199 CERTIFICATE This is certified that Mr./Ms.____________________________________________ a Student of F.Y. B.Sc.C.S. Roll No. ________ has completed the Number Of Practical In the Subject of Design & Analysis of Algorithms as Prescribed by the University of Mumbai under my Supervision during the academic year 2025 - 2 6. Signatories: Subject In - charge (Name & Sign): _____________________ Principal Sign (Name & Sign): ________________________ External Examiner (Name & Sign): ____________________ Date: - __________________________ College Stamp Prof. name : Ms. Jayashree Patade Class/SEM : F.Y.BSC.CS / SEM III (2025 - 2026) Course code : Major Practical 2 Subject name : Design and Analysis of Algorithm Sr. No Date Topics Page No Signature 1 Array Operations a 17/11/2025 Write a program to read n elements into a 1 - D array and print the largest number. b 17/11/2025 Write a program to read a matrix of size m × n and find the sum of all elements. c 17/11/2025 Write a program to accept a 2 - D array and determine the largest element present in it. d 17/11/2025 Write a program to input n numbers into an array and display the reversed array. 2 Stack and List Operation a 24/11/2025 Write a program to perform the following operations: Push three elements into the stack Pop the top element Display the final stack b 24/11/2025 Write a program to convert a given infix expression (e.g., A+B*C ) into its postfix form using a stack. c 2 8/11/2025 Write a program for evaluation of postfix expressions. d 1/12/2025 Write a program to perform following operations Add note at start Add node at position i Delete node Traverse list 3 Recursion a 5/12/2025 Write a program to generate the Fibonacci series up to N terms using a recursive approach. b 5/12/202 5 Write a program that uses recursion to find the factorial of a given positive integer. 4 Searching Techniques a 8/ 12 /2025 Write a program in Python to perform Linear Search on a list of elements. b 8/ 12/2025 Write a program in Python to perform Binary Search on a sorted list of integers. 5 Sorting Techniques a 10/12/2025 Write a program to sort a list of integers using the Bubble Sort algorithm. b 12/12/2025 Write a program to sort a list of integers using the Selection Sort algorithm. c 15/12/2025 Write a program to sort a list of integers using the Insertion Sort Algorithm 6 Nth Min/Max Element a Create a program that asks the user whether they want to find the Nth minimum or Nth maximum element. Based on the user’s choice, compute and return the respective element from the given list of numbers. 7 String Pattern Matching 19/01/2026 Brute force Algorithm Write a program to implement the Brute Force string matching algorithm to find a pattern inside a given text. 8 Greedy Algorithm a Design a program that performs data compression using Huffman Coding , a greedy algorithm to generate the most efficient binary code for each character based on its frequency. The program should output encoded text and the generated code table. 9 Divide and Conquer Algorithm a 2 3/01/2026 Write a program to sort an array of integers using the Merge Sort algorithm. b Design a program to implement Quick Sort using divide and conquer strategy. 10 Dynamic Programing a Write a program to compute the Nth Fibonacci number using Dynamic Programming. #Practical 1a: Create a program that asks the user to enter their name and their age. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Experiment No. — 1 : Array Operations Aim: Implement programs for 1 - d arrays, Implement programs for 2 - d arrays. Tools Used: Programming Language: C/C++/Python/Java (as per requirement) IDE: Code::Blocks, Dev - C++, Visual Studio Code, PyCharm, or any other compiler - supported environment Hardware: Standard PC or Laptop with necessary configurations Debugger: GDB (GNU Debugger) or built - in debugging to ols in IDEs Learning Objectives: 1. Understand the concept and representation of arrays in memory. 2. Learn the difference between 1 - D and 2 - D arrays and their applications. 3. Implement basic operations like insertion, deletion, searching, updating, and traversal in arrays. 4. Analyze the time complexity and space complexity of array operations. 5. Gain hands - on experience in handling multi - dimensional data using 2 - D arrays. Theory: 1. Introduction to Arrays An array is a linear data structure that stores a fixed - size sequential collection of elements of the same data type. It provides indexed access to elements, making retrieval operations efficient. Arrays are widely used due to their contiguous memory allocation , w hich allows for constant - time access to elements using their indices. Arrays are categorized into: 1. One - Dimensional (1 - D) Arrays: A linear collection of elements stored in a single row. 2. Two - Dimensional (2 - D) Arrays: A tabular representation where elements a re stored in a matrix - like format with rows and columns. 2. One - Dimensional Arrays (1 - D Arrays) A 1 - D array is a collection of elements that are stored in contiguous memory locations and accessed using a single index SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Memory Representation of a 1 - D Array: If an array A of size N is declared as A[N] , it will occupy memory locations sequentially: Index Address (Base + Index × Size) Element 0 Base + (0 × Size) A[0] 1 Base + (1 × Size) A[1] 2 Base + (2 × Size) A[2] ... ... ... N - 1 Base + ((N - 1) × Size) A[N - 1] Where Base is the starting memory address, and Size depends on the data type. Basic Operations on 1 - D Arrays: 1. Insertion: Placing an element at a specific index. 2. Deletion: Removing an element and shifting others accordingly. 3. Traversal: Accessing and processing each element sequentially. 4. Searching: Finding an element using Linear Search (O(N)) or Binary Search (O(log N) for sorted arrays). 5. Sorting: Arranging elements in ascending or descending order ( Bubble Sort, Merge Sort, Quick Sort ). Algorithm for Inserting an Element into a 1 - D Array: 1. Start the program and define the array. 2. Read the element to be inserted and the position where it should be placed. 3. Shift elements to the right to create space for the new element. 4. Insert the new element at the given index. 5. Print the updated array. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Algorithm for Searching an Element in a 1 - D Array (Linear Search): 1. Start the program and input the array. 2. Read the search key. 3. Traverse the array sequentially and compare each element with the key. 4. If found, return the index; otherwise, print "Element not found." 3. Two - Dimensional Arrays (2 - D Arrays) A 2 - D array is an extension of the 1 - D array, where data is stored in a tabular format (rows and columns). It is useful for matrix operations, image processing, and game de velopment Memory Representation of a 2 - D Array: A 2 - D array B[R][C] with R rows and C columns is stored in memory using two major techniques: 1. Row - Major Order: Stores elements row by row. ○ Address of B[i][j] = Base + [(i × C) + j] × Size 2. Column - Major Order: Stores elements column by column. ○ Address of B[i][j] = Base + [(j × R) + i] × Size Basic Operations on 2 - D Arrays: 1. Insertion: Adding an element at a specified row and column index. 2. Deletion: Removing an element and optionally shifting others. 3. Traversal: Accessing and processing each element row - wise or column - wise. 4. Searching: Finding an element within a matrix. 5. Matrix Operations: Addition, subtraction, multiplication, and transposition. Algorithm for Traversing a 2 - D Array: 1. Start the program and define a 2 - D array 2. Use nested loops to access each element: ○ Outer loop iterates through rows ○ Inner loop iterates through columns 3. Print each element in a matrix format Algorithm for Searching an Element in a 2 - D Array: 1. Start the program and input the 2 - D array. 2. Read the search key. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai 3. Use nested loops to check each row and column. 4. If found, return the position; otherwise, print "Element not found." Comparison of 1 - D and 2 - D Arrays: Feature 1 - D Array 2 - D Array Structure Linear Tabular (rows & columns) Indexing Single index (A[i]) Two indices (B[i][j]) Memory Usage Less (stores only elements) More (due to additional structure) Operations Easier to implement More complex (due to multiple dimensions) Application Lists, search algorithms Matrices, image processing, tabular data Applications of Arrays: ● 1 - D Arrays: Used for linear lists, search algorithms, sorting, and numerical computations. ● 2 - D Arrays: Used in matrices, image processing, dynamic programming, and databases. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Code: 1. Write a program to read n elements into a 1 - D array and print the largest number. 2. Write a program to read a matrix of size m × n and find the sum of all elements SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai 3. Write a program to accept a 2 - D array and determine the largest element present in it. 4 Write a program to input n numbers into an array and display the reversed array. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Output: 1 2 3 4 SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Learning Outcomes: 1. how to create and manipulate 1 - D and 2 - D arrays in Python. 2. learn to perform basic operations on arrays such as finding the largest element, calculating the sum of matrix elements, and reversing an array. 3. logical thinking and problem - solving skills by applying array concepts to real programming tasks. Course Outcomes: Student will be able to implement and understand the working of one - dimensional (1 - D) and two - dimensional (2 - D) arrays through different operations such as initialization, insertion, deletion, searching, and traversal. Conclusion: This experiment helps in building a strong foundation in array operations usin g Python. By working with both one - dimensional and two - dimensional arrays, students gain practical knowledge of handling data structures, performing computations, and implementing logical operations such as searching, summing, and reversing elements. These skills are essential for solving real - world programming problems and form the basis for understanding more advanced data structures and algorithms. Viva Questions: 1. What is the difference between a 1 - D array and a 2 - D array? 2. How is a 2 - D array stored in m emory? Explain row - major and column - major orders. 3. What is the time complexity of searching in a 1 - D array using Linear Search and Binary Search ? 4. What are the advantages of using arrays over linked lists? 5. How would you implement a matrix multiplication oper ation using a 2 - D array? For Faculty use: Correction Parameters Formative Assessment[40%] Timely Completion of Practical[40%] Attendance Learning Attitude[20%] SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Experiment No. — 2 : List - Based Stack Operations Aim: Create a list - based stack and perform stack operations. Tools Used: 1. Programming Language: C / C++ / Java / Python 2. IDE: Code::Blocks, Dev - C++, Visual Studio Code, PyCharm, or any compiler - supported environment 3. Debugger: GDB (GNU Debugger) or built - in debugging tools in IDEs 4. Standard PC or Laptop with necessary configurations Learning Objectives: ● Understand the concept of a stack and its LIFO (Last In, First Out) property. ● Implement a stack using a list (array - based dynamic implementation). ● Perform basic stack operations: 1. Push – Insert a n element into the stack. 2. Pop – Remove the top element from the stack. 3. Peek – View the top element without removing it. 4. Check for Empty Stack – Determine if the stack is empty. 5. Check for Full Stack – If a size constraint is imposed, check if the stack is f ull. ● Analyze time complexity and space complexity for stack operations. ● Learn applications of stacks in recursion, expression evaluation, and memory management. Theory: 1. Introduction to Stack A stack is a linear data structure that follows the Last In, F irst Out (LIFO) principle. This means that the last element inserted into the stack is the first one to be removed. Stacks can be implemented using: 1. List (Array - based Stack) – Uses a fixed - size or dynamically resized array. 2. Linked List Stack – Uses dynamic ally allocated nodes to allow flexible sizing. In this experiment, we focus on list - based stack implementation where elements are stored contiguously in memory. 2. Stack Operations and Their Functions SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Push Operation (Insertion) ● Adds an element to the top of the stack. ● If the stack is full, the operation may be restricted (in fixed - size implementations). Pop Operation (Deletion) ● Removes the topmost element from the stack. ● If the stack is empty, it results in an underflow condition Peek Operation (Top Element Retrieval) ● Retrieves the top element without modifying the stack. ● Used for checking the next element to be removed. Check If Stack is Empty ● Returns true if no elements are present in the stack. ● Used before performing a pop operation to avoid underf low. Check If Stack is Full (In Fixed - Size Stack) ● Returns true if the stack has reached its maximum capacity. 3. Memory Representation of a Stack (List - Based Stack Implementation) A stack can be represented as an array where: ● The bottom element is at index 0 ● The top element is at index Top (N - 1) for an N - element stack Index Element Remarks 0 A Bottom of the stack 1 B SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai 2 C 3 D Top of the stack The top pointer keeps track of the index of the last inserted element Algorithms for Stack Operations (List - Based Implementation) Algorithm for Push Operation: 1. Check if the stack is full (if applicable). 2. If not full, increment the top pointer 3. Insert the new element at the position Top 4. Display the updated stack. Algorithm for Pop Operation: 1. Check if the stack is empty. 2. If empty, display "Stack Underflow" 3. If not empty, retrieve and remove the top element. 4. Decrement the top pointer 5. Display the updated stack. Algorithm for Peek Operation: 1. Check if the stack is empty. 2. If empty, displ ay "Stack is empty" 3. Otherwise, return the topmost element without removing it. Algorithm for Checking If Stack is Empty: 1. If Top == - 1 , return True (Empty Stack) 2. Otherwise, return False (Stack has elements) Algorithm for Checking If Stack is Full (Fixed Size): 1. If Top == MAX_SIZE - 1 , return True (Stack Full) SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai 2. Otherwise, return False (Stack has space) Time Complexity Analysis of Stack Operations Operation Time Complexity Push O(1) Pop O(1) Peek O(1) IsEmpty O(1) IsFull (Fixed Size) O(1) Since all operations are performed on the topmost element , stacks provide constant - time operations, making them efficient. Applications of Stack in Real - World Scenarios 1. Expression Evaluation: Used in Infix - to - Postfix conversion , Postfix Evaluation , and Exp ression Parsing 2. Function Calls & Recursion: The call stack in programming languages follows a stack - based mechanism for handling recursive function calls. 3. Undo/Redo Mechanism: Text editors and applications use stacks for undo/redo operations. 4. Browser Back and Forward History: Web browsers maintain navigation history using stacks. 5. Memory Management: CPU uses stacks for managing memory, such as register allocation and function execution contexts SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Code: 1. Write a program to perform the following operations: Push three elements into the stack Pop the top element Display the final stack SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai 2. Write a program to convert a given infix expression (e.g., A+B*C) into its postfix form using a stack. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai 3. Write a program for evaluation of postfix expressions. SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE Department of Computer Affiliated to University of Mumbai Output: 1. 2 3. Learning Outcomes: 1. I mplement stack operations such as push, pop, and display using Python lists. 2. R eal applications like conversion of infix expressions to postfix and evaluation of postfix expressions 3. L ist operations including insertion at different positions, deletion, and traversal of elements.