wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Final Quiz

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is

a)

(a) log2n

b)

(b) n-1

c)

(c) n

d)

(d) 2n

2.

In the balanced binary tree in the figure given below, how many nodes will become unbalanced when a node is inserted as a child of the node “g”?

a)

1

b)

3

c)

7

d)

8

3.

A binary search tree is generated by inserting in order the following integers:

50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24

The number of nodes in the left subtree and right subtree of the root respectively is

a)

(a) (4, 7)

b)

(b) (7, 4)

c)

(c) (8, 3)

d)

(d) (3, 8)

4.

Which of the following statements is false?

a)

A tree with n nodes has (n – 1) edges

b)

A labeled rooted binary tree can be uniquely constructed given its postorder and preorder traversal results.

c)

A complete binary tree with n internal nodes has (n + 1) leaves.

d)

The maximum number of nodes in a binary tree of height h is (2h+1-1)

5.

A complete n-ary tree is one in which every node has 0 or n sons. If x is the number of internal nodes of a complete n-ary tree, the number of leaves in it is given by

a)

(a) x(n – 1) +1

b)

(b) xn - 1

c)

(c) xn + 1

d)

(d) x(n+1)

6.

Consider the following nested representation of binary trees: (X Y Z) indicates Y and Z are the left and right sub stress, respectively, of node X. Note that Y and Z may be NULL, or further nested. Which of the following represents a valid binary tree?

a)

(a) (1 2 (4 5 6 7))

b)

(b) (1 ((2 3 4) 5 6) 7)

c)

(c) (1 (2 3 4)(5 6 7))

d)

(d) (1 (2 3 NULL) (4 5))

7.

The most appropriate matching for the following pairs

X: depth first search 1: heap

Y: breadth-first search 2: queue

Z: sorting 3: stack

is:

a)

(a) X—1 Y—2 Z-3

b)

(b) X—3 Y—1 Z-2

c)

(c) X—3 Y—2 Z-1

d)

(d) X—2 Y—3 Z-1

8.

Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder and preorder traversal. Respectively, of a complete binary tree. Which of the following is always true?

a)

(a) LASTIN = LASTPOST

b)

(b) LASTIN = LASTPRE

c)

(c) Both are True

d)

(d) None of the above

9.

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?

a)

a) 7 5 1 0 3 2 4 6 8 9

b)

b) 0 2 4 3 1 6 5 9 8 7

c)

c) 0 1 2 3 4 5 6 7 8 9

d)

d) 9 8 6 4 2 3 0 1 5 7

10.

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:

a)

(a) 2h -1

b)

(b) 2h-1 – 1

c)

(c) 2h+1 -1

d)

(d) 2h+1

11.

The maximum number of binary trees that can be formed with three unlabeled nodes is:

a)

1

b)

4

c)

3

d)

5

12.

The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively. The postorder traversal of the binary tree is:

a)

(A) d e b f g c a

b)

(B) e d b g f c a

c)

(C) e d b f g c a

d)

(D) d e f g b c a

13.

Postorder traversal of a given binary search tree, T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29

Which one of the following sequences of keys can be the result of an in-order traversal of the tree T?

a)

(a) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95

b)

(b) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29

c)

(c) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95

d)

(d) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

14.

Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely?

i) Preorder and Postorder

ii) Inorder and Postorder

iii) Preorder and Inorder

iv) Level order and Postorder

a)

(a) (i) only

b)

(b) (ii), (iii) only

c)

(c) (iii) only

d)

(d) (iv) only

15.

Which one of the following is a key factor for preferring B-trees to binary search trees for indexing database relations?

a)

(a) Database relations have a large number of records

b)

(b) Database relations are sorted on the primary key

c)

(c) B-trees require less memory than binary search trees

d)

(d) Data transfer form disks is in blocks.

16.

What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree with a single node is 0.

a)

(a) 2

b)

(b) 3

c)

(c) 4

d)

(d) 5

17.

The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudocode below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root.


The appropriate expression for the two boxes B1 and B2 are

a)

(a) B1 : (1 + height(n->right)), B2 : (1 + max(h1,h2))

b)

(b) B1 : (height(n->right)), B2 : (1 + max(h1,h2))

c)

(c) B1 : height(n->right), B2 : max(h1,h2)

d)

(d) B1 : (1 + height(n->right)), B2 : max(h1,h2)

18.

Dijkstra’s single source shortest path algorithm when run from vertex a in the below graph, computes the correct shortest path distance to

a)

(A) only vertex a

b)

(B) only vertices a, e, f, g, h

c)

(C) only vertices a, b, c, d

d)

(D) all the vertices

19.

A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property.

Which one of the following is a valid sequence of elements in an array representing 3-ary max heap?

a)

(a) 1, 3, 5, 6, 8, 9

b)

(b) 9, 6, 3, 1, 8, 5

c)

(c) 9, 3, 6, 8, 5, 1

d)

(d) 9, 5, 6, 8, 3, 1

20.

A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is given below:

10, 8, 5, 3, 2

Two new elements '1' and '7' are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements is:

a)

a) 10, 8, 7, 5, 3, 2, 1

b)

(b) 10, 8, 7, 2, 3, 1, 5

c)

(c) 10, 8, 7, 1, 2, 3, 5

d)

(d) 10, 8, 7, 3, 2, 1, 5