144 Data Structures (Computer Science) questions asked in DSSSB TGT / PGT previous year papers, each with the correct answer and explanation. Read them free on UTpaper, or attempt the full papers as timed online tests.
The numbers 70, 50, 10, 80, 30, 60, 100, 90, 40, 20 are inserted in the given order in to a binary search tree. What is the in-order traversal sequence of the resultant binary search tree?
Consider an array A[2 : 8, −4 : 1, 6 : 10]. Base address of array A is = 400 and size of each element = 2 word per memory cell. What is the address of A[5, −1, 8] in row major form?
A628
B614
C630
D626
Show answerHide answer
Correct answer: (A) 628
Explanation
Note: DSSSB allowed option (a) as correct (the computed value 614 does not match the official key).
Inorder and postorder traversal of a binary tree are given.
In: E, I, C, F, B, G, D, J, H, K
Post: I, E, F, C, G, J, K, H, D, B
What is the preorder traversal of the binary tree?
AB, C, E, I, F, D, G, H, J, K
BB, F, I, E, C, D, G, H, J, K
CB, C, E, I, F, D, G, H, K, J
DB, C, E, F, G, H, K, D, J, I
Show answerHide answer
Correct answer: (A) B, C, E, I, F, D, G, H, J, K
Explanation
The root is B (last in postorder). Left subtree {E,I,C,F} has root C, with E (right child I) and F. Right subtree {G,D,J,H,K} has root D, with left G and right H (J, K). Preorder: B, C, E, I, F, D, G, H, J, K.
Which of the following statement(s) is/are correct about red-black binary tree?
I. Every node is either red or black.
II. Every leaf node is red.
III. When a node is red and both its children are black.
AI and II
BI, II and III
CI and III
DIII and II
Show answerHide answer
Correct answer: (C) I and III
Explanation
In a red-black tree every node is red or black, and a red node's children must be black. Leaves (NIL nodes) are black, not red, so II is false.
Consider a max heap, represented by the array:
23, 17, 14, 6, 13, 10, 1, 5
If a value 20 is inserted into this heap, then what will be the new max heap
Add 20 at position 9 as the child of 6, then swap it with 6. Its parent is now 17, so swap again. The parent 23 is larger, so it stops: 23, 20, 14, 17, 13, 10, 1, 5, 6.
Consider the following graph.
Vertices P, Q, R, S, T with edges (weight): P–Q (30), Q–R (5), Q–S (20), Q–T (15), P–S (40), S–T (10), R–T (25).
What is the weight of minimum spanning tree?
A50
B60
C70
D80
Show answerHide answer
Correct answer: (B) 60
Explanation
Kruskal: take Q–R (5), S–T (10), Q–T (15); skip Q–S (20) and R–T (25), which would form cycles; take P–Q (30). Weight = 5 + 10 + 15 + 30 = 60.
Q62DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
What is the total number of elements in a array E[-4: 1, 6: 10]?
A30
B20
C9
D11
Show answerHide answer
Correct answer: (A) 30
Explanation
Rows run from −4 to 1, which is 1 − (−4) + 1 = 6 rows. Columns run from 6 to 10, which is 10 − 6 + 1 = 5 columns. Total elements = 6 × 5 = 30.
Q63DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
Which data structure is used to indicate that the order of the processing of data must be postponed until other conditions are fulfilled?
AArray
BLinked list
CTrees
DStack
Show answerHide answer
Correct answer: (D) Stack
Explanation
A stack holds pending work in LIFO order. The postponed items wait on the stack and are processed only after the current conditions are met, as in recursion or backtracking.
Q64DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
Consider the following new-order strategy for traversing a given tree.
I. Visit the right subtree of a Node using new-order
II. Visit the Node
III. Visit the left subtree of a Node using new-order
The tree: P is the root. P has left child Q and right child V. Q has left child R and right child S; S has left child T; T has right child U. V has left child W and right child Z; W has right child X; X has right child Y.
What is the new-order traversal of the given tree?
AZ, V, Y,X, W,P, S, U, T,Q, R
BR, Q, T, U, S, P, W,X, Y, V, Z
CP, W, X, Y, V,Z,R, Q, T, U, S
DS, U, T,Q,R, Z, V, Y,X, W, P
Show answerHide answer
Correct answer: (A) Z, V, Y,X, W,P, S, U, T,Q, R
Explanation
This new-order is right, node, left, which is reverse in-order. The right subtree of P gives Z, V, Y, X, W. Then comes P. The left subtree gives S, U, T, Q, R.
Q65DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
Consider a binary search tree given below.
Root 14 has left child 10 and right child 16. 10 has left child 7 and right child 13; 13 has left child 11. 16 has right child 20; 20 has left child 18 and right child 25; 25 has left child 22.
What is the pre-order traversal of the binary search tree after 14 is deleted?
14 has two children, so it is replaced by its in-order successor 16, the smallest key in its right subtree. 16's right child 20 moves up. Pre-order is then 16, 10, 7, 13, 11, 20, 18, 25, 22.
Q66DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
Which of the following can be the valid balance factor of any node in an AVL tree?
A1
B2
C3
D4
Show answerHide answer
Correct answer: (A) 1
Explanation
An AVL tree allows each node a balance factor (left height minus right height) of only −1, 0 or +1. So 1 is valid, while 2, 3 and 4 would need a rebalancing rotation.
Q67DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
The vertex in graph with degree one is known as
AIsolated vertex
BLoop vertex
CPendant vertex
DExternal vertex
Show answerHide answer
Correct answer: (C) Pendant vertex
Explanation
A pendant vertex has degree exactly one. An isolated vertex has degree zero.
Q68DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2
For the given graph, what does the following matrix represent?
Graph: vertices V1, V2, V3, V4 with edges e1 = V1–V3, e2 = V3–V4, e3 = V2–V3, e4 = V2–V4, e5 = V1–V4.
Matrix (rows and columns v1, v2, v3, v4):
[ 0 0 1 1 ]
[ 0 0 1 1 ]
[ 1 1 0 1 ]
[ 1 1 1 0 ]
AAdjacency matrix
BIncidence matrix
CCircuit matrix
DCut-set matrix
Show answerHide answer
Correct answer: (A) Adjacency matrix
Explanation
The matrix is square, vertex by vertex, and entry (i, j) = 1 exactly when vi and vj are joined by an edge. For example, V1 is joined to V3 and V4. So it is the adjacency matrix. An incidence matrix would be vertex by edge.
Q69DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
The operator in C++, which is used to access a value referred by a pointer is known as ________.
AIndirect operator
BDirect operator
CIndirection operator
DInsertion operator
Show answerHide answer
Correct answer: (C) Indirection operator
Explanation
The unary * operator, which gives the value a pointer points to, is called the indirection (dereference) operator.
Q70DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
Which traversal of binary search tree is in ascending order?
I. Preorder traversal
II. Postorder traversal
III. Inorder traversal
AOnly II
BI and III
COnly III
DII and III
Show answerHide answer
Correct answer: (C) Only III
Explanation
An in-order traversal (Left, Node, Right) of a BST visits the keys in ascending order. Pre-order and post-order do not.
Q71DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
Which rotations in an AVL tree is known as double rotation?
ALL and RR
BLR and LL
CRL and RR
DLR and RL
Show answerHide answer
Correct answer: (D) LR and RL
Explanation
LR and RL cases each need two single rotations, so they are called double rotations. LL and RR need only one.
Q72DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
Consider the following arrays of elements 289, 219, 250, 217, 212, 215, 22, 25, 27, 211, 26, 29, 300. What is the minimum number of interchanges needed to convert it into max-heap?
A4
B5
C2
D3
Show answerHide answer
Correct answer: (D) 3
Explanation
Bottom-up heapify: 215 swaps with 300, 250 swaps with 300, then 289 swaps with 300. No other node violates the heap, so 3 interchanges.
Q73DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Which of the following statement(s) is/are true about binary search algorithm?
I. It is implemented on sorted array.
II. One must have direct access to the middle element in any sub-list.
III. It is implemented on sorted linked list.
AII and III
BI and III
CI and II
DI, II and III
Show answerHide answer
Correct answer: (C) I and II
Explanation
Binary search needs a sorted list with direct (random) access to the middle element, which an array provides. A linked list has no direct access to the middle, so III is false.
Q74DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
2 Dimensional array (Matrices) with relatively high proportion of zero entries are called ________ while with low proportion of zero entries are called ________.
ARegular matrix; Non-Regular matrix
BSparse Matrix; Dense matrix
CTranspose Matrix; Inverse Matrix
DSquare Matrix; Dense Matrix
Show answerHide answer
Correct answer: (B) Sparse Matrix; Dense matrix
Explanation
A matrix with a high proportion of zero entries is a sparse matrix; one with few zeros is a dense matrix.
Q75DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
The height of a tree is the length of the longest path from root to leaf. What is the maximum and minimum number of nodes in a binary tree of height 'n'?
A2ⁿ⁺¹ − 1, n + 1
B2ⁿ − 1, n
C2ⁿ, n + 1
D2ⁿ⁻¹ − 1, n
Show answerHide answer
Correct answer: (A) 2ⁿ⁺¹ − 1, n + 1
Explanation
A binary tree of height n has at most 1 + 2 + ... + 2ⁿ = 2ⁿ⁺¹ − 1 nodes (completely full) and at least n + 1 nodes (one node per level, a chain).
Q76DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Assume two binary operators '^' and 'v'. '^' has higher precedence than 'v'. Operator '^' is right associative while operator 'v' is left associative. Which of the following represents the expression tree for the given expression?
(9 v 3 ^ 4 v 2)
ARoot v with left child ^ and right child 2; the ^ node has left child 9 and right child v, whose children are 3 and 4.
BRoot v with left child v and right child 2; the inner v has left child 9 and right child ^, whose children are 3 and 4.
CRoot v with left child v and right child 2; the inner v has left child ^ (children 3 and 4) and right child 9.
DRoot v with left child 2 and right child v; the inner v has left child 9 and right child ^, whose children are 3 and 4.
Show answerHide answer
Correct answer: (B) Root v with left child v and right child 2; the inner v has left child 9 and right child ^, whose children are 3 and 4.
Explanation
^ binds tighter, so 3 ^ 4 is grouped first: 9 v (3 ^ 4) v 2. v is left associative, so it is (9 v (3 ^ 4)) v 2: root v with left child the inner v and right child 2.
Q77DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Which of the following is not collision resolution technique of hashing?
ADouble hashing
BQuadratic probing
CChaining
DFolding
Show answerHide answer
Correct answer: (D) Folding
Explanation
Double hashing, quadratic probing and chaining resolve collisions. Folding is a method of computing a hash function, not a collision resolution technique.
Q78DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Which of the following is stable sort?
ASelection sort
BQuick sort
CHeap sort
DMerge sort
Show answerHide answer
Correct answer: (D) Merge sort
Explanation
Merge sort is stable: equal keys keep their original order. Selection, quick and heap sort are not stable in their usual forms.
Q79DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Post-order Binary tree traversal is ________.
ALeft, Node, Right
BLeft, Right, Node
CNode, Left, Node
DRight, Left, Node
Show answerHide answer
Correct answer: (B) Left, Right, Node
Explanation
Post-order traversal visits the left subtree, then the right subtree, then the node (Left, Right, Node).
Q80DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
What will be the balancing factor of node 14 in an AVL tree when a node 13 is deleted from it?
Tree: root 14 has left child 1 and right child 64. Node 1 has right child 13. Node 64 has left child 26 and right child 98. Node 98 has left child 85 and right child 110.
ABF(14) = −1
BBF(14) = −2
CBF(14) = 2
DBF(14) = 1
Show answerHide answer
Correct answer: (B) BF(14) = −2
Explanation
After deleting 13, the left subtree of 14 is just node 1 (height 1). The right subtree 64 → 98 → 85 has height 3. BF = 1 − 3 = −2.
Q81DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Consider a max heap, represented by the array 400, 300, 200, 100, 150, 160, 170, 80, 40. Which will be the new heap after insertion of 350?
Insert 350 at the end (position 10). Its parent 150 is smaller, so swap. The new parent 300 is smaller, so swap again. 400 is larger, so stop: 400, 350, 200, 100, 300, 160, 170, 80, 40, 150.
Q82DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
Consider the following New-order strategy for traversing a binary tree.
I. Visit the right subtree of node using new-order
II. Visit the left subtree of node using new-order
III. Visit the node
Tree: root A has left child B and right child E. B has right child C; C has left child D. E has left child F and right child I; F has children G (left) and H (right); I has right child J; J has right child K.
What is the new-order traversal of the given tree?
AK, J, I, H, G, F, E, D, C, B, A
BA, B, C, D, E, F, G, H, I, J, K
CB, D, C, A, G, F, H, E, I, J, K
DA, B, C, D, K, J, I, H, G, F, E
Show answerHide answer
Correct answer: (A) K, J, I, H, G, F, E, D, C, B, A
Explanation
Right-left-node is the exact reverse of preorder (node-left-right). The preorder is A, B, C, D, E, F, G, H, I, J, K, so the new-order is K, J, I, H, G, F, E, D, C, B, A.
Q83DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
Which statement is correct regarding binary search tree?
I. The value at node N is less than every value in the left subtree of node.
II. The value at node N is greater than or equal to every value in the right subtree of N.
AOnly I
BOnly II
CBoth I and II
DNeither I nor II
Show answerHide answer
Correct answer: (D) Neither I nor II
Explanation
In a BST, the value at N is greater than every value in its left subtree and less than (or equal to) every value in its right subtree. Both statements reverse this, so neither is correct.
Q84DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
Which of the following statement(s) is/are correct regarding the undirected graph?
I. Number of odd degree vertices is even.
II. Sum of degrees of all vertices is even.
AOnly I
BOnly II
CBoth I and II
DNeither I nor II
Show answerHide answer
Correct answer: (C) Both I and II
Explanation
Each edge adds 2 to the total degree, so the sum of degrees is even (handshaking lemma), and hence the number of odd-degree vertices must also be even.
Q85DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
Which statement(s) is/are correct regarding node N deletion in binary search tree?
I. If node N has no children then just replace location of N in the parent node by the null pointer.
II. If node N has two children, then replace it by preorder successor.
AOnly I
BOnly II
CBoth I and II
DNeither I nor II
Show answerHide answer
Correct answer: (A) Only I
Explanation
A leaf node is removed by setting its parent's pointer to null (I correct). A node with two children is replaced by its inorder successor (or predecessor), not its preorder successor, so II is wrong.
Q86DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
What is the condition for binary search of be unsuccessful where Beg is the beginning and End is ending location of sorted array?
AEnd > Beg
BEnd == Beg
CEnd < Beg
DEnd != Beg
Show answerHide answer
Correct answer: (C) End < Beg
Explanation
Binary search keeps narrowing Beg..End; when Beg passes End (End < Beg) the search range is empty, so the element is not present.
Q87DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
While inserting the elements 71, 56, 48, 96, 76, 82, 98 in an empty binary search tree in the sequence shown, which element will come in the lowest level?
A96
B98
C71
D82
Show answerHide answer
Correct answer: (D) 82
Explanation
71 is the root; 56 and 48 go left; 96 goes right; 76 becomes the left child of 96; 82 goes right of 76 (level 4); 98 is the right child of 96. So 82 is at the deepest level.
Q88DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
What is the other name of Data Flow Diagram (DFD)?
AFlow chart
BPictorial graph
CBubble chart
DDi graph
Show answerHide answer
Correct answer: (C) Bubble chart
Explanation
A DFD is also called a bubble chart because processes are drawn as circles (bubbles).
Q89DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
N is the number of nodes of the control graph and E is the number of edges in the control flow graph. What is Mc Cabe's cyclomatic complexity V(G)?
AV(G) = E + N + 2
BV(G) = E − N + 2
CV(G) = E + N − 2
DV(G) = E − N − 2
Show answerHide answer
Correct answer: (B) V(G) = E − N + 2
Explanation
McCabe's cyclomatic complexity for a connected control flow graph is V(G) = E − N + 2 (or number of decisions + 1).
Q90DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
Which of the following is a max-heap?
ARoot 100; children 80 and 60; 80 has child 40; 60 has children 50 and 30; 50 has child 20.
BRoot 100; children 80 and 60; 80 has children 40 and 50; 60 has children 20 and 30.
CRoot 100; children 80 and 60; 80 has children 40 and 50; 60 has right child 30; 30 has child 20.
DRoot 100; children 50 and 60; 50 has children 40 and 80; 60 has children 20 and 30.
Show answerHide answer
Correct answer: (B) Root 100; children 80 and 60; 80 has children 40 and 50; 60 has children 20 and 30.
Explanation
A max-heap must be a complete binary tree with every parent ≥ its children. Option B satisfies both. A and C are not complete trees, and in D the node 50 has a larger child 80.
Q91DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
Which rotations in AVL trees are known as single rotations?
ALL and RR
BLL and LR
CRR and RL
DLR and RL
Show answerHide answer
Correct answer: (A) LL and RR
Explanation
LL and RR imbalances are fixed by one rotation (single rotations). LR and RL need two rotations, so they are double rotations.
Q92DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
What is the at most height of red-black tree with n internal node?
An
Blog₂n
C2log₂(n + 1)
Dlog₂(2n + 1)
Show answerHide answer
Correct answer: (C) 2log₂(n + 1)
Explanation
A red-black tree with n internal nodes has height at most 2log₂(n + 1), since the black height is at least half the height.
Q93DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
Consider the following AVL tree.
Root 38; left child 14, right child 56. 14 has children 8 and 23; 23 has left child 18. 56 has children 45 and 82; 82 has left child 70.
What will be the resultant AVL tree after insertion of node with value 20?
ARoot 38; 14 (children 8, 23); 23 has left child 18; 18 has right child 20; 56 (children 45, 82); 82 has left child 70.
BRoot 38; 14 (children 8, 20); 20 has children 18 and 23; 56 (children 45, 82); 82 has left child 70.
CRoot 38; 14 (children 8, 23); 23 has left child 20; 20 has left child 18; 56 (children 45, 82); 82 has left child 70.
DRoot 38; 14 (children 8, 18); 18 has right child 20; 20 has right child 23; 56 (children 45, 82); 82 has left child 70.
Show answerHide answer
Correct answer: (B) Root 38; 14 (children 8, 20); 20 has children 18 and 23; 56 (children 45, 82); 82 has left child 70.
Explanation
20 goes to the right of 18, making 23 unbalanced (left height 2, right 0) with a left-right pattern. An LR double rotation makes 20 the subtree root with 18 and 23 as children, as in option B.
Q94DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
Preorder traversal of binary search tree is 38, 14, 8, 23, 18, 20, 56, 45, 82, 70. What is the postorder traversal of binary search tree?
The BST is 38 with left subtree 14 (8, and 23 with left child 18 whose right child is 20) and right subtree 56 (45, and 82 with left child 70). Postorder: 8, 20, 18, 23, 14, 45, 70, 82, 56, 38.
A 2D array can be initialised with a flat list when both sizes are given: {1,2,3,4} fills row by row. [2,2] is not C syntax, and only the first dimension may be left empty.
Given a 3-dimensional array C[3][4][5] stored in row-major order, with each element
occupying 1 byte, and the base address 3000, what is the address of C[2][3][4]?
A3057
B3059
C3124
D3171
Show answerHide answer
Correct answer: (B) 3059
Explanation
Offset = i × (4 × 5) + j × 5 + k = 2 × 20 + 3 × 5 + 4 = 59, so the address is 3000 + 59 = 3059.
Correct answer: (D) A base condition and a recursive call
Explanation
A recursive function needs a base condition to stop and a recursive call that moves toward that base case. Without a base case the recursion never ends.
Suppose there are n elements in an array A[ ]. If we want to insert a new element at position i in array A[ ], 1 ≤ i ≤ n, causing elements numbered i, i+1, …, n to become numbered:
Ai−1, i, i+1, i+2, i+3, …, n+1
Bi+1, i+2, i+3, …, n+1
Ci−1, i+1, i+2, i+3, …, n+1
Di+2, i+3, …, n+1
Show answerHide answer
Correct answer: (B) i+1, i+2, i+3, …, n+1
Explanation
To insert at position i, elements i to n each move one place to the right, so they become i+1, i+2, ..., n+1.
If the recursive approach of linear search is used to search a key in a linked list of n elements, then what are the time and space complexity to search an element in a linked list?
ATime Complexity = O(n), Space Complexity = O(1)
BTime Complexity = O(1), Space Complexity = O(1)
CTime Complexity = O(1), Space Complexity = O(n)
DTime Complexity = O(n), Space Complexity = O(n)
Show answerHide answer
Correct answer: (D) Time Complexity = O(n), Space Complexity = O(n)
Explanation
Recursive search makes up to n calls, so the time is O(n). Each pending call uses a stack frame, so the space is also O(n).
Correct answer: (C) Contiguously in a single block
Explanation
C stores 2D arrays contiguously in one block, row after row (row-major order).
How to use these DSSSB TGT / PGT Computer Science questions
Every question here was asked in a real DSSSB TGT / PGT paper; the paper and shift are shown on the card, and the number opens the question on its own page. Try each one before tapping Show answer, then attempt the full DSSSB TGT / PGT papers as timed tests to check your speed under exam conditions.