The golden ratio search is a divide-and-conquer technique for searching a key in
ID: 3603815 • Letter: T
Question
The golden ratio search is a divide-and-conquer technique for searching a key in a sorted array a. It works similar to the famous
binary search but it narrows down possible locations with the aid of the golden ratio, i.e. instead of comparing with the middle
element, Golden ratio search examines the element at index = 0.618*n, where n is the number of elements in the sorted array. For example, if you have an array that has 1000 elements, the algorithm will compare the key with the 618 th element instead of the 500 th element as you would do if you use binary search. If the key is less than a[index], the search continues with the first part of the array using the same strategy, if the key is bigger than a[index], the search continues with the second part of the array using same strategy, if the key = a[index], it stops and return the index. The process also stops when the array is empty, indicating the key is not in the array.
a) Let T(n) be the worse-case time complexity of Golden ratio search. Give a recurrence for the worst-case running time.
b) Solve the recurrence.
c) Comparing with the regular binary search, give one possible advantage of binary search and one possible advantage of this
algorithm?
Explanation / Answer
import java.util.Random;
/**
* Draws random squares
*/
public class RandomSquares
{
public static void main(String[] args)
{
final int MAX_X = 200;
final int MAX_Y = 300;
Random gen = new Random(987456789);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.