Segment 25.17 gave an iterative algorithm for the method addEntry. Implement the

Chapter 25, Problem 12

(choose chapter or problem)

Segment 25.17 gave an iterative algorithm for the method addEntry. Implement the following alternate algorithm for this method: Algorithm addEntry(binarySearchTree, newEntry) result = null currentNode = root node of binarySearchTree parentNode = null while (newEntry is not found and currentNode is not null) { if (newEntry matches entry in currentNode) { result = entry in currentNode Replace entry in currentNode with newEntry } else if (newEntry < entry in currentNode) { parentNode = currentNode currentNode = the left child of currentNode } else // newEntry > entry in currentNode { parentNode = currentNode currentNode = the right child of currentNode } } if (newEntry is not found in the tree) { Create a new node and place newEntry into it if (newEntry < entry in parentNode) Make the new node the left child of parentNode else Make the new node the right child of parentNode } return result

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back