Question 1
Marks: 1
Consider the following pseudo code:
declare a stack of characters
while (there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
write the stack's top character to the screen
pop a character off the stack
}
Ans: a. stetrac
Question 2:
Given a tree T in the box. What is the order of nodes visited using a pre-order traversal?
Ans: c. R S X Y Z T U W P V
Question 3:
Marks: 1
There are two important operations on a stack: PUSH and POP. PUSH adds the new data
to the top of the stack leaving previous data below, and POP removes and returns the
current top data of the stack. When the operations shown below are sequentially
executed, which of the following is the correct combination of the values x and y?
Here, the size of the stack is big enough to hold the entire data. “PUSH(a)” inserts the
data a into the stack, and “POP(b)” removes the data b from the stack.
[Operations]
PUSH (5);
PUSH (3);
PUSH (6);
PUSH (1);
x = POP ;
PUSH (7);
y = POP ;
What are the value of X and Y?
Ans: c. Answer b)
Question 4:
Among Breadth-first search and Depth-first search, which graph traversal algorithm uses
a queue to keep track of vertices that need to be processed?
Ans: a. Only Breadth-first search.
Question 5:
Which of the following is an appropriate description concerning the list and/or array
structures?
Ans: a. The list structure allows any data to be inserted or deleted simply by modifying
pointers. But, after the data was deleted, the cells that contained the data remain as
garbage in memory.
Question 6:
Which of the following stack operations could result in stack underflow?
Ans: c. pop
Question 7:
Which of the following represents the sequence of nodes visited in a post-order traversal
of the binary tree T shown below?
Ans: c. U X W Q Z Y V P
Question 8:
A list of four numbers (4, 1, 3, 2) was re-ordered in ascending order in accordance with a
sorting algorithm. The numbers were re-ordered as shown below. Which of the following
is the sorting algorithm?
(1, 4, 3, 2)
(1, 3, 4, 2)
(1, 2, 3, 4)
Ans: b. Insertion sort
Question 9:
Suppose cursor points to a node in a linked list (using the node definition with member
functions called data and link). What Boolean expression will be true when cursor points
to the tail node of the list?
ANS: a. (cursor->link == NULL)
Question 10:
Suppose you have a directed graph representing all the flights that an airline flies. What
algorithm might be used to find the best sequence of connections from one city to
another?
Ans: c. A shortest-path algorithm.
Question 11:
Which formula is the best approximation for the depth of a heap with n nodes?
Ans: c. log (base 2) of n
Question 12:
Which of the following is the appropriate statement concerning data sorting methods?
Ans: c. The “heap sort” method builds an ordered tree from the unsorted portion of the
elements, extracts the maximum or minimum value from this ordered tree, and moves it
to the sorted portion. This operational sequence is then repeated to gradually shrink the
unsorted portion.
Question 13:
What does a run-time analysis usually count?
Ans: b. The number of arithmetic and other operations required for the program to run
Question 14:
Which of the following stack operations could result in stack underflow?
Ans: b. pop
Question 15:
Define a recursive function F as following:
If n > 0 then F = n x F(n-1)
If n = 0 then F = 1.
As such, what is the value of F(5)?
Ans: d. 120
Question 16:
Suppose T is a binary tree with 16 nodes. What is the minimum possible depth of T?
Ans: c. 4
Question 17:
Given the Heap G. What is the number at the node A after inserting number 4 into the
node marked with the asterisk (*)?
Ans: c. 6
Question 18:
Figure 2 is the array representation of a binary tree shown in Figure 1. What should be
put into the space "a"?
Ans: b. 4
Question 19:
Given a graph G in the box. What is the order of nodes visited using DFS, starting from
node a?
Ans: d. a c b g l k h i j f e d
© Copyright 2025 Paperzz