Skip to content

editor123/ProjectCTreesFiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BinarySearchTreeWithDups Implementation

Overview

This project implements a BinarySearchTreeWithDups class in Java, extending the standard BinarySearchTree to handle duplicate entries. The implementation includes methods for adding elements, counting occurrences, and efficiently counting elements greater than a specified value. The code is designed to be efficient, leveraging the sorted nature of the binary search tree.

Class Details

BinarySearchTreeWithDups<T extends Comparable<? super T>>

This class extends BinarySearchTree<T> and provides the following key functionalities:

  • add(T newEntry): Overrides the add method to insert elements, handling duplicates by placing them in the left subtree.
  • addEntryHelperNonRecursive(T newEntry) (private): A non-recursive helper method for adding entries, ensuring duplicate handling.
  • countIterative(T target): Counts the number of times a specific element appears in the tree (non-recursive).
  • countGreaterRecursive(T target): Counts the number of elements in the tree greater than the target value (recursive).
  • countGreaterIterative(T target): Counts the number of elements in the tree greater than the target value (non-recursive, using a stack).
  • countUniqueValues(): Counts the number of unique values in the tree (O(n) time complexity).

Files Included

  • BinaryNode.java: Defines the BinaryNode class for tree nodes.
  • BinaryTree.java: Provides the basic binary tree implementation.
  • BinarySearchTree.java: Implements the standard binary search tree.
  • BinarySearchTreeWithDups.java: The core class with duplicate handling and counting methods.
  • PoliceReport.java: Defines the PoliceReport class used in the driver program.
  • ProjectCPartADriver.java: Driver program for testing the BinarySearchTreeWithDups class.
  • ProjectCPartBDriver.java: Driver program for processing police report data and comparing tree performance.
  • README.md: This file, providing project documentation.
  • image_c5a152.jpg: An image (please describe its purpose if relevant).

Usage

  1. Compilation:

    • Compile the Java files using a Java Development Kit (JDK). For example:
      javac *.java
  2. Running the Driver Programs:

    • To test the BinarySearchTreeWithDups class:
      java ProjectCPartADriver
    • To process the police report data:
      java ProjectCPartBDriver
    • Note: Ensure the police report data file is in the correct location for ProjectCPartBDriver to run successfully.

Key Implementation Details

  • Duplicate Handling: The addEntryHelperNonRecursive method ensures that duplicate entries are inserted in the left subtree, maintaining the specified behavior.
  • Efficiency: The countGreaterIterative and countUniqueValues methods are implemented with efficiency in mind, using a stack for iterative traversal and a HashSet for unique value tracking, respectively.
  • Recursion vs. Iteration: The project demonstrates both recursive (countGreaterRecursive) and iterative (countIterative, countGreaterIterative) solutions to tree traversal and processing.

Git Instructions for Collaboration

  1. Clone the Repository:

    git clone https://github.com/editor123/ProjectCTreesFiles/tree/master
  2. Pull Latest Changes:

    git pull origin main
  3. Make Changes and Commit:

    git add <modified_files>
    git commit -m "Describe your changes"
  4. Push Changes:

    git push origin main

Author

  • Sangharsha, Rina, Victor

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages