1. Page | 1
PART 1 – Multiple Choice Questions
1. Which of the following is FALSE about linked lists
A. The data structure includes the link to another object of the same type
B. The data set are stored in contiguous order in memory
C. The size is dynamic during run-time
D. Memory is allocated at run-time
2. The advantage of arrays over linked lists is
A. Direct access
B. Less memory usage
C. Easier to implement
D. Dynamic memory allocation
3. Which of the following structures is suitable to keep track of a sequence printing jobs
sent to a network printer?
A. Trees
B. Stack
C. Queues
D. Lists
4. The following problems best solved using stack structures, EXCEPT
A. Balancing of parenthesis
B. Evaluation of postfix expressions
C. Removal of items in random order
D. Evaluation of functions containing recursive calls
5. Given the following sequence of operations performed on a stack:
push (5.0), push (9.5), pop, push (27.5), push (12.7), push (0), pop, pop, push
(31.2)
What will be the sequence of items in the stack as a result?
A. 31.2 0.0 12.7 27.5 9.5 5.0
B. 27.5 9.5 5.0
C. 3.12 27.5 5.0
D. Stack is empty
2. Page | 2
6. Suppose myList is an object of List data structure, and myList.displayList() produces the
following output:
28 7 76 48 70
What would be the output when the following statements are executed?
myList.InsertNode(2, 10);
myList.DisplayList();
A. 10 28 7 76 48 70
B. 28 7 76 10 48 70
C. 28 7 76 48 70 10
D. 28 7 10 76 48 70
7. Suppose an array myArr contains the following sequences of integers:
28 7 76 48 70
What would be resulting sequence of MyArr when the following statement is executed?
myArr [2] = 10;
A. 10 28 7 76 48
B. 28 7 76 10 48
C. 28 7 10 48 70
D. 7 10 76 48 70
8. Which of the following is FALSE when using recursion
A. The recursions must be assumed to work all the time
B. You must have a base case which can be solved without recursion
C. The recursive call must always make progress towards the base case
D. The recursive calls must always be compounded in multiple recursive calls
9. How many times will the symbol ‘#’ be printed by the call foo (4)?
void foo (int i) {
if (i > 1) {
foo (i/2);
foo (i/2);
}
cout << "#";
}
A. 6
B. 7
C. 8
D. 9
3. Page | 3
10. Which of the following statements about QUEUES is FALSE ?
A. New items can only be inserted at the end position
B. The items are processed in a queue on a First in First out basis
C. The main operations of a queue is enqueueing and dequeueing
D. Items cannot be removed from a queue at the beginning of queue
11. In linked lists, there are no NULL links in
A. linear doubly linked list
B. circular linked list
C. single linked list
D. All of the above
12. The range of 4-bits unsigned integer is between:
A. 0 to 15
B. 1 to 16
C. -7 to 8
D. -15 to 14
13. When a new node is inserted in between a linked list, which of these is TRUE:
A. nodes appearing after the new node needs to be moved
B. nodes appearing before the new node needs to be moved
C. nodes appearing before and after the new node need to be moved
D. None of the above
14. One DIFFERENCE between a queue and a stack is:
A. Queues require linked lists, but stacks require array
B. Stacks require linked lists, but queues require array
C. Queues use two ends of the structure; stacks use only one.
D. Stacks use two ends of the structure; queues use only one.
15. The address of an element [i, j] in a m × n matrix based on the column-wise order can be ______
A. m * ( i – 2 ) + j
B. m * ( j – 2 ) + i
C. n* ( i – 1 ) + j
D. n* ( i – 1) + (j – 1)
4. Page | 4
PART 2 – Short Answer Questions
1. Given the following code:
#include <iostream>
using namespace std;
int myfunction(int);
int main () {
int input, answer;
cout <<"Enter an integer: ";
cin >> input;
answer = myfunction(input);
cout << endl<<"The answer "<<input<< "! is " << answer;
return 0;
}
int myfunction (int num) {
cout <<"Fib " << num<< " is " ;
if (num == 0)
return 0;
else (num == 1)
return 1;
else
return myfunction (num-1) + myfunction (num-2);
}
Write the output of the program if the user types 4 as input?
2. Discuss the pros and cons of choosing linked list implementation for lists, stacks
and queues.
3. Suppose a queue called myQueue is implemented using a circular array of
MAXSIZE = 7. Illustrate to show the step-by-step effects in myQueue if the following
sequence of statements is executed:
myQueue.enqueue (‘F’)
myQueue.enqueue (‘C’)
myQueue.enqueue (‘Q’)
myQueue.dequeue
myQueue.enqueue (‘X’)
myQueue.enqueue (‘Z’)
myQueue.dequeue
myQueue.enqueue (‘L’)
myQueue.enqueue (‘S’)
myQueue.enqueue (‘W’)
myQueue.enqueue (‘C’)
myQueue.dequeue
5. Page | 5
4. In C++, a variable that stores integer values can be declared as short (2 bytes or
16 bits) or int (bytes or 32 bits). Furthermore, floating-point numbers can be
declared as float (4 bytes or 32 bits) or double (8 bytes or 64 bits) based on the
IEEE Standard for Floating Point Arithmetic (IEEE-754).
Determine the corresponding binary values that are stored in the computer for the
following variable declarations:
a. unsigned short a = 15;
b. short b = -15;
c. float c = -52.25
5. Use stacks to show the step-by-step evaluation of the post-fix expression given
below:
5.2 2.0 1.5 * + 4.0 2.0 2.0 ^ * -
6. Given below is a recursive method of function f for the value x. Write an equivalent
program segment using iterative method.
int f (int x){
if (x == 0)
return 0;
else
return 2 * f (x – 1) + x * x;
}
7. The elements in an array may be stored based on a row-wise or column-wise
arrangement depending on the programming language used.
Suppose the dimensions of an array myGoodArray are 7X9X8.
Given the address of myGoodArray [4, z, 3] based on the column-wise method is
438, when the base address (B) is 10, with size of each element (W) is 2, and lowest
index of each dimension is 0,
a. Find z.
b. Determine the address of the same element if it is implemented in row-wise
method.
8. Write an algorithm which checks if the brackets in an expression are balanced and
reports an error if the matching brackets is missing.