CS301 Midterm Solved Mega File With Reference
CS301 Midterm Solved Mega File With Reference
com
► One
► Two
► Three
► Four
Which one of the following calling methods does not change the original value of the
argument in the calling function?
Suppose currentNode refers to a node in a linked list (using the Node class with
member variables called data and nextNode). What statement changes currentNode
so that it refers to the next node?
► currentNode ++;
► currentNode = nextNode;
► currentNode += nextNode;
► currentNode = currentNode->nextNode;
A queue where the de-queue operation depends not on FIFO, is called a priority
queue
► False
► True
► 1 pointer
► 2 pointers
► 3 pointers
► 4 pointers
I have implemented the queue with a linked list, keeping track of a front pointer
and a rear pointer. Which of these pointers will change during an insertion into an
EMPTY queue?
► Neither changes
► Only front pointer changes.
► Only rear pointer changes.
► Both change.
►8
►7
►5
►6
► Root Nodes
► Leaf Nodes
► Both of these
► None of these
A binary search tree should have minimum of ________ node/s at each level,
► One
► Two
► Three
► Four
Which one of the following is correct in respect of the above statements regarding the Binary
trees?
“+” is a _________operator.
► Unary
► Binary
► Ternary
► None of the above
A queue where the de-queue operation depends not on FIFO, is called a priority
queue
► False
► True
The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this
problem we should
► a = X (b) ;
► a = X (&b) ;
► a = X (*b) ;
► None of the given options
In the call by value methodology, a copy of the object is passed to the called
function.
► False
► True
class foo
{
public:
void x(foo f);
void y(const foo f);
void z(foo f) const;
...
Which of the three member functions can alter the PRIVATE member variables of the foo object
that activates the function?
► Only x can alter the private member variables of the object that activates the
function. (R )
► Only y can alter the private member variables of the object that activates the function.
► Only z can alter the private member variables of the object that activates the function.
► Two of the functions can alter the private member variables of the object that activates
the function.
►1
►2
► n (where n is the argument)
► There is no fixed maximum
► Log2 (n+1) -1
► Log2 (n+1)
► Log2 (n) - 1
► Log2 (n)
In the linked list implementation of the stack class, where does the push member
function places the new entry on the linked list?
► At the head
► At the tail
► After all other entries that are greater than the new entry.
► After all other entries that are smaller than the new entry.
Suppose we have a circular array implementation of the queue class, with ten items
in the queue stored at data[2] through data[11]. The CAPACITY is 42, i.e., the
array has been declared to be of size 42. Where does the push member function
place the new entry in the array?
► data[1]
► data[2]
► data[11]
► data[12]
► Prefix expression
► Postfix expression
► Infix expression
► None of these
_________ is a binary tree where every node has a value, every node's left subtree
contains only values less than or equal to the node's value, and every node's right
subtree contains only values that are greater then or equal ?
If node A in the BST is deleted, which two nodes are the candidates to take its place?
► J and I (Pending)
Let's call the node as a that requires re-balancing. Consider the two cases given
below:
►The insertion occurs outside (i.e., left-left or right-right) in cases 1 and 2. single rotation can
fix the balance in these two cases.
►The insertion occurs inside ((i.e., left-left or right-right) in cases 1 and 2. single rotation cannot
fix the balance in these two cases
► ab+c*d-
► abc*+d-
► abc+*d-
► (abc*)+d-
A Compound Data Structure is the data structure which can have multiple data
items of same type or of different types. Which of the following can be considered
compound data structure?
► Arrays
► LinkLists
► Binary Search Trees
► All of the given options
Suppose a pointer has been declared in main but has not assigned any variable
address then
► That pointer points to First byte in main function
► That pointer contains a NULL value
► None of these
► That pointer points to any memory address
ZUBAIR & JAHANZAIB 6
Here is the start of a C++ class declaration:
class foo
{
public:
void x(foo f);
void y(const foo f);
void z(foo f) const;
Which of the three member functions can alter the PRIVATE member variables of
the foo object that activates the function?
► Only x can alter the private member variables of the object that activates
the function.
► Only y can alter the private member variables of the object that activates the function.
► Only z can alter the private member variables of the object that activates the
function.
► Two of the functions can alter the private member variables of the object that
activates the function.
► delete
► peek
► pop
► remove
► Stack
► Queue
► Binary Search Tree
► AVL Tree
stack.push('7');
stack.push('8');
stack.push('9');
stack.push('10');
stack.push('11');
stack.push('12');
► 7 8 9 10 11 12
► 9 8 11 10 7 12
► 9 10 8 11 12 7
► 9 10 8 12 7 11
ZUBAIR & JAHANZAIB 7
What is the maximum depth of recursive calls a function may make?
►1
►2
► n (where n is the argument)
► There is no fixed maximum
Consider the following function:
void test_a(int n)
{
cout << n << " ";
if (n>0)
test_a(n-2);
}
What is printed by the call test_a(4)?
►42
►024
►02
►24
Queue follows,
► Last in First out
► First in Last out
► First in First out
► None of these
_________ is a binary tree where every node has a value, every node's left subtree
contains only values less than or equal to the node's value, and every node's right
subtree contains only values that are greater then or equal ?
Four statements about trees are below. Three of them are correct. Which one is
INCORRECT?
Below is a binary search tree. If we delete the value 50 using the algorithm we
discussed, what value will be in the root of the remaining tree?
_________ is a data structure that can grow easily dynamically at run time without
having to copy existing elements.
► Array
► List
► Both of these
► None of these
► Stack
► Queue
► Both of these
► None of these
Suppose that a main program has two integer variables x and y, which are given the value
0. Then the main program calls f(x,y); What are the values of x and y after the function f
finishes?
► Binary Tree
► Complete Binary Tree
► None of these
► Binary Search Tree
Searching an element in an AVL tree take maximum _______ time (where n is no. of
nodes in AVL tree),
► Log2(n+1)
► Log2(n+1) -1
Suppose that we have implemented a priority queue by storing the items in a heap.
We are now executing a reheapification downward and the out-of-place node has
priority of 42. The node's parent has a priority of 72, the left child has priority 52
and the node's right child has priority 62. Which statement best describes the status
of the reheapification.
Suppose you implement a heap (with the largest element on top) in an array.
Consider the different arrays below, determine the one that cannot possibly be a
heap:
►7654321
►7362145
►7643521
►7364251
If there are 23 external nodes in a binary tree then what will be the no. of internal
nodes in this binary tree?
► 23
► 24
► 21
► 22
If there are N external nodes in a binary tree then what will be the no. of internal
nodes in this binary tree?
► N -1
► N+1
► N+2
►N
► Reflexive
► Symmetric
► Transitive
► Associative
► Constant
► Polynomial
► Exponential
► None of the given options
ZUBAIR & JAHANZAIB 10
Which of the following is NOT a correct statement about Table ADT.
► Sorted
► Unsorted
► Heterogeneous
► Random
► A Threaded Binary Tree is a binary tree in which every node that does not have a left
child has a THREAD (in actual sense, a link) to its INORDER successor.
► A Threaded Binary Tree is a binary tree in which every node that does not have a right
child has a THREAD (in actual sense, a link) to its PREOREDR successor.
► A Threaded Binary Tree is a binary tree in which every node that does not
have a right child has a THREAD (in actual sense, a link) to its INORDER
successor.
► A Threaded Binary Tree is a binary tree in which every node that does not have a right
child has a THREAD (in actual sense, a link) to its POSTORDER successor.
Which of the following statement is NOT true about threaded binary tree?
► 11,22,33,44,55,66
► 11,22,33,44,66,55
► 11,22,33,66,44,55
► 11,22,66,33,44,55
ZUBAIR & JAHANZAIB 11
Consider a min heap, represented by the following array:
3,4,6,7,5 After calling the function deleteMin().Which of the following is the
updated min heap?
► 4,6,7,5
► 6,7,5,4
► 4,5,6,7
► 4,6,5,7
► Linear
► Exponential
► Polynomial
► None of the given options
Suppose we are sorting an array of eight integers using quick sort, and we have just
finished the first partitioning with the array looking like this:
2 5 1 7 9 12 11 10
Which formula is the best approximation for the depth of a heap with n nodes?
► log (base 2) of n
► The number of digits in n (base 10), e.g., 145 has three digits
► The square root of n
►n
Suppose you implement a Min heap (with the smallest element on top) in an array.
Consider the different arrays below; determine the one that cannot possibly be a
heap:
While joining nodes in the building of Huffman encoding tree if there are more
nodes with same frequency, we choose the nodes _______.
► Randomly
► That occur first in the text message
► That are lexically smaller among others.
► That are lexically greater among others
A binary tree with 33 internal nodes has _______ links to internal nodes.
► 31
► 32
► 33
► 66
Which traversal gives a decreasing order of elements in a heap where the max
element is stored at the top?
► post-order
► level-order
► inorder
► None of the given options
What requirement is placed on an array, so that binary search may be used to locate
an entry?
► Linked List
► Stack
► Queue
► Tree
► True
► False
► ab+c*d-
► abc*+d-
► abc+*d-
► abcd+*-
Which one of the following calling methods does not change the original value of the argument
in the calling function?
► int &x ;
► int *x ;
► int x ;
► None of the given options
► selpa
► selppa
► apples
► aaappppplleess
In the following C++ code, how many function calls are made?
int x, y, z;
x = 2;
y = 3 + x;
z = foobar(x,y);
►1
►4
►7
►8
► 50
► 60
► 70
► 80
► Add
► next
► remove
► find
► Variable
► Constant
► Inconsistent
► None of the above
► False
► True
► True
► False
Which one of the following calling methods does not change the original value of the argument
in the calling function?
Suppose that the class declaration of SomeClass includes the following function prototype.
bool LessThan( SomeClass anotherObject );
Which of the following tests in the client code correctly compares two class objects alpha
and beta?
Which one of the following operators has higher priority than all of others ?
► Multiplication operator
► Minus operator
► Plus operator
► Exponentiation operator
Four statements about trees are below. Three of them are correct. Which one is INCORRECT?
► Trees are recursively defined multi-dimensional data structures
► The order of a tree indicates a maximum number of childen allowed at each node of the
tree
► A search tree is a special type of tree where all values (i.e. keys) are ordered
► If Tree1's size is greater than Tree2's size, then the height of Tree1 must also be greater
than Tree2's height.
Searching an element in an AVL tree take maximum _______ time (where n is no. of
nodes in AVL tree),
► Log2(n+1)
► Log2(n+1) -1
► 1.44 Log2n
► 1.66 Log2n
Question No: 12 ( Marks: 1 ) - Please choose one
►1
►3
►2
►4
Which one of the following is correct in respect of the above statements regarding the Binary
trees?
► Linked List
► Stack
► Queue
► Tree
Question No: 16 ( Marks: 1 ) - Please choose one
“+” is a _________operator.
► Unary
► Binary
► Ternary
► None of the above
1
4
7
8
65+*7 5 8 + -*
657 5 8+* + -*
5 6+*7 8 5 + -*
3 5 6 * + 7 8 5 + * -
4. In an AVL tree to delete a parent with two childs in a straight line following rotations
will be required:-
a. Single
b. Double
c. Triple
d. None.
11. Each entry which points to a null value in a Singly Linked List is known as:-
a. Node
b. First Node
c. Last Node
d. Head Node
12. Non recursive calls are faster than the Recursive calls.
a. True
b. False
15. When an operator is used in between two operands this is which type of notation
a. Prefix
b. Postfix
c. Infix
d. None of the Above
1
4
7
8
42
024
02
24
Which one of the following is correct in respect of the above statements regarding the Binary
trees?
(i) and (iii) only
(i), (ii) and (iii) only
(ii) and (iii) only
(ii), (iii) and (iv) only