Data Structures and Algorithms
Data Structures and Algorithms
APPENDIX
486
Quiz
QUIZ-I
Set-1
1.
2.
3.
Appendix D: Quiz
4.
5.
For method to be an interface between the outside world and a class, it has to be declared
(a) private
(b) protected
(c) external
(d) public
6.
7.
8.
(b) OOP
(d) A database language
(c) new
9.
487
(d) delete
10. If the piece of the code can be implemented as a macro or as inline function, which of the following
factors favour implementation as an infinite function?
(a) flexibility to manipulate as a pointer
(b) increasing with same components (like variable in an expression), in the wrong way
(c) source code size
(d) speed of execution
11. Which of the following is not a storage class supported by C++?
(a) register
(b) mutable
(c) dynamic
(d) auto
12. In skip list representation while performing search, number of comparisons to be reduced
to__________, if we keep a pointer to a middle pair.
(a) n/4+1
(b) n/2
(c) n/2+1
(d) n/4
13. Sorted array of n elements can be searched in________ time with the binary search method
(a) (n)
(b) O(logn/2) (c) O(n)
(d) O(log n)
14. The amount of instruction space that is needed depends on factors such as
(a) the compiler used
.
(b) the target computer.
(c) the compiler options.
(d) the compiler, the compiler options, the target computer.
15. A pointer to a base class type can be referred to an object of a derived class type, this is called
_______.
(a) polymorphism
(b) inheritance
(c) memory addressing
(d) encapsulation
16. In a circularly linked list organization, insertion of a record involves the modification of
(a) 1 pointer
(b) 2 pointers
(c) 3 pointers (d) no pointer
488
Key to Set-1
1. (b)
2.(d)
3.(a)
4.(a)
5.(d)
6.(b)
7.(d)
8.(c)
9.(c)
10.(d)
11. (c)
12.(c)
13.(d)
14.(d)
15.(a)
16.(b)
17.(c)
18.(a)
19.(d)
20.(b)
QUIZ-I
Set-2
1.
2.
Assume that the random number generating function, rand() returns an integer between 0 and 1000
(both inclusive). To randomly generate a number between a and b (both inclusive), use the expression:
(a) (rand()%(b-a+1))+a
(b) (rand()%a)+b
(c) rand()%(b-a)
(d) (rand()%(b-a))+a
3.
Which of the following type of the functions is an ideal candidate for being declared inline?
(a) A function that is not small and is called frequently.
(b) A function that is small and is not called frequently.
(c) A function that is not small and is not called frequently.
(d) A function that is small and is called frequently.
4.
Time taken to initialize an empty dictionary considering b number of positions in hash table is
________.
(a) O(b)
(b) O(2b)
(c) O(nb)
(d) O(b/n)
5.
Appendix D: Quiz
6.
&x)
then
(a) it results in compile time error
(c) it results in run time error
7.
8.
(b) classes
(d) by linking
(d) public
9.
(d) variable
(c) asm
(d) virtual
16. The _______ asymptotically bounds a function from above and below
(a) -notation
(b) -notation
(c) -notation
(d) -notation
17. Which of the following is useful in implementing quick sort?
(a) set (b) list (c) queue (d) stack
489
490
Key to Set-2
1. (b)
2.(a)
3.(d)
4.(a)
5.(c)
6.(a)
7.(d)
8.(c)
9.(a)
10.(b)
11. (b)
12.(c)
13.(a)
14.(b)
15.(d)
16.(c)
17.(b)
18.(a)
19.(b)
20.(b)
QUIZ-I
Set-3
1.
2.
Forgetting to include a file (like cmath or math.h) that is necessary will result in
(a) Warning when the program is compiled
(b) compilation error
(c) Warning when the program is run
(d) error at link time
4.
The ability of a function or operator to act in different ways on different data types is called
(a) Overloaded
(b) inheritance
(c) polymorphism
(d) glorified
5.
6.
7.
(d) a label
Appendix D: Quiz
8.
9.
491
10. When there are same functions in base and derived classes, then_______ is used to differentiate them.
(a) inline (b) this pointer (c) virtual (d) template
11. Which of the following class constructor will be invoked first?
(a) Virtual base class
(b) abstract class
(c) base class
12. An inline function may be expanded
(a) at the point of its call during compilation
(c) it can not be expanded
13. A function that is called automatically each time an object is destroyed is a ______
(a) destructor (b) terminator (c) destroyer
(d) constructor
14. Queue can be used to implement
(a) Quick sort (b) radix sort
(c) recursion
Key to Set-3
1. (a)
2.(a)
3.(b)
4.(c)
5.(b)
6.(d)
7.(d)
8.(c)
9.(a)
10.(c)
11. (a)
12.(a)
13.(a)
14.(b)
15.(c)
16.(a)
17.(a)
18.(a)
19.(b)
20.(c)
492
QUIZ-I
1.
Set-4
(d) Objects
2.
The member function can find out_______ of the object using this
(a) variables (b) class
(c) data types (d) address
3.
5.
6.
7.
8.
9.
Template supports
(a) generic programming
(c) procedural programming
(d) throw
(d) protected
Appendix D: Quiz
493
ob1, ob2, ob3 are the instances of A. Then what is the value of c in ob1, ob2 and ob3?
(a) 0 0 0
(b) 1 1 1
(c) 3 3 3
(d) 1 2 3
18. In skip lists the number of elements at level i is given by the formulae.
(a) 2i
(b) n/2i
(c) i!
(d) n i
19. _________ occurs when there is not room in the home bucket for the new pair
(a) overflow
(b) collision
(c) underflow
(d) cognition
20. ________ is a computer programming technique used in hashing to resolve hash collisions, cases when
two different values to be searched for produce the same hash key
(a) Secondary hashing
(b) internal hashing
(c) double hashing
(d) external hashing
Key to Set-4
1. (d)
2.(d)
3.(a)
4.(a)
5.(b)
6.(c)
7.(a)
8.(b)
9.(d)
10.(c)
11. (a)
12.(b)
13.(b)
14.(d)
15.(d)
16.(d)
17.(d)
18.(b)
19.(a)
20.(c)
494
QUIZ-I
1.
Set-5
(c) no error
3.
4.
5.
6.
Which one of the following function calls is illegal? (Assume x, y, z are declared as int)
(a) foo(x, y) ; (b) foo(x);
(c) foo(y, y) ; (d) foo(x, y, z);
7.
Overloading involves_________
(a) multiple functions with different names.
(b) multiple functions defined with the same name.
(c) one function with multiple names.
(d) one function with a variety of arguments.
8.
Appendix D: Quiz
9.
(c) overridden
495
(d) permanent
Bucket
14. A hash table can store maximum of 10 records. Currently there are records in locations 1, 3, 4, 8, 9, 10.
The probability of a new record going into location 2, with a hash function resolving collisions by
linear probing is
(a) 0.6
(b) 0.1
(c) 0.2
(d) 0.5
15. ______ is the amount of time the computer needs to run to completion.
(a) waiting time
(b) space complexity
(c) time complexity
(d) average time
16. ______ is a dynamically updateable disk-based index structure which implements a hashing scheme
(a) rehashing
(b) primary clustering
(c) chaining (d) extendible hashing
17. _____ eliminates primary clustering, but not secondary clustering
(a) Quadratic probing
(b) Rehashing
(c) Extendible hashing
(d) Linear probing
18. Chains augmented with additional forward pointers are called
(a) couision pointers (b)
couision chain (c) hash pointers
19. For all n, n > no, (f(n)) = (g(n)) if positive constants c1 and c2 and n0 exists such that
(a) c1 g(n) > f(n) > c2 g(n)
(b) c1 g(n) > f(n) c2 g(n)
(c) c1 g(n) > f(n) c2 g(n)
(d) c1 g(n) f(n) > c2 g(n)
20. Consider the following binary tree. Which one of the following statements is false?
A
B
D
C
E
(a) F is ancestor of C
(c) G is descendent of A
(b) A is ancestor of C
(d) F and G are siblings
Key to Set-5
1. (a)
2.(b)
3.(b)
4.(b)
5.(c)
6.(d)
7.(b)
8.(b)
9.(a)
10.(b)
11. (c)
12.(b)
13.(c)
14.(a)
15.(c)
16.(d)
17.(a)
18.(d)
19.(a)
20.(a)
496
QUIZ-II
Set-1
1.
2.
3.
The smallest element in a max-heap is always at a ____ of the tree assuming that all elements are
distinct.
(a) leaf
(b) root
(c) descendent of root
(d) ascendant of leaf
4.
5.
Which one of the following techniques is preferred when the amount of data to be sorted exceeds the
main memory?
(a) Internal sorting
(b) External sorting
(c) Quick sort
(d) Heap sort
6.
(d) (log n)
(d) O(log n)
7.
In indexed binary search tree left-size field also gives the ___ of an element with respect to the
elements in its sub tree.
(a) rank
(b) sorted order
(c) median
(d) index
8.
9.
(d) n
After deletion of a node in an AVL tree, a maximum of ______ rotation(s) is sufficient to restore
balance.
(a) 2
(b) 0
(c) 1
(d) 3
10. In an AVL tree RR rotation the node which is imbalanced will move towards ______.
(a) left subtree
(b) not move
(c) root
(d) right subtree
11. ______is essentially a binary tree with special update and access rules.
(a) AVL tree
(b) M-way search tree
(c) Splay tree (d) B-Tree
12. In Red-Black tress, red pointers are represented by ___________
(a) solid lines (b) thin lines
(c) red lines
(d) circles
13. A multiway tree of order m is an ordered tree where each node has _________ children.
(a) at most m
(b) not m (c) m (d) at least m
14. In B-tree of height h contains n-nodes; the time complexity for insert operation is _____.
(a) O(h log n) (b) O(h*n) (c) O(log h)
(d) O(h)
15. Deletion of element from a B-tree from a leaf that containing more than the minimum no. of elements
requires ________
(a) modifying parent
(b) Simple deletion of element
(c) modifying left sibling
(d) modifying right sibling
Appendix D: Quiz
497
16. The brute force pattern matching algorithm compares the pattern P with the text T for __________
values
(a) random (b) consecutive (c) sorted (d) binary
17. In bad character shift the length of the shift is equal to the
(a) length of the pattern (b) 3 positions (c) zero positions
18. In KMP pattern matching algorithm the pre processing function computes the ________ of pattern
matches within itself
(a) shifting (b) comparisons (c) number (d) mismatches
19. A compressed trie has internal nodes of degree at least equal to
(a) 2
(b) 0
(c) 3
(d) 1
20. which of the following operation is not supported by tries
(a) delete
(b) find
(c) insert
(d) sorting
Key to Set-1
1. (d)
2.(b)
3.(a)
4.(a)
5.(b)
6.(c)
7.(a)
8.(a)
9.(c)
10.(a)
11. (c)
12.(b)
13.(a)
14.(d)
15.(b)
16.(b)
17.(a)
18.(a)
19.(a)
20.(d)
QUIZ-II
Set-2
1.
2.
3.
(d) log n
4.
In the array implementation of a Binary Heap where the root has index 1, the parent node of the node
with index i is the node with index:
(a) (i 1)/2
(b) (i + 1)/2
(c) 2*i
(d) i/2
5.
External Merge Sort is based on the _______ sorting and _______ merging principle.
(a) internal external
(b) externalinternal
(c) internalinternal
(d) externalexternal
6.
In binary search tree, if the element to be inserted is greater than the root node, the element is inserted
in _________.
(a) left sub-tree (b) right sub-tree (c) cannot be inserted
(d) root
7.
498
8.
9.
The _______imbalances caused due to insertions in AVL Tree is often called single rotation.
(a) LR & RL
(b) RR & RL
(c) LL & RR
(d) LL & LR
10. In deletion of AVL search tree which of the following is not classified imbalance
(a) R2 (b) R1 (c) R0 (d) R-1
11. The run time for a splay (x) operation is proportional to the length of the ____ path for x.
(a) Search (b) Insert (c) Join
(d) Shortest
12. A rotation is local operation in a search tree that preserves _______ traversal key ordering
(a) Post order (b) In order
(c) Preorder
(d) Past order
13. In Red-black trees the value of any node is ______ than the value of its right child
(a) greater (b) equal (c) less
(d) No relation
14. In a B-tree of height h containing n nodes the time complexity of delete operation is ______
(a) O(h*n) (b) O(h)
(c) O(h log n) (d) O(log h)
15. In Deletion from a B-tree case 2 is transformed into case 1 by replacing the deleted element with the
______ element in its right neighboring subtree
(a) root
(b) smallest
(c) largest (d) leftmost
16. In the Boyer-Moore algorithm if the pattern P is algorithm the comparison goes to the next character
if the first character is
(a) m
(b) 1
(c) a
(d) space
17. In the Boyer-Moore algorithm let the string T be this is a test of the Boyer-Moore algorithm and the
pattern P is algorithm after the first comparison _______ takes place.
(a) matching shift
(b) non matching shift
(c) good suffix shift
(d) bad character shift
18. In KMP pattern matching algorithm pre-processing is done by an auxiliary function known as
(a) failure function (b) prefix function (c) insert function (d) postfix function
19. In compressed tries the chain of ______ nodes are compressed
(a) redundant (b) internal (c) leaf
(d) external
20. In standard trie each node except the _____ is labeled with a character
(a) external
(b) leaf
(c) root
(d) internal
Key to Set-2
1. (d)
2.(c)
3.(b)
4.(d)
5.(a)
6.(b)
7.(d)
8.(d)
9.(c)
10.(a)
11. (a)
12.(b)
13.(c)
14.(b)
15.(b)
16.(a)
17.(c)
18.(a)
19.(a)
20.(c)
Appendix D: Quiz
QUIZ-II
499
Set-3
1.
2.
3.
The sequence [2, 4, 8, 12, 17, 15, 25, 20] forms a min-heap. How many elements are there in the left
subtree (including root)?
(a) 3
(b) 4
(c) 5
(d) None of these
4.
5.
Assuming we have to sort n records of equal length stored in a file. The systems main memory can
hold exactly m records (with m much smaller than n). So the source file is divided into ______ parts.
(a) n
(b) m
(c) n/m
(d) m/n
6.
Which of the following statements is false with respect to binary search tree?
(a) Root has maximum element
(b) Right child is greater than left child
(c) Right child is greater than parent node (d) Left child is less than parent node
7.
In a binary search tree keys are inserted in the order 1, 2, 3, , n as result? Find insert, delete
operations take ____ time.
(a) O (n log n) (b) O(n)
(c) O (n2) (d) O (log n)
8.
9.
(d) Adelson
After inserting an element in AVL tree node A became imbalanced. The new element added is the left
child of right grand child of node A. Then the imbalance is of type
(a) RR
(b) RL
(c) LL (d) LR
10. If a new node is added on the right side and the AVL tree is imbalance then the balance factor of the
node which is imbalanced is
(a) -2 (b) 2 (c) 0 (d) either 2 or -2
11. In splay trees, if the amortized costs are lower than the actual costs then potential is ____.
(a) constant
(b) increasing
(c) decreasing
(d) same
12. In Red-Black trees every path from the root to an external node has _____ pointers
(a) one black
(b) two red
(c) Two black (d) one red
13. In Red Black tress every path from the root to a leaf contains the same number of
(a) red nodes
(b) nodes (c) leaf nodes (d) black nodes
14. An m-way search tree of height h may have as few as ______ nodes.
(a) mh-1
(b) m
(c) h
(d) m*h-1
15. A B-tree of order m is also known as ______.
(a) m-ordered tree
(b) m-way search tree
(c) Binary search tree
(d) ordered search tree
500
16. _______ algorithm is preferred for pattern matching when the length is of short duration
(a) Morris
(b) Brute force
(c) Boyer-Moore
(d) KMP
17. In Boyer-Moore algorithm _____ number of pre-computed functions are there
(a) 3 (b) 1 (c) 2 (d) 0
18. In KMP pattern matching algorithm, the time complexity of pre-processing function is
(d) O( log n)
(a) O(n log n)
(b) O(n)
(c) O(n2)
19. A trie structure is a complete ___________tree.
(a) binary
(b) m-ary
(c) B-tree
(d) search
20. A standard trie supports delete in _____ time where m is size of string parameter and d is size of the
alphabet.
(a) O(dm)
(b) O(d)*O(m)
(c) O(dm)
(d) O(d+m)
Key to Set-3
1. (d)
2.(a)
3.(c)
4.(d)
5.(c)
6.(a)
7.(b)
8.(b)
9.(b)
10.(a)
11. (c)
12.(c)
13.(d)
14.(c)
15.(b)
16.(b)
17.(c)
18.(b)
19.(b)
20.(a)
QUIZ-II
Set-4
1.
2.
Using heap data structure, finding the minimum element of the n-array will only take _______ (it is
located at the root of the heap).
(a) O(log n)
(b) O(n log n)
(c) O(1)
(d) O(n)
3.
In a priority queue (implemented as a heap tree), the entry with the highest priority is always at the
____ node.
(a) leaf
(b) root
(c) descendent of root
(d) ascendant of leaf
4.
In the array implementation of a Binary Heap where the root has index 1, the right child of the node
with index i is the node with index:
(a) (i 1)/2
(b) (i + 1)/2
(c) 2*i + 1
(d) 2*i
5.
The simplest form of external sorting is to use a fast internal sort with good locality of reference.
________ is one sort algorithm that is generally very fast and has good locality of reference.
(a) Quick sort
(b) Heap sort
(c) Merge sort
(d) Insertion sort
6.
______ is derived from an ordinary binary search tree by adding the field left size to each tree node.
(a) indexed binary search tree (b) Binary search tree with duplicates
(c) binary tree
(d) Lexographical binary search tree
7.
In a binary search tree keys are inserted in the order 1, 2, 3.........n as result? Find, insert, delete
operations take ______ time.
(a) O(log n)
(b) O(n log n) (c) O(n2) (d) O(n)
Appendix D: Quiz
501
8.
9.
In AVL tree the transformation for an _____ imbalance can be viewed as an RR rotation followed by
an LL rotation.
(a) LR
(b) RR
(c) RL
(d) LL
(d) dash
20. An inverted file is a file structure in which every list contain only ______ record
(a) 0
(b) 2
(c) 1
(d) 3
Key to Set-4
1. (a)
2.(c)
3.(b)
4.(c)
5.(a)
6.(a)
7.(d)
8.(d)
9.(a)
10.(a)
11. (b)
12.(a)
13.(a)
14.(c)
15.(c)
16.(a)
17.(b)
18.(d)
19.(a)
20.(c)
502
QUIZ-II
Set-5
1.
2.
In a Maximum Binary Heap, the node with the minimum key is:
(a) the root node.
(b) one of the leaf nodes.
(c) the left-most node.
(d) the right-most node.
3.
4.
With the heap implementation, the insert and delete operations of the priority queue run in ________
time.
(a) (log n)
(b) (n log n)
(c) (n2)
(d) (n)
5.
After the initial run construction phase, the number of passes required using k-way merging is
_________; where n/m is the number of initial runs and k is the merge order.
(a) k(n/m)
(b) (n/m)/k
(d) (n)
(c) log k ( n / m)
(d) log k ( n / m)
6.
In a binary search tree if the key element is less than root element then _____subtree must be searched
(a) root
(b) center (c) right
(d) left
7.
A binary search tree is constructed with the following keys 20, 22, 26, 21, 13, 19, 18, 15, 26, 28. These
keys are inserted in that order. Then the total keys in the left subtree and the right subtree of the tree
are respectively.
(a) 7, 3
(b) 4, 6
(c) 5, 5
(d) 6, 4
8.
9.
(d) -1, 0, 2
After inserting an element in AVL tree, node A becomes imbalanced. Then new element added is the
right child of right grand child of node A. Then the imbalances is of type
(a) LL
(b) RL
(c) LR
(d) RR
Appendix D: Quiz
503
15. A 200-way search tree of height 8 can hold a minimum no. of ______ nodes.
(a) 8 (b) 200
(c) 8*log 200 (d) 2008-1
16. Given string T and pattern P the pattern matching problem consists of finding a substring of _____
equal to _____.
(a) P P
(b) T P
(c) T T
(d) P T
17. In the Boyer-Moore algorithm bad character shift algorithm is also known as
(a) occurrence shift
(b) matching shift
(c) non matching shift
(d) good suffix shift
18. Which of the following pattern matching algorithm does not require preprocessing on text or pattern?
(a) Robin Karp (b) Brute force (c) Knuth-Morris-Pratt (d) Boyer
19. The structures occur frequently in the area of information organization and _______
(a) storing
(b) search
(c) retrieval
(d) management
20. A standard trie supports insert in ________ time where m is size of string parameter and d is size of the
alphabet.
(a) O(dm)
(b) O(dm)
(c) O(d+m)
(d) O(d)*O(m)
Key to Set-5
1. (a)
2.(b)
3.(b)
4.(a)
5.(d)
6.(d)
7.(b)
8.(c)
9.(d)
10.(a)
11. (c)
12.(b)
13.(d)
14.(b)
15.(a)
16.(b)
17.(a)
18.(b)
19.(c)
20.(a)