Data Structures questions and answers

Arrays, stacks, queues, trees, graphs and hashing. Practise data structures questions from the technical & programming section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample data structures questions with worked answers

Question 1

Which data structure works on the Last-In-First-Out (LIFO) principle?

  1. Queue
  2. Circular queue
  3. Stack
  4. Priority queue

Answer: C. Stack

Explanation: In a stack, the element pushed most recently is the first one popped, which is LIFO. Queues are FIFO, and a priority queue serves elements by priority.

Question 2

An inorder traversal of a Binary Search Tree (BST) lists the keys in which order?

  1. Ascending sorted order
  2. Descending sorted order
  3. Level-by-level order
  4. The order in which keys were inserted

Answer: A. Ascending sorted order

Explanation: Inorder visits left subtree, root, right subtree. In a BST all left keys are smaller and all right keys are larger, so inorder gives ascending order.

Question 3

The preorder traversal of a Binary Search Tree is 50, 30, 20, 40, 70, 60, 80. What is its postorder traversal?

  1. 20, 30, 40, 50, 60, 70, 80
  2. 20, 40, 30, 50, 60, 80, 70
  3. 40, 20, 30, 80, 60, 70, 50
  4. 20, 40, 30, 60, 80, 70, 50

Answer: D. 20, 40, 30, 60, 80, 70, 50

Explanation: The root is 50; the left subtree is 30 with children 20 and 40; the right subtree is 70 with children 60 and 80. Postorder (left, right, root) gives 20, 40, 30, 60, 80, 70, 50.

All 30 data structures questions with answers

Data Structures: common questions

What are data structures questions?

Arrays, stacks, queues, trees, graphs and hashing. They appear in the technical & programming section of many placement tests.

Where can I practise data structures questions with answers for free?

Right here on LogicWiz Exams. Every data structures question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise data structures?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of data structures questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Technical & Programming practice.

More technical & programming topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep