Module 6 Pseudocode and Reflection

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

260

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by UltraCamelMaster345

Report
Raphael Tolentino CS260 Prof. Lebel 4 Aug 2023 Pseudocode Task 1: Create tree structure Create struct Node create variable bid of type Bid Create Node default constructor create pointer for left direction initializing to null create pointer for right direction initializing to null Create constructor that takes aBid of type Bid as a parameter Initialize struct Bid to aBid Task 2: Insert method to tree If root is empty assign root to a new node if empty else call addNode function addNode function { if node is larger than bidId if left node is empty assign a new node to the left else add node to the left
else if right node is empty create new node to the right else add node to the right } Task 3: Remove Method create local variable called cur which points to tree’s root if there is no node to remove return node if key is found if node does not have any left or right children if node is not a parent then node is a root and initialize root to 0 to delete else if parent has left children and matches current node remove the node else remove the right node else if node has only a left child //remove with only left child if node is the root point root to current node’s left child else if the parent’s left child is the current node point the parent’s pointer to the current node’s left child else
point the parent’s right child to the current node’s left child else if node has only a right child //remove with only right child if node is the root point root current node’s right child else if the parent’s left child is the current node point the parent’s pointer to the current node’s right child else point the parent’s right child to the current node’s right child //remove node with two children else //find successor (leftmost child of right subtree ) create local variable node and assign to the current node’s right child while variable suc left child is not empty keep going down the left subtrees copy successor to current node call remove function, pass the location of current node’s right child based on key return //node found and removed Task 4: Search method Create local variable current pointing to the root node while current is not empty if key matches the key current is pointing to
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
return current since match is found if key input is less than the current node’s value/key search left else search right return 0 if not found Reflection The coding this week was more involved in terms of the algorithm. But, im- plementing the BST search, insert, and remove functions was easier for me since I was able to visualize it easier in my head and with all the examples. Additionally, there are not a lot of FIXMEs compared to the previous assignments. However, the most confusing part was the copying of the node in order to delete it. At first it looked like the copied node would not get deleted and would only move up a level, however, I went back and saw that both will get deleted. I thoroughly enjoyed learn- ing the BST data structure and its benefits. It seems that this is a fast and efficient data structure to hold a lot of data. Maybe faster than hash tables in certain areas and virtually no chance for collisions.