Project 4: Self Organizing Binary Search Tree

Due: 11/10/2023

Educational Objectives: Understanding and developing a self organizing binary search tree data structure, practicing tree traversal algorithms, practicing recursive algorithms, and analyzing of algorithm complexity.

Statement of Work: Implement a class template for a generic self organizing binary search tree, which supports element insertion, deletion, search (and self-restructuring), and in-order and level-order traversals. Analyze the time complexity of one of the member functions.

Project Requirements:

In this project, you will develop a class template for a generic self organizing binary search tree. The self organizing binary search tree can restructure itself based on the search frequency of the data in the tree. In particular, a threshold value is maintained by the tree and a search count is maintained in each node of the tree. The search count in a node is increased by 1 each time the data in the node is searched. When the search count reaches the threshold, the corresponding node will move up in the tree by one level, which is achieved by a single rotation: rotate the position of the current node with its parent node. Let t denote the node whose search count reaches the threshold, and let p denote the parent node. Let us also assume that t is the left child of p. Then the rotation occurs as follows: 1) node t will occupy the position of p (that is, the parent of p will point to t instead of p); 2) the right child of node t becomes the left child of p; and 3) node p becomes the right child of node t. Note that this is the single rotation in AVL tree that we discussed in class. The following figure shows the single rotation (the node with data 40 reaches the search count). The case that t is the right child of the parent node p is analogous to the one we just discussed: 1) node t will occupy the position of p (that is, the parent of p will point to t instead of p); 2) the left child of node t becomes the right child of p; and 3) node p becomes the left child of node t.

After the single rotation, the search count of node t is re-set to 0. When a node is already at the root (top) of the tree, no rotation should be performed even if the search count reaches the threshold. For this case, you also need to re-set the search count to 0.

single-rotation BST

Name your self organizing binary search tree class template as "BST". Your BST must have a nested structure named "BSTNode" to contain the node related information (including, e.g., element, the search count, and pointers to children nodes). In addition, BST must at least support the following interfaces (in the following T is the abstract type of the elements stored in a node in BST).

The following public functions will call the corresponding private versions of the functions to perform certain tasks:

 

Other Requirements:

Provided Code

The tar file contains the following files:

  1. proj4_driver.cpp: the driver program to test your implementation of the self organizing binary search tree.
  2. proj4.x: executable code (compiled on linprog.cs.fsu.edu)
  3. proj4.input: sample input file. You can redirect the standard input of proj4.x to this file ('./proj4.x < proj4.input'), or you can just type line by line when the program asks for input.

Deliverable Requirements

Turn in the tar file containing all c++ header files, source files, makefile, and analysis.txt on Canvas.

Grading

Notes: