Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need code in Java with short comment to understand and output. CompareSearch:Implement Interpolation Search algorithm from textbook (Algorithm 8.1) and the Binary Search algorithm from

Need code in Java with short comment to understand and output.

CompareSearch:Implement Interpolation Search algorithm from textbook (Algorithm 8.1) and the Binary Search algorithm from textbook (Algorithm 1.5). Try different problem instances against both algorithms to analyze best-case, average-case, and worstcase.

Compare the performances of both of the algorithms based on your results and how they compare to each other. I will attach both the algorithm. You can copy and modify the algorithm to answer this question.

It also need a report. The report should include different problem instances used and the analysis of performance of each algorithm and how compare against each other

ALGORITHM 1.5:

public static index binsearch(int n, keytype [] S, keytype x)

{

index location, low, high , mid ;

number denominator;

low = 1; high = n;

location = 0;

while (low <= high && location == 0) {

mid = {(low +high) /2];

if ( x == S [mid])

location = mid;

else if (x < S [mid] )

high = mid -1 ;

else

low = mid +1;

}

return location ;

}

ALGORITHM 8.1

Determine whether x is in the sorted array S of size n

Inputs positive integer n and sorted ( non decreasing order ) array of numbers S indexed from 1 to n

Outputs the location i of x in S; 0 if x is not in S

public static index interpsrch(int n, number [] S, number x)

{ index low, high, mid,i; number denominator;

low = 1; high = n; i = 0;

if (S[low] <= x <= S[high]) while (low <= high && i == 0) { denominator = S[high] - S[low]; if (denominator == 0) mid = low; else mid = low + [ ((x-S[low]) * (high - low)) / denominator] ; if (x == S [mid] ) i = mid; else if (x < S [mid]) high = mid -1; else low = mid +1; } return i ;

}

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

2. Does the topic meet the criteria specified in the assignment?

Answered: 1 week ago

Question

Demonstrate how to use the Gaps Model for diagnosing and

Answered: 1 week ago