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
-
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...
-
Lowbirth weight babies are at increased risk of respiratory infections in the first few months of life and have low liver stores of vitamin A. In a randomized, double-blind experiment, 130 lowbirth...
-
Calculate the profitability index for Problem 3. For Problem 4.
-
I dont know you, and I very much liked working with Oscar Jones. Why was he transferred to Chicago? The customer you have just met for the first time is unhappy because of his relationship with the...
-
Jay Seago is suing the manufacturer of his car for $3.5 million because of a defect that he believes caused him to have an accident. The accident kept him out of work for a year. The company has...
-
dy 1. Find and simplify. dx tanx (a) y= (3 marks) (b) y x cosh (In x) (3 marks) (c) + sinh 2y = y - cosh 2x (4 marks)
-
Selected transactions for M. Acosta, an interior decorator, in her first month of business, are as follows. Jan. 2 Invested $10,000 cash in business. 3 Purchased used car for $3,000 cash for use in...
-
A company reports the following: Net income $292,010 $21,630 22,000 $35.64 Preferred dividends Shares of common stock outstanding Market price per share of common stock Calculate the company's...
-
The total of foreign exchange transactions can be 30 or 40 times the volume of exports and imports. Most foreign exchange transactions are conducted for trade. What is remittances. financial or...
-
How does the direction of intra-entity transfers (resulting in intra-entity gross profit in inventories) affect the computation of the noncontrolling interest's share of consolidated net income Both...
-
The client is employed in Amazon, India, and receives a competitive annual package that includes ESOPs that have increased in value. With a taste for success, your client is investing a large amount...
-
Scenario: Henri and Lila are about to close on their new home. You are a sales agent for the clients and have been asked by them to review the closing documents for accuracy. You find three errors on...
-
Cash Cows Which business unit represents a Cash cow in ITC's business portfolio?
-
1. Find any five of Zappos corporate values. Pick two of the values and explain how you think those values would influence the way employees do their work. 2. Using this list of corporate values and...
-
Suppose that you are part of a virtual team and must persuade other team members on an important matter (such as switching suppliers or altering the project deadline). Assuming that you cannot visit...
-
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.
-
OBB Personenverkehr (OBB), the Austrian state-owned railway, carries about 235 million passengers a year on routes within wholly owned by OBB Holding Group, which in turn, is wholly owned by the...
-
Jose Medellin participated in the rape and murder of two teenage girls in Houston, Texas. He was arrested and read his Miranda rights, and he confessed. At the time, he was not informed that he could...
-
The United States brought a lawsuit requesting forfeiture of a \($38.5\) million jet purchased by Teodoro Nguema Obiang Mangue (Nguema) because the government believed the jet had been purchased with...
Study smarter with the SolutionInn App