0% found this document useful (1 vote)
442 views

CSCI203 Spring 2010 Workshops Lab 7 (1) With Answers!

This document contains a lab session summary on algorithms and data structures. It discusses binary search trees and AVL trees, including questions about identifying AVL trees, constructing AVL trees from insertions, representing graphs as adjacency lists and matrices, depth-first search on graphs, sorting algorithms, solving recurrence relations using the master's theorem, and properties of AVL trees such as height, maximum number of nodes, and depth. Students are assigned problems involving these topics.

Uploaded by

technofreak9
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
442 views

CSCI203 Spring 2010 Workshops Lab 7 (1) With Answers!

This document contains a lab session summary on algorithms and data structures. It discusses binary search trees and AVL trees, including questions about identifying AVL trees, constructing AVL trees from insertions, representing graphs as adjacency lists and matrices, depth-first search on graphs, sorting algorithms, solving recurrence relations using the master's theorem, and properties of AVL trees such as height, maximum number of nodes, and depth. Students are assigned problems involving these topics.

Uploaded by

technofreak9
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like