You are on page 1of 15

# CS-301 Data Structure

Tariq Hanif
Sahiwal

FINALTERM EXAMINATION
Spring 2012
CS301- Data Structure 25-07-2012
1. The tree data structure is a
Linear data structure
Non-linear data structure
Graphical data structure
Data structure like queue

2. In the linked list implementation of the queue class, where does the insert member
function place the new entry on the linked list?
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

3.The operation for removing an entry from a stack is traditionally called:
delete
peek
pop
remove
4.A binary tree with N internal nodes has _____ links, _______ links to internal nodes and
2N, N-1, N+1 Page 315
N-1, 2N, N+1
N+1, N-1, 2N
N+1, N-1, 2N
5.If there are N elements in an array then the number of maximum steps needed to find an
element using Binary Search is _______ .
N
N
2
N
2
log
2
N
6.A binary tree with 45 internal nodes has _______links to external nodes.
44
45
46
90

CS-301 Data Structure
Tariq Hanif
Sahiwal
7.Suppose that a selection sort of 100 items has completed 42 iterations of the main loop.
How many items are now guaranteed to be in their final spot
21
41
42
43
8.Which one of the following algorithms is least efficient,
Quick Sort
Insertion Sort
Merge Sort
Bubble Sort
9.A binary tree with 33 internal nodes has _______ links to internal nodes.
31
32
33
66
10.The maximum number of external nodes (leaves) for a binary tree of height H is
_________
2
H
2
H
+1
2
H
-1
2
H
+2
11-A complete binary tree of height ____ has nodes between 16 to 31 .
2
3
4
5
12. The worst case of building a heap of N keys is
N
N
2
Nlog2N 363
NlogN
2
N
13. Suppose we had a hash table whose hash function is n % 12, if the number 35 is already
in the hash table, which of the following numbers would cause a collision?
144
145
143
148
14-A binary tree with 24 internal nodes has ______ external nodes.
22
23
48
25

CS-301 Data Structure
Tariq Hanif
Sahiwal
15-_________ is a c data structure that can grow easily dynamically at run time without
having to copy existing elements.
Array
List
Two dimensional array
16.Whenever we write a class it begins with,
Class body
Class declaration
Class name
Class constructor
17. Which one of the following is TRUE about recursion?
Recursion extensively uses stack memory. 149
Threaded Binary Trees use the concept of recursion.
Recursive function calls consume a lot of memory.
Recursive function calls consume a lot of memory.
18. If we insert a new node in an AVL tree which is perfectly balanced tree, then we will
need ________ to keep it AVL.
One rotation
Two rotations
Rotations equal to number of levels
No rotation at all
19. The worst case of deletion in AVL tree requires _________.
Only one rotation
Rotation at each non-leaf node
Rotation at each leaf node
Rotations equal to log
2
N
20. In Threaded Binary Tree, every node that does not have a right-child has a thread to its
In-order predecessor
Pre-order successor
In-order successor
Pre-order predecessor
21-In the Disjoint sets, union is a _________ time operation.
Constant
Variable
Exponential
22. Merge sort and quick sort both fall into the same category of sorting algorithms, which is
known as:
O (NlogN) sorts
Interchange sorts
Complex sorts

CS-301 Data Structure
Tariq Hanif
Sahiwal
23-In an array list, the worst case of removing an element is :
To remove an element from the end of the list 16
To remove an element from the start of the list
We cannot remove element from an array list
To remove an element from the middle of the list
24. Which one of the following is NOT true about transient object?
The lifetime of a transient object can exceed that of the application which is accessing it.
An instance of an object type.
Its lifetime cannot exceed that of the application. Not sure
Application can also delete a transient object at any time.
25 .In case of deleting a node from AVL tree, rotation could prolong to the ............... node.
Leaf
Root
Middle node
Sibling
26- Left pointer of dummy node in a threaded binary tree points to
Itself while the right pointer points to the root of tree.
Root node of the tree while the right pointer points itself
Root node of the tree while the right pointer is always NULL.
NULL while the right pointer of dummy node points to the itself.
27. In threaded Binary tree, we convert ________ pointers of the tree to threads.
Left
Right
Null 323
all
28. Which one of the following is NOT true regarding the skip list?
Each list S
i
contains the special keys + infinity and - infinity.
List S
0
contains the keys of S in non-decreasing order.
Each list is a subsequence of the previous one.
List S
h
contains only the n special keys.

29.The definition of Transitivity property is
For all element x member of S, x R x
For all elements x and y, x R y if and only if y R x
For all elements x, y and z, if x R y and y R z then x R z
For all elements w, x, y and z, if x R y and w R z then x R z
.30.Which one of the following is NOT an example of equivalence relation:
Electrical connectivity
Set of people
<= relation
Set of pixels
31.A find(x) on element x is performed by :
returning exactly the same node that is found.
returning the root of the tree containing x.
returning the whole tree itself containing x.
returning "true".

CS-301 Data Structure
Tariq Hanif
Sahiwal
32.A simple sorting algorithm like selection sort or bubble sort has a worst-case of
O(1) time because all lists take the same amount of time to sort
O(n) time because it has to perform n swaps to order the list.
O(n
2
) time because sorting 1 element takes O(n) time
O(n
3
) time, because the worst case has really random input which takes longer to sort
33.Suppose A is an array containing numbers in increasing order, but some numbers occur
more than once. When using a binary search for a value, the binary search always finds
____________
the first occurrence of value.
the second occurrence of value.
may find first or second occurrence of value.
It will give an error.

34.When unions are done by weight (size) and N=1000,000 where N is the number of nodes
then what will be the maximum levels of tree ?
1000,000
100
20
200
35. What is the best definition of collision in a hash table?
Two entries are identical except for their keys
Two entries with different data have different keys.
Two entries with different keys have the same hash value.
Two entries with the same key have different hash values.
36. Which of the following is NOT true regarding the maze generation?
Randomly remove walls until the entrance and exit cells are in the same set.
Removing a wall is the same as doing a union operation.
Remove a randomly chosen wall if the cells it separates are already in the same set.
Do not remove a randomly chosen wall if the cells it separates are already in the same set.
37. Which of the given option is NOT a factor in Union by Size:
Maintain sizes (number of nodes) of all trees
Make smaller tree, the subtree of the larger one.
Make the larger tree, the subtree of the smaller one
Maintain sizes (number of nodes) while performing union operation
38. While deleting a node from Binary Search Tree (BST), which of the following number of
cases we have to take care of?.
1
4
2
3 176

39. Function Calls are made with the help of which of the following data structures?
Hash Table
Stack
Binary Tree
Queue

CS-301 Data Structure
Tariq Hanif
Sahiwal

40.A binary relation R over S is called an equivalence relation if it has which of the following
property/properties?
Reflexivity
Symmetry
Transitivity
Reflexivity, Symmetry and Transitivity 394

FINALTERM EXAMINATION
Spring 2012
CS301- Data Structure 28-07-2012

1. Numbers 5, 222, 4, 48 are inserted in a queue, which one will be removed first?
48
4
222
5
1. The tree data structure is a
Linear data structure
linear data structure 112 - on N
Graphical data structure
Data structure like queue
3. 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?
if (alpha < beta)
if (alpha.LessThan(beta))
if (LessThan(alpha, beta))
if (LessThan(alpha).beta)

CS-301 Data Structure
Tariq Hanif
Sahiwal

4.If there are 56 internal nodes in a binary tree then how many external nodes this binary
tree will have?
54
55
56
57
5. A binary tree of N nodes has _______.
Log
10
N levels
227 N levels
2
Log
N / 2 levels
N x 2 levels
6. Binary Search is an algorithm of searching, used with the ______ data.
439 Sorted
Unsorted
Heterogeneous
Random
7. If there are N elements in an array then the number of maximum steps needed to
find an element using Binary Search is _______.
N
N
2
N
2
Nlog
log
2
N

CS-301 Data Structure
Tariq Hanif
Sahiwal
8. Consider to following array
23 15 5 12 40 10 7
After the first pass of a particular algorithm, the array looks like
15 5 12 23 10 7 40
Name the algorithm used
Heap sort
Selection sort
Insertion sort
according to rule Bubble sort
9. Which of the following statement is true about dummy node of threaded binary
tree?
This dummy node never has a value.
This dummy node has always some dummy value.
231 . This dummy node has either no value or some dummy value
This dummy node has always some integer value.
10. Which of the following statement is NOT true about threaded binary tree?
Right thread of the right-most node points to the dummy node.
Left thread of the left-most node points to the dummy node.
The left pointer of dummy node points to the root node of the tree.
321 . node dummy most node points to the - Left thread of the right
11. A complete binary tree is a tree that is _________ filled, with the possible
exception of the bottom level.
Partially
323 etely Compl
Incompletely
Partly

CS-301 Data Structure
Tariq Hanif
Sahiwal
12. Consider a min heap, represented by the following array:
10,30,20,70,40,50,80,60
After inserting a node with value 31.Which of the following is the updated min heap?

336 10,30,20,31,40,50,80,60,70
10,30,20,70,40,50,80,60,31
10, 31,20,30,40,50,80,60,31
31,10,30,20,70,40,50,80,60
13. Consider a min heap, represented by the following array:
11,22,33,44,55
After inserting a node with value 66.Which of the following is the updated min heap?

336 11,22,33,44,55,66
11,22,33,44,66,55
11,22,33,66,44,55
11,22,66,33,44,55
14. What requirement is placed on an array, so that binary search may be used to
locate an entry?
The array elements must form a heap.
The array must have at least 2 entries.
Array must be sorted
The arrays size must be a power of two.
15. We can not remove items randomly from ___________
431 Stack
Two dimensional arrays
Array

CS-301 Data Structure
Tariq Hanif
Sahiwal
16. + is a _________operator.
Unary
61 Binary
Ternary
Unary and Binary
17. Huffman encoding uses _________ to develop codes of varying lengths for the
letters used in the original message.
Stack
Queue
299 Binary tree
18. Merge sort and quick sort both falls into the same category of sorting algorithms,
which is known as:
O (NlogN) sorts
Interchange sorts
Complex sorts
19. Suppose h is height of Binary Search Tree, then maximum steps required for a search
operation are
382 1 h
H+1
2
h
2
h
1

CS-301 Data Structure
Tariq Hanif
Sahiwal
20. Suppose currentNode refers to a node in a linked list (using the Node class with member
variables called data and nextNode). Which statement changes currentNode so that it refers to
the next node?
currentNode ++
currentNode = nextNode;
currentNode += nextNode;
>nextNode; - currentNode = currentNode
21. During insertion, there are ________ cases for rotation in an AVL tree.
2
3
229 4
5
22. Which of the following can NOT be a max-heap ?
7 6 5 4 3 2 1
7 3 6 2 1 4 5
7 6 4 3 5 2 1
7 3 6 4 2 5 1
23. In min-heap, the node with minimum value is _____.
519 Root
Left most child
Right most child
It can be anywhere in the heap.
24. While building Huffman encoding tree, the new node that is the result of joining
two nodes has the frequency.
Equal to the small frequency
Equal to the greater frequency
293 Equal to sum of the two frequencies

CS-301 Data Structure
Tariq Hanif
Sahiwal
Equal to difference of the two frequencies
25. If there are 23 external nodes in a Binary tree, then number of internal nodes will
be :
24
21
22
23
26. If there are N internal nodes in a binary tree, then number of external nodes will
be:
N -1
N
303 N +1
N +2
27. Which of the following is a property of Binary tree?
internal nodes. N A binary tree of N external nodes has
303 A binary tree of N internal nodes has N+1 external nodes.
A binary tree of N external nodes has N+1 internal nodes.
A binary tree of N internal nodes has N-1 external nodes.
28. Which one of the following is NOT true regarding the skip list?
Each list S
i
contains the special keys + infinity and - infinity.
List S
0
contains the keys of S in non-decreasing order.
Each list is a subsequence of the previous one.
446 . contains only the n special keys
h
st S Li

CS-301 Data Structure
Tariq Hanif
Sahiwal
29. Which one of the following is NOT the property of equivalence relation:
Reflexive
Symmetric
Transitive
385 Associative
30. The definition of Transitivity property is
For all element x member of S, x R x
For all elements x and y, x R y if and only if y R x
385 For all elements x, y and z, if x R y and y R z then x R z
For all elements w, x, y and z, if x R y and w R z then x R z
31. A find(x) on element x is performed by :
returning exactly the same node that is found
returning the root of the tree containing x.
returning the whole tree itself containing x.
returning "true".
32. A simple sorting algorithm like selection sort or bubble sort has a worst-case of
O(1) time because all lists take the same amount of time to sort
O(n) time because it has to perform n swaps to order the list.
487 ) time because sorting 1 element takes O(n) time
2
O(n
O(n
3
) time, because the worst case has really random input which takes longer to sort.
33. Here is an array of ten integers:
5 3 8 9 1 7 0 2 6 4
Array after the FIRST iteration of the main loop in selection sort algorithm will be
(sorting from smallest to largest):
477 0 3 8 9 1 7 5 2 6 4
2 6 4 0 3 8 9 1 7 5

CS-301 Data Structure
Tariq Hanif
Sahiwal
2 6 4 9 1 7 0 3 8 5
0 3 8 2 6 4 9 1 7 5
34. Suppose A is an array containing numbers in increasing order, but some numbers
occur more than once. When using a binary search for a value, the binary search
always finds ____________
the first occurrence of value.
the second occurrence of value.
may find first or second occurrence of value
It will give an error.
35. When unions are done by weight (size), the depth of any element is never greater
than
420 n
2
log
nlog
2
n
nlog
2
n+1
log
2
n-1
36. When unions are done by weight (size) and N=1000,000 where N is the number
of nodes then what will be the maximum levels of tree ?
1000,000
100
420 20
200
37. What is the best definition of collision in a hash table?
Two entries are identical except for their keys.
Two entries with different data have different keys.
471 Two entries with different keys have the same hash value.
Two entries with the same key have different hash values.

CS-301 Data Structure
Tariq Hanif
Sahiwal
38. Suppose currentNode refers to a node in a linked list (using the Node class with member
variables called data and nextNode). Which boolean expression will be true when
CurrentNode refers to the tail node of the list?

) (currentNode == null
(currentNode->nextNode == null)
(nextNode.data == null)
(currentNode.data == 0.0)
39. Consider the following infix expression:
x y * a + b / c
Which of the following is a correct equivalent expression for the above?
x y -a * b +c /
x *y a - b c / +
+ b c / - x y a *
x y a * - b/ + c
40. If we have 1,000 sets each containing a unique person, then which of the following
relations would be true on each set?
Reflexive
Symmetric
Transitive
Associative