Data structure viva questions follow your lab programs. The 14 that matter, with model answers, likely follow-ups and three answer-key errors to avoid.
Data structure viva questions often follow the programs in your lab record, so start from those. We compared three published lab syllabi: Anna University's CS3311, a VTU-scheme lab manual from KSIT Bengaluru, and IARE's ACSB05. All three have you build a stack, a queue, an infix-to-postfix converter, a singly linked list and a binary search tree. Expect those first. The examiner then checks that you understand the code you ran: what overflow means in your stack, why the queue is circular, what your inorder traversal printed. Below are the 14 questions that follow from those programs, each with a short model answer and the follow-up to expect.
How the lab viva is marked
The viva is a small share of the marks, but it is where the examiner can see whether you understand the program you ran. The KSIT manual, written for VTU's 2018-scheme lab (18CSL38), gives a sample split for a one-part lab of 15 marks for procedure, 70 for execution and 15 for the viva, and notes that it can change with university regulations. You pick one experiment from the lot, and changing it once costs you the procedure marks for that part. Its rubric for the viva component separates "Exceptional" from "Acceptable" answers mainly by elaboration: an acceptable student answers "but fails to elaborate"; an exceptional one answers "with explanations and elaboration".
So the target for every answer below is the same: the definition, then one sentence on why, tied to your own program.
Which topics each syllabus covers
- Lab program — Anna Univ. CS3311 — VTU manual (KSIT) — IARE ACSB05 (Python)
- Stack with an array or list — Yes — Yes — Yes
- Queue or circular queue — Yes — Yes — Yes
- Infix to postfix, postfix evaluation — Yes — Yes — Yes
- Singly linked list — Yes — Yes — Yes
- Binary search tree — Yes — Yes — Yes
- Doubly or circular linked list — No — Yes — Yes
- Stack or queue built on a linked list — Yes — Partly — Yes
- Hashing with linear probing — Yes — Yes — No
- Graph traversal (BFS/DFS) — No — Yes — Yes
- Searching and sorting — Yes — No — Yes
- AVL tree, heap, Dijkstra, Prim — Yes — No — No
Check your own syllabus against this table and spend your time on the rows marked Yes for your course.
Opening questions
1. What is a data structure, and how is it different from an abstract data type?
Testing: whether you separate the idea from the code.
Model answer: a data structure is a concrete way of storing data in memory, such as an array or a linked list. An abstract data type (ADT) defines values and operations "independent of any particular implementation" (NIST). A stack is an ADT; your array with a top index is one implementation of it, and a linked list is another.
2. Array or linked list: when would you pick each?
Testing: trade-offs, not definitions.
Model answer: an array gives constant-time access by index but needs a fixed block of memory, and inserting in the middle shifts elements. A linked list grows node by node and inserts by changing pointers, but reaching the i-th element means walking from the head.
Follow-up: "Can you binary search a sorted linked list?" You can run the algorithm, but finding each midpoint means walking the list, so you lose the speed that made binary search worth using.
Stack programs
3. What are overflow and underflow in your stack program?
Model answer: overflow is a push onto a full stack; underflow is a pop or peek on an empty one. In an array stack that starts with top = -1, overflow is top == MAX - 1 and underflow is top == -1. A linked-list stack has no fixed size, so overflow only happens when memory runs out.
Follow-up: "Where are stacks used?" Function calls and recursion, expression evaluation, and backtracking.
4. Convert this infix expression to postfix.
Testing: precedence and associativity, live.
Model answer: scan left to right; operands go straight to output; an operator pops any stacked operator of higher precedence, or equal precedence if the incoming operator is left-associative; ^ is right-associative, so it does not pop another ^. For ((A+B)*C-(D-E)^(F+G)) with the usual precedence (^ above * above -), the result is:
Postfix: A B + C * D E - F G + ^ -
Prefix: - * + A B C ^ - D E + F GSay your precedence rules out loud before you start. That alone shows the examiner you know where this question usually goes wrong (see the answer-key errors below).
5. Evaluate a postfix expression step by step.
Model answer: push operands; on an operator, pop two, apply it, push the result. For 2 3 * 5 4 * + 9 -:
2 3 * -> 6
5 4 * -> stack: 6 20
+ -> 26
9 - -> 26 - 9 = 17Follow-up: "Which popped value is the left operand?" The second one popped. Getting this backwards breaks - and /.
Queue programs
6. Why use a circular queue, and how does your program know it is full?
Model answer: in a simple linear array queue, slots freed at the front are never reused. A circular queue wraps the indexes with modulo arithmetic so they are. The catch: when front == rear, the queue could be empty or full. The two standard fixes are to leave one slot unused or to keep a count.
#define MAX 5
char q[MAX];
int front = 0, rear = 0; /* empty when front == rear */
int is_full(void) { return (rear + 1) % MAX == front; } /* holds MAX - 1 items */
int is_empty(void) { return front == rear; }Know which fix your own program uses. It is the most common follow-up on this program.
7. How do you build a stack or a queue from a linked list?
Model answer: for a stack, push and pop at the head, so both are constant time. For a queue, insert at the tail and delete at the head; with a singly linked list you keep a tail pointer so you never walk the list to find the end.
Follow-up for Python labs: "Why not use a list as a queue?" The Python tutorial says popping from the front of a list is slow because every other element shifts, and recommends collections.deque instead.
Linked lists
8. What changes when you delete a node from a singly, doubly or circular list?
Model answer: in a singly linked list you need the previous node, so you track it while walking. In a doubly linked list each node knows its neighbours, so you relink prev and next directly. In a circular list the last node points back to the first, so deleting the head also means updating the last node's pointer. Mention the edge cases your code handles: an empty list, a single node, deleting the head.
Tree programs
9. What does inorder traversal of your BST print?
Model answer: the keys in sorted order, because inorder visits left subtree, node, right subtree. The VTU program builds a BST from 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2 and traverses it:
Inorder: 2 5 6 7 8 9 14 15 24
Preorder: 6 5 2 9 8 7 15 14 24
Postorder: 2 5 7 8 14 24 15 9 6Follow-ups: "What happened to the repeated 8, 5 and 2?" (the output above assumes your insert ignores duplicates; know what yours does). "What is the worst case?" Search becomes linear when the tree degenerates into a chain. Insert the same nine keys in sorted order and the tree is nine levels deep instead of four.
10. How do you delete a node with two children?
Model answer: replace it with its inorder successor (the smallest key in its right subtree) or its inorder predecessor, then delete that node from its old position. In the tree above, deleting 9 puts 14 in its place.
11. What is an AVL tree's balance factor, and when do you need a double rotation?
Relevant if AVL trees are on your syllabus, as they are in Anna University's list.
Model answer: the balance factor is the height difference between a node's two subtrees, and it must be -1, 0 or +1 at every node. Left-left and right-right imbalances are fixed with one rotation; left-right and right-left need two. This keeps search, insert and delete logarithmic even in the worst case.
12. How is a heap stored, and why does it suit a priority queue?
Model answer: a binary heap is a complete binary tree stored in an array: with a 0-based index, node i has children at 2i+1 and 2i+2 and its parent at (i-1)/2, rounded down. The minimum (or maximum) sits at the root, and insert and remove-root take O(log n), which is exactly what a priority queue needs.
Graph and hashing programs
13. BFS or DFS: which data structure does each use?
Model answer: BFS uses a queue and visits nodes level by level, so it finds the path with the fewest edges. DFS uses a stack, or recursion, and goes deep before backtracking. With an adjacency list both run in O(V + E).
Follow-up for Dijkstra labs: "Does it work with negative edge weights?" No: it assumes non-negative weights; Bellman-Ford handles negative ones.
14. In your hashing program, what happens on a collision?
Model answer: with linear probing, the key goes into the next free slot. Take H(K) = K mod 100 (an illustrative table size): 1234 goes to slot 34, then 5634 also hashes to 34 and moves to 35, and 2035, which hashes to 35, is pushed to 36. That growing run of filled slots is primary clustering, and it slows searches as the table fills.
Follow-up: "Can you delete by emptying the slot?" No. A later search would stop at the gap and miss keys stored after it. You mark the slot as deleted or move later keys back.
Three answer-key errors to avoid
Answer keys get copied from manual to manual, and some carry mistakes. The KSIT manual's "Possible Viva questions" list, otherwise useful, has three worth knowing:
- The infix conversion. It gives the postfix of ((A+B)*C-(D-E)^(F+G)) as AB+C*DE--FG+^, which only holds if ^ is applied last. The manual's own infix program treats ^ as the power operator, and by the usual convention power binds tighter than -, which gives the answer in question 4.
- The ADT definition. It says the representation of a data structure in memory is an abstract data type. That reverses the standard definition: an ADT is defined independently of any implementation.
- Collision resolution. It lists "overflow block" as the open addressing method. Linear probing, which the manual's own hashing program uses, is the textbook example of open addressing.
If an examiner reads from one of these keys, give the correct answer and explain the assumption.
A three-day plan
- Day 1: reread every program in your record. For each, write the one-line answer to "what does this do, and what can go wrong?"
- Day 2: trace questions 4, 5, 9 and 14 by hand without notes. Then run your own programs on edge cases: an empty stack, a full circular queue, a duplicate BST key.
- Day 3: have a classmate ask you the 14 questions and push with "why?" after each answer. Aim for the definition plus one sentence of reasoning.
If these questions come up in a placement interview
If you are preparing for a placement technical round rather than a lab viva, practise writing each structure's code and stating its complexity, not just the definitions. Our technical round interview questions and LeetCode interview questions cover that side, and the Java viva questions guide covers the language viva. For job interviews, Verve AI's Interview Copilot listens to the conversation and shows suggestions only you can see; its Software Engineering domain covers algorithms, system design and DevOps topics, and you can type sample questions into its Playground first to see how it responds.
Sources
- Anna University CS3311 Data Structures Laboratory, list of 14 exercises (stack, queue, circular queue, linked lists, postfix, BST, AVL, heaps, Dijkstra, Prim, searching, sorting, open addressing): https://cac.annauniv.edu/aidetails/afug_2021_fu/Revised/IandC/B.E.CSE.pdf
- KSIT Data Structures Lab manual for VTU 18CSL38 (2018 scheme): program list including the BST key sequence, circular queue, SLL, DLL, graph and K mod m hashing with linear probing; 15+70+15 marks split; one change of experiment; viva rubric wording; "Possible Viva questions" answer key: https://www.ksit.ac.in/images/nba_1638686937118.pdf
- IARE ACSB05 Data Structures Laboratory (Python), 12-week experiment list: https://www.iare.ac.in/sites/default/files/lab2/CSE_DATA_STRUCTURES_LABORARTORY_SYLLABUS.pdf
- Abstract data type defined independently of implementation: https://xlinux.nist.gov/dads/HTML/abstractDataType.html
- Stack overflow, underflow, linked-list push and pop at the head, uses in recursion, expression evaluation and backtracking: https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29
- Operator precedence, right-associative ^, popping rule in infix-to-postfix conversion: https://en.wikipedia.org/wiki/Shunting_yard_algorithm
- Circular queue full versus empty, one unused slot or a count: https://en.wikipedia.org/wiki/Circular_buffer
- Queue on a linked list with a tail pointer; modulo indexing for array queues: https://en.wikipedia.org/wiki/Queue_%28abstract_data_type%29
- Python lists slow for popping from the front; use collections.deque: https://docs.python.org/3/tutorial/datastructures.html
- BST inorder order, worst case linear, deletion with inorder successor or predecessor: https://en.wikipedia.org/wiki/Binary_search_tree
- AVL balance factor, single and double rotations, logarithmic worst case: https://en.wikipedia.org/wiki/AVL_tree
- Binary heap as complete binary tree, array index formulas, O(log n) insert and remove, priority queues: https://en.wikipedia.org/wiki/Binary_heap
- BFS uses a queue, DFS a stack, fewest-edges paths, O(V + E): https://en.wikipedia.org/wiki/Breadth-first_search
- Dijkstra requires non-negative weights; Bellman-Ford for negative weights: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
- Linear probing, primary clustering, deletion by flag or moving keys back: https://en.wikipedia.org/wiki/Linear_probing
- Verve Interview Copilot (suggestions visible only to the user; Software Engineering domain): https://docs.vervecopilot.com/features/interview-copilot
- Verve Playground (type sample questions to preview responses): https://docs.vervecopilot.com/features/what-is-playground
- Worked examples (conversions, postfix evaluation, BST traversals, hash slots) were checked by running them; they are not taken from a source.
Ryan
CEO of Verve AI






