Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (30 points) Consider an ordered (sorted) array A of size n and the following ternary search algorithm for finding the index such that Ali-K.

image text in transcribed

3. (30 points) Consider an ordered (sorted) array A of size n and the following ternary search algorithm for finding the index such that Ali-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 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): () Generate arrays of sizes n -500, 1000, 2000, 4000 and 8000. Fill the arrays as follows: AlU- integer(8xvi) 012,..,. -1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago