Recent questions tagged data-structures

6 6 votes
1 1 answer
218
218 views
A binary tree has:Left subtree containing $1000$ nodes Right subtree containing $100$ nodesHow many nodes are processed before the root in preorder, inorder, and postorde...
5 5 votes
2 2 answers
221
221 views
A binary tree has the following traversals:Preorder traversal $: \text{A M P K L D H T}$ Inorder traversal $:\text{P M L K A H T D}$Which of the following is the postorde...
7 7 votes
1 1 answer
185
185 views
Which of the following functions correctly returns the total number of nodes in a binary tree rooted at $\texttt{t}$?int tree_size(TreeNode *t) { if (t == NULL) return 0;...
6 6 votes
1 1 answer
178
178 views
Consider the following binary tree:Which option correctly gives the preorder, postorder, inorder, and level-order traversals?Preorder $:\texttt{9 15 23 12 8 6 2 7 10 5 35...
6 6 votes
1 1 answer
158
158 views
Consider the following binary search tree:If we traverse the tree in postorder and print only the key values that are greater than $12$ and less than $20$, what will be t...
11 11 votes
1 1 answer
242
242 views
6 6 votes
1 1 answer
200
200 views
A node of a binary tree is called nearly balanced if one of the following holds:The node is a leaf. The node has one child and that child is a leaf. The node has two chil...
6 6 votes
2 2 answers
231
231 views
A complete binary tree is stored in an array using $\mathbf{1}$-based indexing, where the root is stored at index $1$.For a node stored at index $11$, which of the follow...
7 7 votes
1 1 answer
193
193 views
A binary tree has height $4$, where height is measured as the maximum number of edges from the root to a leaf.Can such a binary tree have exactly $8$ leaves?Yes, because ...
7 7 votes
1 1 answer
304
304 views
Assume there are $n$ elements in the data structure. Consider the following statements:$\text{S1}:$ A stack can be implemented using a linked list such that each individu...
4 4 votes
1 1 answer
192
192 views
Suppose a client performs an intermixed sequence of $\texttt{enqueue}$ and $\texttt{dequeue}$ operations on a queue. The enqueue operations put the integers $0$ through $...
8 8 votes
3 3 answers
239
239 views
Consider the following postfix expression:$\texttt{1 2 3 + 4 5 * * +}$Which of the following fully parenthesized infix expressions is equivalent to it?$\texttt{( 1 + ( ( ...
6 6 votes
3 3 answers
200
200 views
Consider the following prefix expression:$\texttt{+ * 2 3 / 8 4}$Which of the following is its correct postfix form?$\texttt{2 3 * 8 4 / +}$$\texttt{+ * 2 3 / 8 4}$$\text...
7 7 votes
2 2 answers
189
189 views
For the expression:$\texttt{2 * 3 + 8 / 4}$Assume the expression tree has $\texttt{+}$ as the root, $\texttt{*}$ as the left subtree root, and $\texttt{/}$ as the right s...
5 5 votes
2 2 answers
182
182 views
6 6 votes
3 3 answers
201
201 views
Convert the following fully parenthesized infix expression into postfix form:$\texttt{( 2 + ( ( 3 + 4 ) * ( 5 * 6 ) ) )}$Which of the following is the correct postfix exp...
5 5 votes
2 2 answers
242
242 views
A stack is used to check whether parentheses, braces, and brackets are properly balanced.Consider the following two inputs:Input $1: \texttt{[()]\{\}\{[()()]()\}}$Input $...
6 6 votes
3 3 answers
310
310 views
Suppose an intermixed sequence of stack push and pop operations is performed. The push operations push the integers $0$ through $9$ in order. The pop operations print the...
7 7 votes
3 3 answers
282
282 views
A stack client reads tokens from left to right. If the token is a word, it is pushed onto the stack. If the token is $\texttt{-}$, one item is popped and printed.Consider...
7 7 votes
3 3 answers
316
316 views
A queue is implemented using two stacks $\text{S1}$ and $\text{S2}$.Use the implementation where $\texttt{dequeue()}$ is $\text{O(1)}$ by keeping the front of the queue a...
4 4 votes
2 2 answers
195
195 views
Suppose a circular queue of capacity $(n - 1)$ elements is implemented with an array of $n$ elements.Insertion and deletion operations are carried out using $\texttt{REAR...
6 6 votes
3 3 answers
195
195 views
A FIFO queue is represented using a circular linked list and only one external pointer $\text{Q}$.Design $1: \text{Q}$ points to the node containing the front item. Desig...
8 8 votes
2 2 answers
217
217 views
Consider an array implementation of a queue. Suppose we try to keep all items at the front of a partially-filled array, so that $\texttt{data[0]}$ is always the front of ...
6 6 votes
3 3 answers
195
195 views
Consider an initially empty stack $\text{S}$ and an initially empty queue $\text{Q}$.The following operations are performed:S.push(5) S.push(6) S.push(S.top()) S.push(7) ...
7 7 votes
4 4 answers
245
245 views
Convert the following infix expression into postfix expression:$$\texttt{a + (b - c) - d * ((e - f) / g + h)}$$Which of the following is correct?$\texttt{a b c - + d e f ...
6 6 votes
2 2 answers
233
233 views
Which of the following statements is true about arithmetic expressions?Parentheses are needed in all arithmetic expressions. Infix expressions do not require precedence r...
5 5 votes
2 2 answers
211
211 views
Which of the following permutations can be obtained in the same order using a stack, assuming the input sequence is:$$5, 6, 7, 8, 9$$$7, 8, 9, 5, 6$ $5, 9, 6, 7, 8$ $7, 8...
4 4 votes
2 2 answers
211
211 views
If the following sequence of operations is performed on an initially empty stack:push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2), popwhat is the sequence ...
5 5 votes
3 3 answers
219
219 views
An initially empty stack undergoes the following operations:push(40) push(10) push(10) push(pop() + pop()) push(20) push(5) push(pop() / pop())Assume the division operati...