Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider linear search again (see Exercise 2.1-3). How many elements of the input sequence need to be checked on the average, assuming that the element

Consider linear search again (see Exercise 2.1-3). How many elements of the input sequence need to be checked on the average, assuming that the element being searched for is equally likely to be any element in the array? How about in the worst case? What are the average-case and worst-case running times of linear search in notation? Justify your answers.

I understand that the average case is n/2 and that the worst case is n. I also know that the running times for both cases in notation is (n). However, I don't know how an answer of (n) is reached for both cases. Could someone provide a Cost Time Analysis next to each line of the pseudocode (shown below), show how T(n) is computed, and explain how (n) is found from T(n)?

This is the linear search pseudo code:

1 for i = 1 to A.length

2 if A[i] = v

3 return i

4 return nil

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago