1.Easy
What is a directed graph?
- AA graph whose edges have a direction from one vertex to another
- BA graph that has no cycles
- CA graph in which every pair of distinct vertices is joined by an edge
- DA graph whose edges all have weights
2.Easy
In an undirected graph, what is the degree of a vertex?
- AThe number of edges connected to it
- BThe length of the longest path from it
- CThe number of vertices in the graph
- DIts position in the adjacency list
3.Easy
In a tree, what is a leaf?
- AA node with no children
- BA node with no parent
- CThe node with the largest value
- DA node with exactly one child
4.Medium
The keys 50, 30, 70, 20, 40 are inserted in this order into an empty binary search tree. What is the left child of 30?
- A20
- B70
- C40
- D50
5.Medium
A binary tree has root 1 with left child 2 and right child 3; node 2 has children 4 (left) and 5 (right). What is the postorder traversal?
- A4 2 5 1 3
- B1 2 4 5 3
- C5 4 3 2 1
- D4 5 2 3 1
6.Medium
In a binary heap stored in an array starting at index 0, where is the parent of the node at index i?
- AAt index ⌊(i − 1) / 2⌋
- BAt index ⌊i / 2⌋ + 1
- CAt index 2i + 1
- DAt index i − 1
7.Hard
How can you detect whether a singly linked list contains a cycle using O(1) extra memory?
- AMove one pointer by one step and another by two steps and check whether they meet
- BStore every visited node in a hash set
- CCount the nodes until the count exceeds the list length field
- DSort the list and look for duplicates
8.Hard
A dynamic array doubles when full. Why do many implementations shrink it only when it is one quarter full, not half full?
- ATo avoid repeated resizing when pushes and pops alternate near the boundary
- BBecause halving at one half would lose elements
- CTo keep the array sorted
- DBecause the memory allocator can only release memory in quarters of a block
Answer key
- 1. A · A graph whose edges have a direction from one vertex to another
- 2. A · The number of edges connected to it
- 3. A · A node with no children
- 4. A · 20
- 5. D · 4 5 2 3 1
- 6. A · At index ⌊(i − 1) / 2⌋
- 7. A · Move one pointer by one step and another by two steps and check whether they meet
- 8. A · To avoid repeated resizing when pushes and pops alternate near the boundary
Full step-by-step solutions: practise this topic on examproblems.com.