Docsity

Binary Tree - Data Structures - Exam, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
-- --
CS 308 Data Structures
Fall 2000 - Dr. George Bebis
Final Exam
Duration: 12:00 - 2:00 pm
Name:
1. True/False (2 pts each) To get credit, you must (very briefly) for your answers !!
(1.1) TFThe maximum number of nodes in a tree that has L levels is 2^L
(1.2) TFA queue should be used when implementing Breadth First Search (BFS).
(1.3) TFThe largest value of a binary search tree is always stored at the root of the tree.
(1.4) TFA complete tree is also a full tree.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Binary Tree - Data Structures - Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

CS 308 Data Structures

Fall 2000 - Dr. George Bebis

Final Exam

Duration: 12:00 - 2:00 pm

Name:

  1. True/False (2 pts each) To get credit, you must (very briefly) for your answers !!

(1.1) T F The maximum number of nodes in a tree that has L levels is 2^L

(1.2) T F A queue should be used when implementing Breadth First Search (BFS).

(1.3) T F The largest value of a binary search tree is always stored at the root of the tree.

(1.4) T F A complete tree is also a full tree.

  • 2 -

(1.5) T F In a binary tree, every node has exactly two children.

(1.6) T F Tree operations typically run in O ( d ) time where d is the number of nodes in the tree.

(1.7) T F To delete a dynamically allocated tree, the best traversal method is postorder

(1.8) T F In a heap, the left child of a node is always less than the right child of a node.

(1.9) T F Implementing a priority queue using heaps is more efficient than using linked lists.

  • 4 -

(1.15) T F The order in which elements are inserted in a binary search tree in unimportant.

  1. Short answers (3 pts each)

(2.1) What is the number of nodes in a full tree with L levels? Prove it (show all the steps care- fully).

(2.2) What is the maximum number of levels (height) of a tree with N nodes? What is the mini- mum number of levels (height) of a tree with N nodes? Justify your answers.

(2.3) Assume A is an array-based tree with 70 nodes.

What is the index of the first leaf node?

Who is the parent of A[50]?

  • 5 -

Who are the children of A[10]?

How many leaf nodes does the tree have?

(2.4) We have discussed two different approaches to implement a priority queue. Which are these two approaches? How do they compare in terms of efficiency (time wise)? Justify your answer.

(2.5) Given the graph below, draw its adjacency matrix representation (store the vertices in alpha- betical order)

A

B

F

E

D

C

  • 7 -

(2.9) Show how the tree in (2.8) would look like after each of the following operations:

(i) delete 22

(ii) insert 34 (use the tree from step (i))

(2.10) Given the tree shown below, show the order in which nodes in the tree are processed by preorder traversal.

  • 8 -

(2.11) A priority queue is implemented as a heap. Show how the heap shown below would look like after each of the following operations:

37

20 10 2 19

41

66

11 18 6

(i) pq.Enqueue(38);

(ii) pq.Enqueue(102); (use the heap from step (i))

(2.12) Continue problem (2.11) (iii) pq.Dequeue(x); What is the value of x? (use the heap from step (ii))

(v) pq.Dequeue(y); What is the value of y? (use the heap from step (iii))

  • 10 -
  1. Code

(3.1) (10 pts) Write a function that returns the largest value in a binary search tree (full credit will be given only to the most efficient solutions).

  • 11 -

(3.2) (10 pts) Write a boolean member function IsBST that determines if a binary tree is a binary search tree.