Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Discrete Math Problems: 1.From the below algorithm (linear search) construct the function f(n) which computes the number of steps the algorithm executes for a list

Discrete Math Problems:

1.From the below algorithm (linear search) construct the function f(n) which computes the number of steps the algorithm executes for a list of n integers and compute O(f) using the definition

ALGORITHM 2 The Linear Search Algorithm.

procedure linear search(x: integer, a1, a2,..., an: distinct integers)

i := 1

while (i n and x ai)

i := i + 1

if i n then location := i

else location := 0

return location{location is the subscript of the term that equals x, or is 0 if x is not found}

2.For the algorithm below, can you construct f(n) which gives the number of steps performed with input n if so, construct f(n); otherwise state why not.

// input to algorithm is n, an integer

j := n;

while( j>= 1 )

{

for i := 1 to j

{

x := x + 1;

}

j := floor ( j/2 );

}

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Which of the key word is used to create an instance of a class?

Answered: 1 week ago

Question

How many bytes a char data type occupies?

Answered: 1 week ago