Assignment 2 COS 212: Department of Computer Science Submission Deadline: 8 May 2020 at 23:00
Assignment 2 COS 212: Department of Computer Science Submission Deadline: 8 May 2020 at 23:00
COS 212
Objectives:
General instructions:
Plagiarism:
The Department of Computer Science considers plagiarism as a serious offence. Disciplinary action will
be taken against students who commit plagiarism. Plagiarism includes copying someone else’s work
without consent, copying a friend’s work (even with consent) and copying material (such as text or
program code) from the Internet. Copying will not be tolerated in this course. For a formal definition of
plagiarism, the student is referred to http://www.library.up.ac.za/plagiarism/index.htm (from
the main page of the University of Pretoria site, follow the Library quick link, and then choose the
1
Plagiarism option under the Services menu). If you have any form of question regarding this, please
ask one of the lecturers, to avoid any misunderstanding. Also note that the OOP principle of code
re-use does not mean that you should copy and adapt code to suit your solution.
Upon successful completion of this assignment you will have implemented your own threaded AVL tree
in Java, which supports efficient inorder and postorder traversals.
Your Task
Download the archive assignment2Code.tar.gz and untar it in an appropriate directory. The archive
contains the following files:
• ThreadedAVLNode.java
• ThreadedAVLTree.java
• Tester.java
The use of a threaded binary search tree to perform an inorder traversal was covered during
lectures. For information on using a threaded binary search tree to perform a preorder traversal,
refer to the last paragraph on page 240 of the textbook. A threaded AVL tree node is simply
a threaded binary search tree node that additionally stores the balance factor that an AVL tree
requires.
• Class ThreadedAVLTree describes a threaded AVL tree (i.e. an AVL tree where every node is
a threaded node). AVL tree structure, as well as insertions and deletions for AVL trees, are
described in Section 6.7.2 of the textbook. A threaded AVL tree is an AVL tree built out of
threaded nodes. Crucially, the insertion and deletion operations must be augmented so that they
correctly update the threads for nodes involved in tree rotations, where necessary. It is your task
to determine when and how such threads need to be updated.
Implement all the methods specified in the provided classes. You are not allowed to modify provided
method signatures, class names, or data fields. You are allowed to add additional methods and/or
2
data fields as necessary. Be sure to carefully follow all instructions provided in comments within the
provided files.
Test your code very thoroughly. Test each method separately, and focus on edge cases (operations
performed on empty trees, trees containing only one node, each of the AVL tree insertion and deletion
cases, and so on). Make sure that all strings returned by the traversal methods conform to the
specified format (check carefully for any deviations in format, including additional spaces at the end
of the strings).
HINT: It is strongly advised that you start by focusing on the implementation of a standard AVL
tree first, while ignoring threads. Only once you have a working AVL tree, shift your focus to adding
support for threads and traversals. Before jumping to the code, understand the process visually by
drawing threaded AVL trees on paper, performing various rotations on them, and observing how the
existing threads must change. If you understand the process, you can write an algorithm in pseudocode
to express it. If you can write the pseudocode, you can translate it to Java.
Submission Instructions:
You must create your own makefile, and include it in your submission. Your makefile will be overwritten
during testing. The makefile used for testing will compile your code with the following command:
javac *.java
The makefile used for testing will also execute your program using the following command:
java Tester
Failure to include a makefile in your submission archive will result in your program failing to compile,
and will result in a mark of zero.
Once you are satisfied that everything is working, you must tar your Java code together with the
makefile, with no folders/subfolders. Your Java archive should be named sXXXass2.tar.gz, where
XXX is your student number. Test your code thoroughly, with multiple test cases, before submitting
it for marking. The submission deadline is 8 May 2020 at 23:00.
Good luck!