Presentation on theme: "CS208 Coursework 2 Neil Ghani Mark Dukes Handin: Friday 11 March, 12pm, Departmental Office."— Presentation transcript:
CS208 Coursework 2 Neil Ghani Mark Dukes Handin: Friday 11 March, 12pm, Departmental Office
Question 1: Write an algorithm that takes a tree as input and returns the largest element stored in the tree Question 2: Write an algorithm that counts the number of pieces of data stored in a tree Trees
More Trees Question 3: Write an algorithm that takes as input a number n and a tree and prints out all data stored at depth n. So if t is the tree 6 / \ 5 7 / \ 9 12
Q3 Continued … then printAt 0 t = 6 printAt 1 t = 5, 7 printAt 2 t = 9, 12 Hint: Use recursion on the number as well as the tree. Look at cutAt in the lecture slides.
BSTs Q4: Give all the BSTs which store the numbers 1, 2, 3, 4, 5 Q5: Look at the tree given in Q3. What are the results of printing out the data stored in that tree using i) preorder traversal; ii) inorder traversal; and iii) post order traversal
Even More Trees Q6 Define an algorithm which takes two trees as input and returns the depth at which they first differ