4. Programming & Data Structures
4. Programming & Data Structures
● Operations:
○ Push: Insert at top (O(1)).
○ Pop: Remove from top (O(1)).
○ Peek: View top element (O(1)).
● Applications: Function call stack, undo operations.
● Operations:
○ Enqueue: Insert at rear (O(1)).
○ Dequeue: Remove from front (O(1)).
● Variants:
○ Circular Queue: Efficient space usage.
○ Priority Queue: Serves highest priority first.
3. Linked Lists
4. Trees
● Properties:
○ Each node has ≤ 2 children.
○ Maximum nodes at level L = 2^L.
● Traversals:
○ Inorder (LNR): Left → Root → Right.
○ Preorder (NLR): Root → Left → Right.
○ Postorder (LRN): Left → Right → Root.
5. Graphs
MCQS
1. Introduction to Algorithms & Complexity
3. Linked Lists
4. Trees
16.In a binary tree, the maximum number of nodes at level *i* is:
a) *i*
b) 2i
c) 2^i
d) i²
Answer: c) 2^i
17.Postorder traversal of A(B,C) gives:
a) ABC
b) BAC
c) BCA
d) CBA
Answer: c) BCA
18.An AVL tree ensures balance by:
a) Rotations
b) Hashing
c) Randomization
d) Indexing
Answer: a) Rotations
19.B-trees are commonly used in:
a) Databases
b) Stacks
c) Queues
d) Sorting
Answer: a) Databases
20.The height of a BST with *n* nodes can be:
a) O(log n)
b) O(n)
c) Both a & b
d) O(1)
Answer: c) Both a & b
5. Graphs
9. Trees (Advanced)
46.The worst-case height of an AVL tree with *n* nodes is:
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
47.In a B-tree of order *m*, each node has at most:
a) *m* children
b) *m-1* keys
c) Both a & b
d) *m+1* keys
Answer: c) Both a & b
48.A B+ tree differs from a B-tree in that:
a) All data is stored in leaves
b) Internal nodes store keys only
c) Supports range queries efficiently
d) All of the above
Answer: d) All of the above
49.Threaded binary trees are used to:
a) Replace pointers with threads
b) Enable inorder traversal without recursion/stack
c) Reduce memory usage
d) All of the above
Answer: d) All of the above
50.The inorder successor of a node in a BST is the:
a) Smallest node in the right subtree
b) Largest node in the left subtree
c) Parent node
d) Root node
Answer: a) Smallest node in the right subtree