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?
- Queue
- Circular queue
- Stack
- 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?
- Ascending sorted order
- Descending sorted order
- Level-by-level order
- 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?
- 20, 30, 40, 50, 60, 70, 80
- 20, 40, 30, 50, 60, 80, 70
- 40, 20, 30, 80, 60, 70, 50
- 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
- Which data structure works on the Last-In-First-Out (LIFO) principle?
- Starting with an empty stack, Kavya performs: push(5), push(8), push(3)…
- Starting with an empty queue: enqueue(A), enqueue(B), enqueue(C), dequeue()…
- What is the time complexity of accessing the element at index i of an array?
- Which data structure is used to implement Breadth-First Search (BFS) of a graph?
- An inorder traversal of a Binary Search Tree (BST) lists the keys in which…
- What is the postfix form of the infix expression A + B * C - D ?
- A binary tree has height 4, where height is the number of edges on the longest…
- What is the value of the postfix expression 6 2 3 + - 3 8 2 / + * ?
- A circular queue is implemented in an array of size n using front and rear…
- Keys 15, 22, 8 and 29 are inserted in that order into an empty hash table of…
- The preorder traversal of a Binary Search Tree is 50, 30, 20, 40, 70, 60, 80…
- The keys 10, 4, 7, 1 are inserted in that order into an empty array-based…
- How many structurally different binary trees can be formed with exactly 3 nodes?
- Two stacks share a single array arr[0..n-1]. Stack 1 starts at index 0 and…
- Which data structure is the most natural choice for implementing the Undo…
- What is the time complexity of inserting a new node at the beginning (head) of…
- A data structure allows insertion and deletion at both the front and the rear…
- A tree data structure has 25 nodes. How many edges does it have?
- Which of the following is a non-linear data structure?
- The keys 45, 20, 60, 10, 30, 25, 50 are inserted in that order into an empty…
- What is the prefix (Polish) form of the infix expression (A + B) * (C - D) ?
- The keys 12, 22, 35, 42, 55, 7, 17 are inserted into a hash table of size 10…
- An undirected simple graph has 6 vertices whose degrees are 3, 3, 2, 2, 2 and…
- In a doubly linked list, you are given a pointer to a node (not the head or…
- An array-based binary min-heap holds [2, 5, 3, 9, 6, 4, 8]. One deleteMin…
- A binary tree has preorder traversal A B D E H C F G and inorder traversal D B…
- The keys 10, 20, 30, 25, 28 are inserted in that order into an empty AVL tree…
- The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may…
- A max-heap of 15 distinct keys is stored in array positions 1 to 15. How many…
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
- Pseudo-code: Trace loops, recursion and bitwise logic.
- C Programming: Output prediction, pointers and operators.
- Java: OOP, strings, collections and exceptions.
- Python: Data types, comprehensions and mutability.
- Algorithms: Complexity, sorting, searching, recursion and DP.
- Object-Oriented Programming: Encapsulation, inheritance, polymorphism, abstraction.
- DBMS: Keys, normalisation, transactions and indexing.
- SQL: Joins, grouping, subqueries and query output.
- Operating Systems: Processes, scheduling, memory and deadlocks.
- Computer Networks: OSI/TCP-IP, protocols, addressing and ports.
- Software Engineering: SDLC, testing, agile and version control.
- Cloud & DevOps: Service models, containers, CI/CD and Linux.
- GenAI Basics: LLMs, tokens, prompting, embeddings and RAG.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
- SQL: SQL quizzes by topic, from SELECT and joins to window functions: query output and concepts for analyst and developer roles.
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