What is a data structure?
- A. A type of database only
- B. A way of organizing and storing data for efficient use (correct)
- C. A programming language
- D. A sorting algorithm
What does an algorithm's time complexity measure?
- A. The year it was invented
- B. The memory of the computer
- C. The number of lines of code
- D. How its running time grows as the input size grows (correct)
Which data structure follows FIFO (first in, first out)?
- A. Queue (correct)
- B. Stack
- C. Tree
- D. Graph
Which operation adds an element to the top of a stack?
- A. Push (correct)
- B. Enqueue
- C. Peek
- D. Pop
Which operation removes the top element of a stack?
- A. Pop (correct)
- B. Dequeue
- C. Push
- D. Insert
What is the time complexity of accessing an array element by index?
- A. O(n)
- B. O(log n)
- C. O(1) (correct)
- D. O(n^2)
In a singly linked list, each node stores data and what?
- A. A pointer to the previous node only
- B. The list length
- C. A pointer to the next node (correct)
- D. An index
What is the first node of a linked list called?
- A. Tail
- B. Leaf
- C. Root
- D. Head (correct)
What is the top node of a tree called?
- A. Parent of all leaves only
- B. Head
- C. Leaf
- D. Root (correct)
A node with no children in a tree is called a:
- A. Edge
- B. Leaf (correct)
- C. Branch
- D. Root
How many children can each node have in a binary tree at most?
- A. 1
- B. Unlimited
- C. 2 (correct)
- D. 3
What does Big O notation describe?
- A. The memory address of data
- B. How an algorithm's time or space grows with input size (correct)
- C. The size of the code
- D. The exact running time in seconds
What is the time complexity of linear search?
- A. O(1)
- B. O(n) (correct)
- C. O(log n)
- D. O(n log n)
What does binary search require?
- A. A linked list
- B. A hash table
- C. A sorted collection (correct)
- D. Unique values only
What is the time complexity of binary search?
- A. O(1)
- B. O(log n) (correct)
- C. O(n)
- D. O(n^2)
What is recursion?
- A. A type of array
- B. A loop that never ends
- C. A sorting method
- D. A function that calls itself (correct)
What is a base case in recursion?
- A. The first function call
- B. The largest input
- C. The condition that stops further recursive calls (correct)
- D. The return type
Which data structure is used for function calls in most languages?
- A. Heap
- B. Stack (correct)
- C. Graph
- D. Queue
Which data structure is used for breadth-first search?
- A. Queue (correct)
- B. Hash table
- C. Stack
- D. Heap
What does a graph consist of?
- A. Vertices and edges (correct)
- B. Keys and values only
- C. Roots and leaves only
- D. Rows and columns
What is the worst-case time complexity of bubble sort?
- A. O(n)
- B. O(n log n)
- C. O(log n)
- D. O(n^2) (correct)
What is the average time complexity of merge sort?
- A. O(n)
- B. O(log n)
- C. O(n log n) (correct)
- D. O(n^2)
What is the worst-case time complexity of quicksort?
- A. O(n)
- B. O(log n)
- C. O(n^2) (correct)
- D. O(n log n)
Which sorting algorithm is stable and always O(n log n)?
- A. Heap sort
- B. Quicksort
- C. Merge sort (correct)
- D. Selection sort
What is the extra space used by merge sort on arrays?
- A. O(n) (correct)
- B. O(n^2)
- C. O(1)
- D. O(log n)
What does a hash function do in a hash table?
- A. Counts the elements
- B. Sorts the keys
- C. Encrypts the values
- D. Maps a key to an index (correct)
What is a collision in a hash table?
- A. A full table
- B. A key that is too long
- C. A deleted key
- D. Two keys mapping to the same index (correct)
What is the average time to look up a key in a hash table?
- A. O(log n)
- B. O(n log n)
- C. O(1) (correct)
- D. O(n)
In a binary search tree, where are values smaller than a node stored?
- A. In its right subtree
- B. In the parent
- C. In its left subtree (correct)
- D. In a separate list
Which traversal of a binary search tree visits values in sorted order?
- A. Post-order
- B. Level-order
- C. In-order (correct)
- D. Pre-order
In pre-order traversal, when is the current node visited?
- A. After both subtrees
- B. Only if it is a leaf
- C. Between the subtrees
- D. Before its left and right subtrees (correct)
What is the height of a balanced binary tree with n nodes?
- A. About n^2
- B. About n
- C. About n/2
- D. About log n (correct)
What is the worst-case search time in an unbalanced binary search tree?
- A. O(n) (correct)
- B. O(n log n)
- C. O(log n)
- D. O(1)
What is a heap?
- A. A hash table with buckets
- B. A complete binary tree where each parent is ordered relative to its children (correct)
- C. A linked list of blocks
- D. A sorted array
What does a min-heap keep at its root?
- A. The newest element
- B. The smallest element (correct)
- C. The largest element
- D. The median
What is the time to insert into a binary heap?
- A. O(n log n)
- B. O(log n) (correct)
- C. O(n)
- D. O(1)
Which data structure is usually used to implement a priority queue?
- A. Stack
- B. Array without ordering
- C. Heap (correct)
- D. Linked list only
Which algorithm explores as deep as possible before backtracking?
- A. Depth-first search (correct)
- B. Breadth-first search
- C. Binary search
- D. Dijkstra's algorithm
Which graph representation uses a V × V matrix?
- A. Adjacency list
- B. Edge list
- C. Incidence tree
- D. Adjacency matrix (correct)
Which algorithm finds shortest paths from one source with non-negative edge weights?
- A. Prim's algorithm
- B. Dijkstra's algorithm (correct)
- C. Depth-first search
- D. Kruskal's algorithm
What is dynamic programming?
- A. Random guessing
- B. Solving problems by combining solutions to overlapping subproblems and storing them (correct)
- C. Using dynamic memory only
- D. Programming that changes at runtime
What is memoization?
- A. Caching results of function calls to avoid recomputation (correct)
- B. Allocating memory early
- C. Writing notes in code
- D. Memorizing algorithms
What is the time complexity of inserting at the head of a singly linked list?
- A. O(n log n)
- B. O(log n)
- C. O(1) (correct)
- D. O(n)
What is a doubly linked list?
- A. A list where each node links to both the next and previous nodes (correct)
- B. A list with two heads
- C. A list stored twice
- D. Two linked lists joined together
Which technique uses two indexes moving through an array to solve problems in linear time?
- A. Divide and conquer
- B. Two pointers (correct)
- C. Hashing
- D. Backtracking
What is a greedy algorithm?
- A. One that makes the locally best choice at each step (correct)
- B. One that tries every possibility
- C. One that uses recursion only
- D. One that uses the most memory
What is the time complexity of naive recursive Fibonacci?
- A. O(n^2)
- B. O(n)
- C. O(log n)
- D. O(2^n) (correct)
What is the time complexity of Fibonacci computed with dynamic programming?
- A. O(2^n)
- B. O(n^2)
- C. O(1) always
- D. O(n) (correct)
What does the sliding window technique help with?
- A. Matrix multiplication
- B. Problems on contiguous subarrays or substrings (correct)
- C. Graph colouring
- D. Sorting arrays
Which algorithm finds a minimum spanning tree by adding the cheapest edge that does not form a cycle?
- A. Kruskal's algorithm (correct)
- B. Floyd-Warshall
- C. Bellman-Ford
- D. Dijkstra's algorithm
Which algorithm can handle negative edge weights and detect negative cycles?
- A. Dijkstra's algorithm
- B. Breadth-first search
- C. Bellman-Ford (correct)
- D. Prim's algorithm
Which algorithm computes shortest paths between all pairs of vertices in O(V^3)?
- A. Dijkstra's algorithm
- B. Topological sort
- C. Floyd-Warshall (correct)
- D. Kruskal's algorithm
What is a topological sort?
- A. Sorting a tree by height
- B. Ordering vertices by degree
- C. Sorting numbers by their digits
- D. A linear ordering of a directed acyclic graph's vertices respecting edge directions (correct)
Which data structure efficiently supports union and find for connected components?
- A. Deque
- B. Segment tree
- C. Disjoint set union (correct)
- D. Trie
What is a trie mainly used for?
- A. Balancing trees
- B. Storing graphs
- C. Fast prefix lookups on strings (correct)
- D. Sorting numbers
What is an AVL tree?
- A. A heap variant
- B. A tree with only leaves
- C. A self-balancing binary search tree (correct)
- D. A graph with no cycles
What is the amortized time to append to a dynamic array?
- A. O(n^2)
- B. O(1) (correct)
- C. O(n)
- D. O(log n)
What is the time complexity of building a heap from n elements with heapify?
- A. O(n) (correct)
- B. O(n^2)
- C. O(log n)
- D. O(n log n)
Which problem is solved by the classic 0/1 knapsack dynamic programming approach?
- A. Sorting items by weight
- B. Packing items into the fewest boxes
- C. Finding the shortest path
- D. Choosing items with maximum value under a weight limit (correct)
What is the time complexity of the dynamic programming solution for the longest common subsequence of strings of length m and n?
- A. O(m × n) (correct)
- B. O(2^(m+n))
- C. O(m + n)
- D. O(log m)
How can you detect a cycle in a linked list using O(1) extra space?
- A. Store each node in a hash set
- B. Floyd's slow and fast pointers (correct)
- C. Sort the list
- D. Reverse the list twice
What is backtracking?
- A. Building candidates step by step and abandoning ones that cannot lead to a solution (correct)
- B. Traversing a list backwards
- C. Sorting in reverse
- D. Undoing a git commit
What is the space complexity of a recursive DFS on a graph in the worst case?
- A. O(1)
- B. O(log V)
- C. O(V) (correct)
- D. O(E^2)
What is a segment tree used for?
- A. Sorting segments of an array
- B. Answering range queries like sums or minimums with updates in O(log n) (correct)
- C. Storing strings by prefix
- D. Finding cycles
Which sorting algorithm is not comparison-based?
- A. Quicksort
- B. Merge sort
- C. Heap sort
- D. Counting sort (correct)
What is the lower bound for comparison-based sorting in the worst case?
- A. Ω(n log n) (correct)
- B. Ω(n^2)
- C. Ω(n)
- D. Ω(log n)
What is the time complexity of Dijkstra's algorithm with a binary heap?
- A. O(E^2)
- B. O(V + E)
- C. O(V^3)
- D. O((V + E) log V) (correct)
What does a stable sort guarantee?
- A. Equal elements keep their original relative order (correct)
- B. It never uses extra memory
- C. It never swaps elements
- D. It always runs in O(n log n)
Which problem asks for the minimum number of edits to turn one string into another?
- A. Edit (Levenshtein) distance (correct)
- B. Coin change
- C. Longest increasing subsequence
- D. Knapsack