DSA_Assignment_Answers
DSA_Assignment_Answers
1. A data structure is a way of organizing and storing data to perform operations efficiently.
Examples of linear data structures: Array, Linked List. Examples of non-linear data structures: Tree,
Graph.
2. An array stores elements in contiguous memory and has a fixed size, whereas a linked list
consists of nodes that contain data and a pointer to the next node, allowing dynamic memory
allocation.
3. Time complexity indicates how the runtime of an algorithm increases with input size. In linear
search, the worst-case time complexity is O(n), where n is the number of elements in the array.
4. In stacks, overflow occurs when we try to push an element into a full stack. Underflow occurs
when we try to pop an element from an empty stack, both leading to errors.
5. Space complexity is the amount of memory used by an algorithm during its execution. For
example, an algorithm that sorts an array without extra space has O(1) space complexity.
6. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Real-life
7. The height of a tree is the number of edges on the longest path from the root to a leaf. A BST with
8. A queue is a linear structure that follows FIFO order, while a circular queue connects the last
position back to the first, utilizing memory more efficiently and avoiding unused space.
9. The postfix expression of (A + B) * (C - D / E) is: AB+CDE/-*. This form eliminates the need for
10. Hashing is a technique for mapping data to a fixed-size table using a hash function. Collision
occurs when two keys map to the same index in the hash table.
11. A circular queue connects the end of the queue back to the front, allowing efficient use of
memory by reusing freed spaces, which is not possible in a simple linear queue.
12. A binary tree is a hierarchical structure where each node has at most two children. A full binary
tree has all nodes with 0 or 2 children, while a complete one is filled level-wise.
13. Dynamic memory allocation in linked lists allows memory to be allocated at runtime using
14. The recursive formula for Fibonacci is: fib(n) = fib(n-1) + fib(n-2), with base cases fib(0)=0,
15. Binary search is an efficient algorithm for finding an element in a sorted array. It requires that the
16. To insert a node at the beginning of a singly linked list: create a new node, point its next to the
17. Divide and conquer splits the problem into subproblems (e.g., merge sort), while greedy
algorithms make local optimal choices (e.g., Kruskal's algorithm). Both solve problems but use
different strategies.
18. Recursion is a technique where a function calls itself to solve smaller instances of the problem.
19. Push pseudocode: if top == size-1 then overflow else top++, stack[top] = item. Pop pseudocode:
20. A priority queue assigns priority to elements. The highest priority is dequeued first, unlike a