Sie sind auf Seite 1von 9

College of Computer Science and Engineering

http://my.uowdubai.ac.ae

CSCI 203

Algorithms and Data Structures

Spring 2010
LAB Session #7

Week 8:

Last Name First Name Student ID Signature


Karachiwala Huzeifa 3544436

BINARY SEARCH TREES AND


AVL TREES

Dr. Abdellatif Tchantchane Jaspreet 1


Question 1.

Which of the following binary trees are AVL trees?

AVL Trees: a,g,d,f,h.

Dr. Abdellatif Tchantchane Jaspreet 2


Question 2

a. Construct an AVL tree by inserting their elements successively, starting


with the empty tree.
a. 1, 2, 3, 4, 5, 6

b. 6, 5, 4, 3, 2, 1

Dr. Abdellatif Tchantchane Jaspreet 3


c. 3, 6, 5, 1, 2, 4

d. Construct a binary search tree with 1, 2, 3, 4, 5, 6

Dr. Abdellatif Tchantchane Jaspreet 4


Question3

a. Write down the adjacency list for the above graph

1 -> 2 -> 4 -> 7


2 -> 3
3 -> 4
4 -> 1
5 -> 2
6 -> 5 -> 1
7-> 4 -> 6 -> 1

b. Write down the adjacency matrix

1 2 3 4 5 6 7
1 0 1 0 1 0 0 1
2 0 0 1 0 0 0 0
3 0 0 0 1 0 0 0
4 1 0 0 0 0 0 0
5 0 1 0 0 0 0 0
6 1 0 0 0 1 0 0
7 1 0 0 1 0 1 0

c. starting at vertex 1 List the vertices in order as they are visited by DFS
(use the adjacency list)

1 -> 2 -> 3 -> 4 -> Backtrack to 2 -> 5 - > Backtrack to 1 -> 7 -> 6

Dr. Abdellatif Tchantchane Jaspreet 5


Question 4 (Use Java Applet)

Construct an AVL tree by inserting their elements successively, starting with


the empty tree. 1 6 4 7 9 8 3 5 2
http://www.site.uottawa.ca/~stan/csi2514/applets/avl/BT.html

Dr. Abdellatif Tchantchane Jaspreet 6


Question 5 : Sorting by counting (search the internet)

Question 6 (need practice)


i =n −1
a. Compute the following sum ∑i(i +1)
i =0

i =n −1 i
b. Compute the following : ∑∑5
i =0 k =0

c. 22 + 21+…+2k

Dr. Abdellatif Tchantchane Jaspreet 7


Assignment
Question 7. Recurrence relations and Master Theorem (Assignment)
a. Using the Master Theorem find the order of growth for solutions of the
following recurrence equation(simplify):

T(n) = 3 T(n/2) + 1 for n > 1, T(1) = 1.

b. Solve the following recurrence equation

S(n) = 4.S(n − 1) + 7 for n > 1, S(1) = 8

n +1 i −1
c. ∑∑6i
i =1 k =0

Question 8 (assignment)

Dr. Abdellatif Tchantchane Jaspreet 8


AVL Trees : Show the results of inserting 2 1 4 5 9 3 6 7 9 12 14 15 into an
initially empty tree.

Question 9
a. Show that the maximum number of nodes in a binary tree of height h is
2h+1 − 1 (h = 0. A binary tree of height 0 has one node)

b. What is the depth of an AVL tree?

c. What is the depth of a binary search tree?

Dr. Abdellatif Tchantchane Jaspreet 9

Das könnte Ihnen auch gefallen