Data Structures Practice Test

Ten questions on stacks, queues, trees and time complexity for computer science exams and placement preparation.

Answered 0 of 10

Score: 0 / 10

  1. Question 1 of 10

    Which data structure follows Last In, First Out (LIFO)?

    See the answer

    Answer: Stack. A stack removes the most recently added item first, like a pile of plates.

  2. Question 2 of 10

    Which data structure follows First In, First Out (FIFO)?

    See the answer

    Answer: Queue. A queue removes items in the order they were added, like a line at a counter.

  3. Question 3 of 10

    What is the worst-case time complexity of binary search on a sorted array?

    See the answer

    Answer: O(log n). Each step halves the search range, so it takes about log₂ n steps.

  4. Question 4 of 10

    What is the time complexity of reading an array element by its index?

    See the answer

    Answer: O(1). The element's address can be calculated directly from its index, so access takes constant time.

  5. Question 5 of 10

    Which data structure is normally used for breadth-first search (BFS) on a graph?

    See the answer

    Answer: Queue. BFS visits nodes level by level, and a queue keeps them in that order. Depth-first search uses a stack.

  6. Question 6 of 10

    Which traversal of a binary search tree gives its values in sorted order?

    See the answer

    Answer: Inorder. Inorder visits left, node, right. In a binary search tree this gives ascending order.

  7. Question 7 of 10

    What is the worst-case time complexity of merge sort?

    See the answer

    Answer: O(n log n). Merge sort always splits the list in half and merges in linear time, giving O(n log n).

  8. Question 8 of 10

    What is the average time complexity of looking up a key in a hash table?

    See the answer

    Answer: O(1). With a good hash function, lookups take constant time on average. The worst case can reach O(n).

  9. Question 9 of 10

    In a min-heap, where is the smallest element?

    See the answer

    Answer: At the root. Every parent is smaller than or equal to its children, so the minimum is always at the root.

  10. Question 10 of 10

    How long does it take to insert a node at the head of a singly linked list?

    See the answer

    Answer: O(1). You only point the new node at the old head and update the head, so no traversal is needed.

Keep revising Data Structures

More practice tests

Written by StudyZone for revision. This is not an official exam paper. Always check the latest syllabus from the official exam body.