answersLogoWhite

0

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

13y ago

What else can I help you with?

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 time complexity of an algorithm that uses a binary search to find an element in a sorted array in logn time?

The time complexity of an algorithm that uses binary search to find an element in a sorted array in logn time is O(log n).


How many comparisons are typically required in a binary search algorithm to find a specific element in a sorted array?

In a binary search algorithm, typically log(n) comparisons are required to find a specific element in a sorted array, where n is the number of elements in the array.


What is the maximum number of comparisons required in a binary search algorithm to find a specific element in a sorted array?

The maximum number of comparisons required in a binary search algorithm to find a specific element in a sorted array is log(n), where n is the number of elements in the array.


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.