BST Reflection

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

350

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

2

Uploaded by SargentSnake1088

Report
Caio Mauro 11/26/23 CS300 Reflection: The assignment this week was to complete a code for the binary search tree. The goal was to have the ability to add, read and remove nodes in the tree. Binary search trees are special because they put values that are greater than the root to the right and values that are less than the root to the left. This is true throughout the entire tree. This is good because searching for a value within a binary search tree is very fast. You cut your runtime in half because from the start you can discard half of the tree. These trees can be very versatile and in large data sets they can process data quickly. Pseudocode: Define a class named BinarySearchTree Initialize the class with methods for Insert, Print, Remove, and Search Create a root variable pointing to null Implement the Insert method: If the root is null, set the new item as the root Otherwise, If the item is less than the root, If the left is null, add the item Else, If the item is less than the leaf, add it to the left If the item is greater than the leaf, add it to the right Else if the item is greater than the root, If the right is null, add the item Else, If the item is less than the leaf, add it to the left If the item is greater than the leaf, add it to the right Implement the Print method: If the root is not null, Traverse to the left and output if found Traverse to the right and output if found Implement the Remove method: If the root is empty, return Else, Traverse to the left, delete the node if found, and set it to a null pointer Traverse to the right, delete the node if found, and set it to a null pointer
Implement the Search method: If the root is not null, Traverse to the left and return if found Traverse to the right and return if found
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help