In binary search, we split the list in half, perform one comparison to determine if our...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In binary search, we split the list in half, perform one comparison to determine if our target element is in the first or second half, and repeat on the appropriate half as necessary until only one element remains. Since there are at most log2 n halving operations, we use at most 1 log2n = log2n comparisons in the worst-case. Now consider ternary search instead. Here we would split the list into thirds, perform (at most) 2 comparisons to determine which third contains our target element, and repeat on the appropriate third as necessary until only one element remains. i. What is the worst-case number of comparisons performed by ternary search? Explain. ii. Which algorithm performs fewer comparisons in the worst-case, and by how much? Your answer should be in the form, "Algorithm A performs x-times fewer comparisons than Algo- rithm B," for appropriate values of A, B, and x. Hint: The following mathematical fact may come in handy; it allows one to change the base of a logarithm. log, n = log, n/loga. Let us now generalize to k-ary search, where we split the list into k equal size groups and perform (at most) k-1 comparisons to determine the appropriate group on which to repeat. iii. What is the worst-case number of comparisons performed by k-ary search? Explain. iv. What is the integer value of k which minimizes the number of comparisons in the worst-case? Explain. Hint: Ensure that your expression from part iii is in the form f(k) log2 n for some function f(k). To do this, make use of the fact that loga n = login/loga, as you did above. In binary search, we split the list in half, perform one comparison to determine if our target element is in the first or second half, and repeat on the appropriate half as necessary until only one element remains. Since there are at most log2 n halving operations, we use at most 1 log2n = log2n comparisons in the worst-case. Now consider ternary search instead. Here we would split the list into thirds, perform (at most) 2 comparisons to determine which third contains our target element, and repeat on the appropriate third as necessary until only one element remains. i. What is the worst-case number of comparisons performed by ternary search? Explain. ii. Which algorithm performs fewer comparisons in the worst-case, and by how much? Your answer should be in the form, "Algorithm A performs x-times fewer comparisons than Algo- rithm B," for appropriate values of A, B, and x. Hint: The following mathematical fact may come in handy; it allows one to change the base of a logarithm. log, n = log, n/loga. Let us now generalize to k-ary search, where we split the list into k equal size groups and perform (at most) k-1 comparisons to determine the appropriate group on which to repeat. iii. What is the worst-case number of comparisons performed by k-ary search? Explain. iv. What is the integer value of k which minimizes the number of comparisons in the worst-case? Explain. Hint: Ensure that your expression from part iii is in the form f(k) log2 n for some function f(k). To do this, make use of the fact that loga n = login/loga, as you did above.
Expert Answer:
Related Book For
Foundations of Financial Management
ISBN: 978-1259024979
10th Canadian edition
Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta
Posted Date:
Students also viewed these programming questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
How could a company's "green" policies affect their reputation management and community-building strategies, both positively and negatively?
-
Match the space curves in Figure 8 with their projections onto the xy-plane in Figure 9. B) FIGURE 8 dv 1) FIGURE 9
-
Describe the functions of the OECD.
-
Figure Q25.4 shows four different loops in a magnetic field. The numbers indicate the lengths of the sides and the strength of the field. Rank in order the magnetic fluxes \(\Phi_{1}\) through...
-
Andrea has prepared the following list of statements about corporations. 1. A corporation is an entity separate and distinct from its owners. 2. As a legal entity, a corporation has most of the...
-
What is this relationship between V out and V in for this circuit? ( Symbols have their usual meaning, with v denoting small signal values )?
-
For "n" write in terms of double factorials and 1/2 the following gamma functions T(2+n) . r (1/22 - 0 Identifies to prove ^ ( 1 +n) ^ ( = - n ) = (-1) ^ #T (b) Use these that
-
Investigate the role of banking in sustainable development, exploring advanced concepts such as green financing, social impact investing, and corporate social responsibility initiatives at the...
-
How do financial institutions leverage risk management strategies to ensure stability in banking operations at a master's level?
-
Assume the Capital Asset Pricing Model (CAPM) holds. The expected annual return of stock A is 6%. The annual risk-free rate was 5% and the expected annual return of the market was 7%. If the standard...
-
Sweety's Net Income and Dividends for 2021 and 2022 are shown below. 2021 2022 Net Income $660,000 $720,000 Dividends $350,000 $400,000 Sweety Inc's retained earnings on December 31, 2022 were...
-
The function lerp(t,a, b) can be used to linearly interpolate between two points in space. If we use the De Casteljau algorithm to evaluate 116 points on a cubic Bezier curve, how many times will the...
-
Describe Russias revolutions in March and November of 1917.
-
With your classmates, form small teams of skunkworks. Your task is to identify an innovation that you think would benefit your school, college, or university, and to outline an action plan for...
-
The opposite of a wind turbine is an electric fan: The electric energy that powers the fan is converted to the kinetic energy of moving air. A fan is putting 1.0 J of kinetic energy into the air...
-
A 60 kg runner in a sprint moves at 11 m/s. A 60 kg cheetah in a sprint moves at 33 m/s. By what factor does the kinetic energy of the cheetah exceed that of the human runner?
-
A fielder tosses a 0.15 kg baseball at 32 m/s at a 30 angle to the horizontal. What is the balls kinetic energy at the start of its motion? What is the kinetic energy at the highest point of its arc?
Study smarter with the SolutionInn App