3. (30 points) Consider an ordered (sorted) array A of size n and the following ternary...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. (30 points) Consider an ordered (sorted) array A of size n and the following ternary search algorithm for finding the index į such that A[i] = K. Divide the array into three parts. If A[n/3] > K, the first third of the array is searched recursively, else if A[2n/3] > K then the middle part of the array is searched recursively, else the last third of the array is searched recursively. Provisions are also made in the algorithm to return n/3 if A[n/3] = K, or return 2n/3 if A[2n/3]=K. (a) Write the recurrence relation for the number of comparisons C(n) in the average case for the binary and ternary searches and solve the ternary average case only. (b) Do the following experiment (need to write a program in the language of your choice): (i) Generate arrays of sizes n = 500, 1000, 2000, 4000 and 8000. Fill the arrays as follows: A[i] = integer(8× √i); i=0,1,2, ..., n-1. 3. (30 points) Consider an ordered (sorted) array A of size n and the following ternary search algorithm for finding the index į such that A[i] = K. Divide the array into three parts. If A[n/3] > K, the first third of the array is searched recursively, else if A[2n/3] > K then the middle part of the array is searched recursively, else the last third of the array is searched recursively. Provisions are also made in the algorithm to return n/3 if A[n/3] = K, or return 2n/3 if A[2n/3]=K. (a) Write the recurrence relation for the number of comparisons C(n) in the average case for the binary and ternary searches and solve the ternary average case only. (b) Do the following experiment (need to write a program in the language of your choice): (i) Generate arrays of sizes n = 500, 1000, 2000, 4000 and 8000. Fill the arrays as follows: A[i] = integer(8× √i); i=0,1,2, ..., n-1.
Expert Answer:
Answer rating: 100% (QA)
a Recurrence relation for the number of comparisons Cn in the average case for binary and ternary searches Binary Search In binary search we divide th... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Date of purchase Units purchased Find the cost of goods sold if sales total $78,857 for the inventory table shown below. Cost per Total retail Total Retail price unit cost per unit value Beginning...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
In Problem, p is the price per unit in dollars and q is the number of units. If the weekly demand function is p = 30 - q and the supply function before taxation is p = 6 + 2q, what tax per item will...
-
McDonald's executives want to experiment with redesigning its restaurants so that the customers form one line leading to four registers to place orders, rather than four lines leading to four...
-
A young girl sits at the edge of a dock by the bay, dipping her feet in the water. At the instant shown in FIGURE 11-62, she holds her lower leg stationary with her quadriceps muscle at an angle of...
-
Simple numbers are used in this problem to highlight the concepts covered in the chapter. Assume that the Canberra Company produces one producta bath mat that sells for $10. Canberra uses a...
-
On January 1, Year 6, HD Ltd., a building supply company, JC Ltd., a construction company, and Mr. Saeid, a private investor, signed an agreement to carry out a joint operation under the following...
-
Question 2. HappySummer Ltd produces two types of air conditioners. The first type, named FastCold 100, is based on a more advanced technology than the second type, named Frozen99. The new technology...
-
Suppose the daily demand curve for flounder at Cape May is given by QD = 1,600 - 600P, where QD is demand in pounds per day and P is price per pound. a. If fishing boats land 1,000 pounds one day,...
-
Determine the tax liability, marginal tax rate, and average tax rate in each of the following cases. Use the Tax Tables and tax rate schedules to compute tax liability. Required: a. Single taxpayer,...
-
Since childhood, Louis Armstrong Carriker had been known simply as Bud, a nickname given to him by his paternal grandmother.1 Buds father, a New Orleans native, was a lifelong fan of the famous blues...
-
Damages, which are usually determined by the jury, come in four forms: Nominal damages Compensatory damages Hedonic damages Punitive damages
-
An assembly line must create one finished product every 2 minutes. The sum of the task times required to create a product is 200 seconds. What is the theoretical minimum number of workstations for...
-
Falsification of medical or business records is grounds for both criminal indictment and civil liability.
-
A certain facility has a design capacity of 2,500 units a day and an effective capacity of 2,225 units. Name one potential determinant of its effective capacity.
-
1, Can symptoms of seriously mentally ill and/or addiction be useful in a family? How? Give an example of how a child may develop symptoms to benefit a family. How would you work with that symptom?...
-
On January 2, 20X3, Sheldon Bass, a professional engineer, moved from Calgary to Edmonton to commence employment with Acco Ltd., a large public corporation. Because of his new employment contract,...
-
Suppose you are given a set S = {a 1 , a 2 , . . . ,a n } of tasks, where task a i requires p i units of processing time to complete, once it has started. You have one computer on which to run these...
-
Draw a table showing the order of every element in * 11 . Pick the smallest primitive root g and compute a table giving ind 11.g (x) for all x * 11 .
-
Show that if A is a nonsingular, symmetric, n n matrix, then A 1 is symmetric. Show that if B is an arbitrary m n matrix, then the m m matrix given by the product BAB T is symmetric.
-
How many months does it take to save $200,000.00 based on the information provided in this problem?---
-
What is the amount oi the credit to employee city income tax payable?
-
Milat is the total yearly gross pay for all employees?
Study smarter with the SolutionInn App