Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 24
Q401:
What is the action taken when deleting a node from the left subtree of a node with a balance of -1 and the right subtree is balanced?
A. Perform a single rotation at the parent node
B. Perform a double rotation at the parent node
C. Change the balance of the parent node and stop
D. Continue up the tree without rotation
Correct Answer:
A
Chapter: 24
Q402:
When deleting a node from an AVL tree where the right subtree of the parent node is unbalanced and the parent had a balance of -1, what is the required action?
A. Perform a double rotation at the parent node
B. Perform a single rotation at the parent node
C. Change the balance of the parent node and continue up the tree
D. Change the balance of the parent node and stop
Correct Answer:
A
Chapter: 24
Q403:
What is the purpose of expression trees in compilers?
A. To convert source code into machine language
B. To represent mathematical expressions and parse them
C. To optimize code execution by removing redundant calculations
D. To convert code into assembly language
Correct Answer:
B
Chapter: 24
Q404:
In an expression tree, what does the root node typically represent?
A. The leftmost operand
B. The rightmost operand
C. The final result of the expression
D. The primary operator of the expression
Correct Answer:
D
Chapter: 24
Q405:
What is a parse tree used for in database query processing?
A. To optimize query execution by removing redundant queries
B. To convert SQL queries into an optimized machine code
C. To represent the structure of SQL queries for processing
D. To translate SQL queries into assembly language
Correct Answer:
C
Chapter: 24
Q406:
What is the role of an optimizer in compilers?
A. To parse and analyze source code
B. To convert source code into machine language
C. To identify and reuse common subexpressions for efficiency
D. To manage memory allocation during code execution
Correct Answer:
C
Chapter: 25
Q407:
What is the main purpose of an expression tree in compilers?
A. To parse and analyze source code
B. To represent mathematical expressions
C. To manage memory allocation
D. To optimize code execution
Correct Answer:
B
Chapter: 25
Q408:
In an expression tree, what do the leaf nodes contain?
A. Operators
B. Operands
C. Parent nodes
D. Subtrees
Correct Answer:
B
Chapter: 25
Q409:
What is the result of an inorder traversal of the expression tree with the expression a + b * c + d * e + f * g?
A. a + b * c + d * e + f * g
B. (a + (b * c)) + ((d * e) + (f * g))
C. a + (b * c) + d * e + f * g
D. (a + b * c) + (d * e) + (f * g)
Correct Answer:
B
Chapter: 25
Q410:
What does the postorder traversal of the expression tree with the expression a + b * c * d + e * f + g yield?
A. a b c d * * + e f * + g *
B. a b c * + d * e f * + g *
C. a b c * d * + e f * + g *
D. a b c * d * e f * + g *
Correct Answer:
A
Chapter: 25
Q411:
Which traversal method produces an expression without parentheses from an expression tree?
A. Preorder
B. Postorder
C. Inorder
D. Level-order
Correct Answer:
B
Chapter: 25
Q412:
What is the key advantage of using Huffman Encoding for data compression?
A. It increases the size of data
B. It reduces the size of data without losing information
C. It converts data into plain text
D. It directly increases the speed of data transmission
Correct Answer:
B
Chapter: 25
Q413:
In Huffman Encoding, what does each node in the binary tree represent?
A. A frequency value
B. A character and its frequency
C. A data chunk
D. An encoded binary sequence
Correct Answer:
B
Chapter: 25
Q414:
How does Huffman Encoding ensure that no code is a prefix of another?
A. By using fixed-length codes
B. By encoding with random binary patterns
C. By creating a binary tree where each code is uniquely assignable
D. By converting the entire text into one continuous binary string
Correct Answer:
C
Chapter: 25
Q415:
What is the main disadvantage of using Huffman Encoding?
A. It cannot compress text effectively
B. It may result in longer codes for certain characters
C. It requires the entire data to be known before encoding
D. It results in loss of some data
Correct Answer:
C
Chapter: 25
Q416:
In the process of converting an infix expression to a postfix expression, what data structure is primarily used?
A. Stack
B. Queue
C. Tree
D. Array
Correct Answer:
A
Chapter: 25
Q417:
Which method of traversal can be used to output an expression tree in prefix notation?
A. Postorder
B. Inorder
C. Preorder
D. Level-order
Correct Answer:
C
Chapter: 25
Q418:
What happens when you perform a postorder traversal on an expression tree with the expression a + b * c * d?
A. You get the expression as a b c d * * +
B. You get the expression as a b c * d * +
C. You get the expression as a * b c d +
D. You get the expression as a b c d * +
Correct Answer:
A
Chapter: 25
Q419:
How does the Huffman algorithm start building the encoding tree?
A. By picking the two nodes with the highest frequency
B. By picking the two nodes with the lowest frequency
C. By combining nodes at random
D. By sorting all nodes by their ASCII values
Correct Answer:
B
Chapter: 25
Q420:
What is the final step in building a Huffman tree?
A. Encode the data
B. Traverse the tree
C. Combine the two nodes with the highest frequency
D. Output the encoded data
Correct Answer:
C