1.
A data structure is a way of organizing and storing data so that it can be accessed and modified
efficiently.
Examples:
Linear: Array, Linked List
Non-linear: Tree, Graph
2. Arrays are collections of elements stored in contiguous memory locations, while linked lists
consist of nodes that contain data and pointers to the next node.
3. Time complexity is a way to express the amount of time an algorithm takes to run as a function of
the input size.
Worst-case time complexity of linear search: O(n)
4. Overflow occurs when trying to push an element into a full stack. Underflow happens when trying
to pop an element from an empty stack.
5. Space complexity is the amount of memory an algorithm uses as a function of the input size.
Example: A recursive function may use stack space for function calls.
6. A stack is a linear data structure that follows the Last In First Out (LIFO) principle.
Applications: Undo functionality in editors, browser history.
7. Height of a tree is the number of edges on the longest path from root to a leaf node.
Height of a BST with 7 nodes (assuming it's balanced): 2
8. A circular queue connects the last position back to the first position, allowing efficient utilization of
space compared to a linear queue.
9. Postfix form of (A + B) * (C - D / E) is: A B + C D E / - *
10. Hashing is a technique to convert a large key into a small index.
Collision in hashing occurs when two keys hash to the same index.
11. A circular queue reuses empty spaces left by dequeued elements, reducing memory wastage
unlike linear queues which can't reuse space.
12. A binary tree is a data structure in which each node has at most two children.
Full binary tree: Every node has 0 or 2 children.
Complete binary tree: All levels are completely filled except possibly the last.
13. Dynamic memory allocation in linked lists allows allocation of memory at runtime using pointers,
unlike arrays with fixed size.
14. Recursive formula for Fibonacci series: F(n) = F(n-1) + F(n-2), F(0)=0, F(1)=1
F(5) = 5
15. Binary search is a searching algorithm that works on sorted arrays.
Condition: The list must be sorted.
16. Steps to insert node at beginning of singly linked list:
1. Create a new node.
2. Point new node's next to head.
3. Move head to point to the new node.
17. Divide and conquer solves problems by dividing into subproblems, solving them independently,
then combining results (e.g., Merge Sort).
Greedy algorithms make locally optimal choices hoping for global optimum (e.g., Kruskal's
algorithm).
18. Recursion is a method where the solution depends on solutions to smaller instances of the same
problem.
Example factorial: fact(n) = n * fact(n-1)
19. Stack using array pseudocode:
Push(x):
if top == size - 1: Overflow
else: top++, arr[top] = x
Pop():
if top == -1: Underflow
else: return arr[top--]
20. A priority queue is a special type of queue in which each element is associated with a priority.
Unlike normal queues, elements with higher priority are dequeued before lower priority.