You are on page 1of 18

Appendix C: Questions and Answers

APPENDIX

486

Quiz

QUIZ-I

Set-1

1.

Dividing a program into functions


(a) is the key to object-oriented programming.
(b) makes the program easier to conceptualize.
(c) makes the program run faster.
(d) may reduce the size of the program.

2.

Which one of the following statements is not correct?


(a) A destructor is not inherited.
(b) A constructor can not be called explicitly.
(c) A constructor is not inherited.
(d) A destructor can be called explicitly.

3.

The following program fragment:


int a = 10;
int const &b = a;
a = 11;
cout << a << b << endl;

(a) prints 1111


(c) results in compile-time error

(b) prints 1011


(d) results in run-time error

Appendix D: Quiz

4.

Choose the correct statement from the following?


(a) In a class, the access control is private by default.
(b) In a struct, the access control is private by default.
(c) In a class, the access control is static by default.
(d) In a class, the access control is public by default.

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.

Experimental methods are used in


(a) performance analysis
(b) performance measurements
(c) efficiency
(d) performance analysis and performance measurements

7.

The time taken by the program p is the sum of


(a) the run time and loading time
(b) liking time and loading time
(c) liking time and compilation time (d) compilation time and the run time

8.

C++ was originally called


(a) Procedural programming language
(c) C with classes

(b) OOP
(d) A database language

The C++ memory allocation function is


(a) erase
(b) free

(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

Advanced Data Structures and Algorithms in C++

17. Average time complexity of insert operation on skip list of n elements is


(a) O(n)
(b) O(n log n)
(c) O(log n)
(d) O(1)
18. Separate chaining is also known as_______.
(a) external chaining
(b) internal chaining
(c) double chaining
(d) separate chaining
19. In ________, hash function key is partitioned into number of parts of equal lengths and then added
together.
(a) Digital analysis
(b) Division
(c) Mid square method
(d) Folding
20. When the size of the record is very small which technique occupies more space?
(a) Linear Probing
(b) Chaining
(c) Quadratic probing
(d) Rehashing

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.

__________ is used to represent static member function with class name.


(a) Increment operator
(b) Scope resolution operator
(c) Conditional operator
(d) Decrement operator

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.

Reusability is a desirable feature of a language as it


(a) reduces the compilation time (b) reduces the execution time
(c) decreases the testing time
(d) increases the maintenance cost

Appendix D: Quiz

6.

Consider the following program code


int a = 1,b = 2;
a = change(b);
cout << a << b;

if the function change() is codes as


int change(const int
{
x = 10;
return (11);
}

&x)

then
(a) it results in compile time error
(c) it results in run time error

(b) it prints 1110


(d) it prints 112

7.

The components of time complexity are


(a) the compiler used.
(b) the target computer.
(c) the computer options.
(d) the compiler, the computer options, the target computer.

8.

A C++ source file is transformed into an executable file


(a) object file and linking
(c) by compiling the source file into an object file

(b) classes
(d) by linking

The fields in a class, of a C++ program are by default


(a) Private
(b) static
(c) protected

(d) public

9.

10. Which the following can not be declared static?


(a) member variables
(b) object
(c) functions
(d) functions and member variables
11. this pointer points to___________.
(a) function
(b) object
(c) class

(d) variable

12. Choose the correct statement regarding inline functions


(a) It increases the code size
(b) It reduces the compilation time.
(c) It reduces the execution time
(d) it slows down execution
13. Which is not a keyword
(a) implicit
(b) using

(c) asm

(d) virtual

14. Open addressing is also known as___________


(a) Open hashing
(b) closed hashing (c) double hashing

(d) separate hashing

15. A C++ exception handling mechanism is said to be


(a) catch handle
(b) non-resumptive (c) resumptive

(d) stack unwinding

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

Advanced Data Structures and Algorithms in C++

18. Average time complexity of delete operation on skip list is


(a) O(log n)
(b) O(n)
(c) O(n log n)
(d) O(1)
19. In an n-pair dictionary represented as a sorted chain the number of comparisons for search can be
reduced to ________ if we use a pointer to the middle pair.
(a) n/2
(b) n/2+1
(c) log n
(d) n
20. Which of the following collision resolution technique requires pointers?
(a) Open addressing
(b) Chaining
(c) Closed hashing
(d) Probing

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.

A variable defined within a block is visible


(a) from the point of definition onwards in the block.
(b) from the point of definition onwards.
(c) from the point of definition onwards in the function
(d) through the function

2.

Consider the following program code


static char x[3] = 1234;
cout << x;

A complete c++ program with these two statements


(a) will give a compilation error
(b)
prints 1234
(c) prints 123
(d)
prints 1234 followed by some junk
3.

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.

The approaches used to determine the performance of a program are


(a) Analytical
(b) analytical and experimental
(c) analytical and theoretical
(d) experimental

6.

The goto statement causes control to go to


(a) An operator (b) a variable (c) a function

7.

(d) a label

The ability to define several functions with the same is called


(a) operator overloading
(b) method overloading
(c) overloading
(d) function overloading

Appendix D: Quiz

8.

Which is false regarding this pointer?


(a) It points to the currently executing object.
(b) It stores address of one object at a time.
(c) It is created explicitly.
(d) It is genetic pointer.

9.

A constructor is called whenever


(a) an object is declared
(b) an object is used
(c) a class is used
(d) a class is declared

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

(d) derived class

(b) at run time


(d) at execution time

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

(d) depth first search

15. Overloading of unary operator by member function takes


(a) at least one argument
(b) only one argument
(c) no arguments
(d) two arguments
16. All the public members of a base class become protected member of the derived class. This happens in
__________
(a) protected inheritance
(b) public inheritance
(c) private inheritance
(d) virtual inheritance
17. Which of the following operation is not performed on a dictionary?
(a) Sorting
(b) Deleting
(c) Insert
(d) Search
18. The goal of hashing is to produce a search that takes
(a) O(1) time (b) O(log n) time
(c) O(n log n) time

(d) O(n2) time

19. In double hashing, secondary hash function is chosen such that


(a) does not effect clustering
(b) minimizes clustering
(c) maximizes clustering
(d) avoids clustering
20. Worst case performance of hashing technique is
(a) Worse than skip list.
(b) Better than skip list.
(c) Same as skip list.
(d) Cannot be determined.

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

Advanced Data Structures and Algorithms in C++

QUIZ-I
1.

Set-4

The basic run time entities in OOP are


(a) Functions (b) Classes (c) Data and codes

(d) Objects

2.

The member function can find out_______ of the object using this
(a) variables (b) class
(c) data types (d) address

3.

The following program


void abc( int &p)
{ cout << p;}
void main(void)
{
float m = 1.23;
abc(m);
cout << m;
}

(a) results in compile time error


(c) results in run time error
4.

A class template can declare


(a) constant data members
(c) global data members

(b) prints 1.23


(d) prints 1

(b) static data members


(d) private data members

5.

Global and static variables are stored in


(a) stack
(b) heap
(c) register (d) permanent storage area

6.

Overloading is otherwise called


(a) virtual polymorphism
(c) ad-hoc polymorphism

7.

8.
9.

Template supports
(a) generic programming
(c) procedural programming

(b) transient polymorphism


(d) pseudo polymorphism
(b) structured programming
(d) object-oriented programming

A block of statements which generate exceptions is


(a) rethrow
(b) try block
(c) catch

(d) throw

Protected base class visibility in public derivation is


(a) public
(b) private
(c) private protected

10. When an object is created to child class


(a) Destructor is called
(c) First base class constructor is called

(d) protected

(b) First child class constructor is called


(d) Both are called simultaneously

11. Which one of the asymptotic notation is most popular?


(a) big oh (b) theta (c) little oh
(d) omega
12. The compiler identifies a virtual function to be pure
(a) by its location in the program
(b) if it is equated to 0
(c) by the presence of the keyword pure
(d) if it is equated to null

Appendix D: Quiz

493

13. If f(n) = 10n2 + 4n + 2, then


(a) f(n) = O(10n2)
(b) f(n) = O(n2)
(c) f(n) = O(10n2 + 4n)
(d) f(n) = O(5n2 + 2n)
14. The environmental stack space is needed to store
(a) All constant variable values.
(b) Compiled version of the program instruction.
(c) Compiled version of the program instruction, all constant variable values.
(d) to resume the execution of the partially completed functions and methods.
15. The member function of every object name access to a pointer named______
(a) address
(b) null
(c) link
(d) this
16. C++ encourages structuring a software as a collection of components that are
(a) Highly cohesive and tightly coupled.
(b) not highly cohesive but tightly coupled.
(c) not highly cohesive and loosely coupled.
(d) highly cohesive and loosely coupled.
17. class A
{
public: static int c;
A()
{ c++; }
};

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

Advanced Data Structures and Algorithms in C++

QUIZ-I
1.

Set-5

The following C++ program fragment


#include <iostream.h>
int a = 15;
void main()
{ int a = 25;
{ int a = 75;
cout << a << ", " << ::a;
}
}

(a) prints 75, 15


(c) prints 15, 25
2.

(b) prints 75, 25


(d) results in run-time error

The following C++ code results in


#include iostream.h
void main(void)
{
cout (int a = 5) (int b = 6);
}

(a) runtime error

(b) compilation error

(c) no error

(d) link time error

3.

Which one of the following operators cannot be overloaded?


(a) >>
(b) ?:
(c) !=
(d) >=

4.

A reference is not the same as pointer, because


(a) a reference can be null.
(b) a reference once established cannot be changed.
(c) a reference needs an explicit differencing mechanism.
(d) they are one and the same.

5.

In C++ program, the fields in a class are by default _______.


(a) public
(b) protected
(c) private
(d) global

6.

A function foo() is defined as


void foo( int a = 25, int b = 100)
{ cout << a << b << endl;
}

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.

When should a function be implemented as a template function?


(a) When the data types of the parameters all have copy constructors.
(b) When the function depends on an underlying data type.
(c) When the function only takes one argument
(d) When the function is relatively short (usually just one line).

Appendix D: Quiz

9.

Virtual functions can not be


(a) static members
(b) derived

(c) overridden

10. Local variables are stored in _________ storage area


(a) stack
(b) registers
(c) heap

495

(d) public members

(d) permanent

11. Which of the following is useful in traversing a given graph by BFS?


(a) stack
(b) list
(c) queue
(d) set
12. Dictionary is a collection of pairs of the form where k is the key and v is the value.
(a) (k-1, v+1)
(b) (k, v)
(c) (v, k)
(d) (k+1, v+1)
13. f(k) is the ___________ for the pair where k is key.
(a) Index (b) Node
(c) Home bucket (d)

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

(d) skip lists

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

Advanced Data Structures and Algorithms in C++

QUIZ-II

Set-1

1.

A max-heap is a max tree that is also a _________.


(a) binary search tree
(b) indexed binary search tree
(c) binary
(d) complete binary tree

2.

What is the minimum number of elements in a heap of height h?


(a) h
(b) 2h
(c) 2h+1
(d) 2h+1-1

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.

What is the worst-case running time of heapsort?


(a) (n log n)
(b) (n)
(c) (n2)

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.

The time complexity of indexed search method is


(a) O(n log n)
(b) O(n)
(c) O(h)

(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.

The height of an AVL tree with n elements is


(a) log n
(b) n2
(c) n log n

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

(d) half of the pattern

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.

What is the maximum number of elements in a heap of height h?


(a) h
(b) 2h
(c) 2h+1
(d) 2h+1-1

2.

What is the height of n-element heap?


(a) log n
(b) n log n
(c) log n

3.

(d) log n

In a priority queue, the ______ priority entry is removed first.


(a) lowest
(b) highest
(c) either lowest or highest

(d) None of these

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.

In indexed binary search tree left side field contains __________.


(a) number of elements in left subtree +1 (b) number of left leaf node +1
(c) value of left leaf node
(d) number of elements in left sub tree

498
8.
9.

Advanced Data Structures and Algorithms in C++

All AVL Trees are basically


(a) empty trees (b) B-Trees (c) quad trees

(d) binary search trees

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.

A min-heap is a min tree that is also a _________.


(a) binary search tree
(b) indexed binary search tree
(c) binary
(d) complete binary tree

2.

Is an array that is in sorted order (ascending) a min-heap?


(a) Yes
(b) No
(c) Cannot say
(d) None of these

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.

Which data structure is more suitable for implementing a priority queue?


(a) list
(b) stack
(c) graph
(d) heap

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.

AVL tree was not developed by _______.


(a) Landis
(b) Anderson
(c) Velskii

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

Advanced Data Structures and Algorithms in C++

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.

What is the time complexity of insertion into a max-heap?


(a) O(log n)
(b) O(n log n)
(c) O(n2)
(d) O(n)

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.

An n element AVL tree with height h can be searched in


(a) O(n)
(b) O(log h)
(c) O(h log h)
(d) O(h)

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

10. In R0 imbalance of AVL tree the significance of R is


(a) Deleted element is in right subtree
(b) Deleted element is in left subtree
(c) No element is deleted
(d) Deleted element is root element
11. A Sequence of m operations on splay tree with initially n nodes takes time of the order of ______.
(a) O(n log n*m)
(b) O(n log n +m log n)
(c) O(n*m)
(d) O(n log n2)
12. In Red-Black trees pointers from internal node to an external node are _____.
(a) Black (b) Red
(c) Solid (d) Null
13. There are never two _______ links in a row.
(a) Red
(b) White (c) Orange
(d) Black
14. An m-way search tree of height h may have many as ________ nodes
(d) m+1
(a) m*h-1
(b) m
(c) mh-1
15. Deletion of element in a B-tree is divided into _____ cases.
(a) 3 (b) 1 (c) 2 (d) 4
16. In the Boyer-Moore algorithm if the pattern P is algorithm, then the shift value of character a is
(a) 8
(b) 1
(c) 9
(d) 0
17. In the Boyer-Moore algorithm if the character being compared is not present in the pattern then
_______ shift will be performed
(a) good suffix shift
(b) bad character shift
(c) non-matching shift
(d) matching shift
18. Time complexity of brute force string matching algorithm is
(a) (log n)
(b) (n log n)
(c) (n)
(d) (n2)
19. Each node in a trie structure will not contain
(a) pointer
(b) node number
(c) desired word

(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

Advanced Data Structures and Algorithms in C++

QUIZ-II

Set-5

1.

What is the time complexity of deletion from a max-heap?


(a) O(log n)
(b) O(n log n) (c) O(n2) (d) O(n)

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.

Heap sort (with n-element heap) takes ______ time.


(a) (log n)
(b) (n log n)
(c) (n2)

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.

The permissible balance factors of an AVL tree are


(a) 1, 0, -2
(b) 0, 1, 2
(c) -1, 0, 1

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

10. In RR rotation the node which is imbalanced is replaced with


(a) Root of right subtree
(b) left child of right subtree
(c) root of left sub tree
(d) right child of left subtree
11. In splay trees if the amortized costs are higher then the actual costs then potential is _____.
(a) same
(b) Decreasing (c) increasing (d) constant
12. In a red black-tree, (x) every external node is colored black (y) the children of red node of black
(a) (x) is false (y) is correct
(b) Both (x) and (y) are correct
(c) (x) is correct (y) is false
(d) Both (x) and (y) is false
13. In _______ trees each node may contain more than one key
(a) Binary tree (b) AVL tree
(c) Splay trees (d) B-Tree
14. In B-tree of order m all external nodes are _____.
(a) at different levels
(b) at same levels
(c) have 1 child node
(d) have two child nodes

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)

You might also like