Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Searching the Dark Valley (15 points) A list of n distinct integers a1,a2,,an is called a valley list if the elements reading from left

image text in transcribed

2. Searching the Dark Valley (15 points) A list of n distinct integers a1,a2,,an is called a valley list if the elements reading from left to right first decrease and then increase. The location of the valley is the value i where ai is 1 . For example, the list 3,2,1,6,7 is a valley list with a valley at 3 since the number 1 occurs in the third position. We also consider a list of n increasing numbers to be a valley list with a valley at 1 , and a list of n decreasing numbers to be a valley list with a valley at n. (a) (2 points) Fill in the blank for the pseudocode for an algorithm based on linear search that takes as input a valley list a1,a2,,an and returns the location of the valley. procedure LinearValley (a1,a2,,an : valley list) 1. for i:=1 to n1 2. if 3. return i 4. return n (b) (3 points) What is a loop invariant of LinearValley that you could use to prove the correctness of LinearValley? (You do not have to prove.) (c) (2 points) Fill in the blank for the algorithm based on binary search that takes as input a valley list a1,a2,,an and returns the location of the valley. procedure BinaryValley (a1,a2,,an : valley list) 1. i:=1 2. j:=n 3. while (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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago