answersLogoWhite

0


Best Answer

Since a binary search tree is ordered to start with, to find the largest node simply traverse the tree from the root, choosing only the right node (assuming right is greater and left is less) until you reach a node with no right node. You will then be at the largest node.

for (node=root; node!= NULL&&node->right != NULL; node=node->right);

This loop will do this. There is no body because all the work is done in the control expressions.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the algorithm to find largest node in a binary search tree?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you search a particular element from the vector?

To search a particular element from the vector, use the find() algorithm. If the vector is sorted, you can use the binary_search() algorithm to improve efficiency. Both algorithms can be found in the <algorithm> header in the C++ standard library.


Which search algorithm is best?

The question is a bit too vague for a meaningful answer, it depends on what you are searching and what you are looking for.For search in an unsorted list, there is no better alternative than the naive algorithm of looking at every single element.For search in a sorted list (like a phone book sorted on name) binary search is much more efficient.For string search, like used in biology to find DNA matches, there are dedicated algorithms that deal exclusively with string matching.For graph search, A* ("A star") is among the better.For more general search problems there are a whole host of search methods that work better than others in particular domains. But so far, there is no ultimate winner that is best for everything. The best ones are generally custom made for one particular problem, like the best known algorithm for the Travelling Salesman Problem.See also related link.


What if the elements are repeated in binary search?

You will find one of them (not necessarily the first or the last).


Is it true In a binary search if the search fails to find the item on the first attempt then there are 999 elements left to search in an array of 1000 elements?

False. In a binary search, if the search fails on the first trial of an array of 1000 elements, then there are only nine more elements left to search.


What are the advantages and disadvantages of binary search algorithms?

the major limitation of binary search is that there is a need of sorted array to perform binary search operation. if array is not sorted the output is either not correct or may be after a long number of steps and according to data structure the output should come in minimum number of steps.

Related questions

What is the worst case and best case for binary search?

The best case for a binary search is finding the target item on the first look into the data structure, so O(1). The worst case for a binary search is searching for an item which is not in the data. In this case, each time the algorithm did not find the target, it would eliminate half the list to search through, so O(log n).


An algorithm to find whether a directed graph is connected or not?

You can use a The Depth-First Search algorithm.


How can i find an algorithm to determine the largest number?

1,000000000000,00000000000000,00000000,000000000000,00000000000,00000000000,00000,0000000000,000000,actually, there is no such thing as 'the largest number'.


How do you search a particular element from the vector?

To search a particular element from the vector, use the find() algorithm. If the vector is sorted, you can use the binary_search() algorithm to improve efficiency. Both algorithms can be found in the <algorithm> header in the C++ standard library.


Which search algorithm is best?

The question is a bit too vague for a meaningful answer, it depends on what you are searching and what you are looking for.For search in an unsorted list, there is no better alternative than the naive algorithm of looking at every single element.For search in a sorted list (like a phone book sorted on name) binary search is much more efficient.For string search, like used in biology to find DNA matches, there are dedicated algorithms that deal exclusively with string matching.For graph search, A* ("A star") is among the better.For more general search problems there are a whole host of search methods that work better than others in particular domains. But so far, there is no ultimate winner that is best for everything. The best ones are generally custom made for one particular problem, like the best known algorithm for the Travelling Salesman Problem.See also related link.


How do you find a largest algorithm in c plus plus?

#define max (a, b) ((a) >= (b)) ? (a) : (b)


What if the elements are repeated in binary search?

You will find one of them (not necessarily the first or the last).


Where might one find information about a binary search tree?

One can find information about a binary search tree from a few different places. One can find information at sites such as Wikipedia and You Tube or from taking computer classes that teach about data structures.


Is it true In a binary search if the search fails to find the item on the first attempt then there are 999 elements left to search in an array of 1000 elements?

False. In a binary search, if the search fails on the first trial of an array of 1000 elements, then there are only nine more elements left to search.


What are the advantages and disadvantages of binary search algorithms?

the major limitation of binary search is that there is a need of sorted array to perform binary search operation. if array is not sorted the output is either not correct or may be after a long number of steps and according to data structure the output should come in minimum number of steps.


What are the advantages of algorithm of binary search?

The primary advantage of a binary search algorithm is that searching a sequence can be achieved in logarithmic time. The primary disadvantages are that the data must be in sorted order. Arrays are the ideal container for binary searches as they provide constant-time random-access and are therefore trivial to both sort and search efficiently. Sorted binary trees can also be used, however for optimal performance they must be totally balanced (e.g., red/black binary tree). Constant-time random-access is not a requirement of binary trees, however the cost of maintaining balance during construction of the tree has to be taken into account. With a linear search, we start at one end of the sequence and traverse through the sequence one element at a time until we find the value we're looking for, or we reach the element one-past-the-end of the sequence (in which case the element we're looking for does not exist). For a sequence of n elements, the worst case is O(n). Linear search is ideal for forward lists (singly-linked lists) and lists (doubly-linked lists) as neither provides nor requires constant-time random-access. With binary search, we locate the middle element in the sequence. If that's not the value we are looking for, we can easily determine which half of the sequence contains our value because the elements are in sorted order. So we eliminate the other half and repeat the algorithm with the remaining half. As such, each failure to find the value reduces the number of elements to be searched by half (plus the middle element). If there are no elements in the remaining half then the value does not exist. The worst case is therefore O(log n).


How to find height of subtree in a Binary tree?

Check this out! http://stackoverflow.com/questions/575772/the-best-way-to-calculate-the-height-in-a-binary-search-tree-balancing-an-avl