SCHOOL OF MATHEMATICS, STATISTICS &
COMPUTER SCIENCE
UNIVERSITY OF KWAZULU NATAL
WESTIVILLE CAMPUS
Practical V
COURSE CODE: COMP201 Data Structures
Examiner: Mr E. Jembere
Duration: open
Marks: 40 marks
Instructions
1. Attempt all questions.
2. Your solutions will be marked/assessed during the practical session on Tuesday, 5 September
2017. Please note that no marking will be done before or after the practical session.
3. Assessment will be done NOT only on your code, but also on your ability to explain your code.
Inability to explain your code will cost you all your marks for that question.
4. You are advised to come for the practical session almost done with all questions on this paper.
5. The stars against the questions indicate the level of difficulty of a question. The level of difficulty
is rated easy (no star), moderate (*), hard (**), or challenging (***).
1. *(Add new methods in BST) Add the following new methods in BST.
/** Displays the nodes in a breadth-first traversal */
public void breadthFirstTraversal()
/** Returns the height of this binary tree, i.e., the
* number of the nodes in the longest path of the root to a leaf */
public int height()
/** Returns true if the element is in the tree */
* Use recursion to search for an element*/
Public Boolean recursiveSearch(E e)
[5, 10, 5]
1|Page
2. *(Implement inorder traversal without using recursion) Implement the inorder method in
BST using a loop and stack instead of recursion.
[10]
3. *(Implement preorder traversal without using recursion) Implement the preorder method
in BST using a loop and a stack instead of recursion.
[10]
----------------------------------------------------------------------------------------------------------------
WISHING YOU ALL THE BEST
2|Page