Question

Discuss a situation in which you would use a recursive binary search. What is the stopping...

Discuss a situation in which you would use a recursive binary search. What is the stopping condition in the recursive binary search?

Please use own words not a google searched article.

Homework Answers

Answer #1

Consider a situation where A game is build which has a leaderboard. The leaderboard will have the scores in a sorted order since after completion of each game the scores will be given from highest to lowest(sorted in descending order). After the calculation of the scores based on the scores the rank will be given to each player, to search for the rank based on the score we have to use binary search because it will be the most efficient algorithm since the data is in sorted order, it will compute in O(logn) time complexity. To search in the leaderboard there will be slight modification since the data is sorted in descending order. i.e if the current score is less than the middle of the leaderboard then it will search in the right direction, if the current score is greater than the middle of the leaderboard then it will search for the left side of the leaderboard. The stopping rule is if the middle score of the leader board is equal to the current score the algorithm will return the index + 1 which is the rank of the particular user.
pesudocode will be like this

BinarySearch(left, right, leaderboard)
{
   middle = (left + right)/2;
   if(leaderboard[middle] == currentscore)
   {
       return index + 1;
   }
   elseif(leaderboard[middle] < currentscore)
   {
       return BinarySearch(left, middle, leaderboard);
   }
   elseif(leaderboard[middle] > currentscore)
   {
       return BinarySearch(middle + 1, right, leaderboard);
   }
}

If you have any doubts please comment and please don't dislike.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA: Design and implement a recursive version of a binary search.  Instead of using a loop to...
JAVA: Design and implement a recursive version of a binary search.  Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time.  If the value is not the target, refine the search space and call the method again.  The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are passed to...
Discuss synectics in your own words. Provide an example of a situation when you would use...
Discuss synectics in your own words. Provide an example of a situation when you would use synectics.
All necessary steps much show for these problems, please. The binary search algorithm is used with...
All necessary steps much show for these problems, please. The binary search algorithm is used with the following list; x has the value “flour.” Name the elements against which x is compared. Work shown should include which half of the list is searched after the midpoint is determined. butter, chocolate, eggs, flour, shortening, sugar How many different bit strings of length seven are there? A survey of 160 college students reveals that 85 own automobiles, 101 own bikes, 25 own...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
This assignment involves using a binary search tree (BST) to keep track of all words in...
This assignment involves using a binary search tree (BST) to keep track of all words in a text document. It produces a cross-reference, or a concordance. This is very much like assignment 4, except that you must use a different data structure. You may use some of the code you wrote for that assignment, such as input parsing, for this one. Remember that in a binary search tree, the value to the left of the root is less than the...
3. The search for identity involves four statuses. Discuss each of the four in light of...
3. The search for identity involves four statuses. Discuss each of the four in light of your experiences as you “searched” for and developed your own personal identity. 4. What impact does race/ethnicity have on the development of identity? 5. Discuss the relationship between identity development, self-esteem, and academic performance.
You are given a reference to the root node of a binary search tree, that implements...
You are given a reference to the root node of a binary search tree, that implements a dictionary data structure. Please print all the elements in depths 500 through 510, all in sorted order. A node in a binary search tree is at depth x, if it takes x hops to get from the root. So the root is at depth 0, the children of the root are at depth 1, and so on. The class TreeNode defines a single...
There are always interesting legal cases in the news. Use a search engine (Google, Bing, etc.)...
There are always interesting legal cases in the news. Use a search engine (Google, Bing, etc.) to search for “Tort Cases 2016”. Look through what you find and copy the link* of one of the articles that grab your attention. Post a summary of it, and include your reaction to it AND a copy of the link*, in case classmates might like to read the article in its entirety.
What is wrong with my recursive Binary Search code? For some reason my 'middle' value is...
What is wrong with my recursive Binary Search code? For some reason my 'middle' value is always zero? Please fix and explain! #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int BinarySearch(const int A[],const int L,const int R,const int key) {              if (R >= 1){           int middle = L + (R-1)/2;                              if (A[middle] == key)        return A[middle];               if (A[middle] > key){...
1. Search the Internet using a search engine (such as Google) for a recent article that...
1. Search the Internet using a search engine (such as Google) for a recent article that discusses a change in the price of something. For example, search "price increase," "price rise," "price drop," or "price decrease." (I recommend you avoid articles about the stock market.) Copy the URL address of the web site. You will need to post it. 2. Determine the cause of the price change by reading the article. Then try to identify which of the theoretical demand...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT