Given algorithm looks for a value in a nondecreasing sequenc

Assignment Help Data Structure & Algorithms
Reference no: EM13943902

Given algorithm looks for a value in a nondecreasing sequence and returns the index of the value if it is found or 0 if it is not found.

Input: A sequence si, ...... ,sj (j >= i >= 1) sorted in nondecreasing order, a value key, i, and j
Output: The output is an index k for which sk = key, or if key is not in the sequence, the output is the value 0.

binary_search(s, i, j, key) {
if (i > j) // not found
return 0
k = (i + j)/2
if (key == sk) // found
return k
if (key < sk) // search left half
j = k - 1
else // search right half
i = k + 1
return binary_search(s, i, j, key)
}

Consider the sequence s1 = 'C', s2 = 'G', s3 = 'J', s4 = 'M', s5 = 'X'. Show how the algorithm executes in case key = 'C'.

Reference no: EM13943902

Questions Cloud

Logistics vendor for handfield manufacturing : Monczka-Trent Shipping is the logistics vendor for Handfield Manufacturing Co, in Ohio. Handfield has daily shipments of a power-steering pump from its Ohio plant to an auto assembly line in Alabama. The value of the standard shipment is $250,000...
Would your answer change if the inability : Would your answer change if the inability to meet private sector customer demand reduces sales of 50,000 during this (ignore any effects beyond this period)?
What are some of the critical differences : When you start a new project, what are the essential tasks you take care or start with?
Machine hours to apply to these products : Apply linear programming to this problem. A firm wants to determine how many units of each of two products (products X and Y) they should produce in order to make the most money. The profit from making a unit of product X is $190 and the profit fr..
Given algorithm looks for a value in a nondecreasing sequenc : Given algorithm looks for a value in a nondecreasing sequence and returns the index of the value if it is found or 0 if it is not found.
Trait theory of leadership : How many of you ascribe to the trait theory of leadership which implies that leaders are born--not made or shaped by mentors or by being a follower first
Difference in the mean selling price of homes : Refer to the real estate data in Blackboard. Determine whether there is a difference in the mean selling price of homes with an attached garage and homes without an attached garage.
Range of output theoretically possible : An assembly line with 17 tasks is to be balanced. The longest task is 2.3 minutes, and the total time for all tasks is 18 minutes. The line will operate for 460 minutes per day.
Total bond interest expense : the amount of the premium on these bonds at issuance total bond interest expense will be recognized over the life of these bonds

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement a stack adt by writing a class

Instantiate the Stack class in the main function and provide a user loop and a menu so that all the Stack class member-functions, push, pop, etc., are available so that the user can thoroughly exercise the member-functions of the Stack class.

  Determine if a string s is a palindrome

What data structure is most suitable to determine if a string s is a palindrome, that is, it is equal to its reverse.

  Determine the branching factor

Expalin the search algorithm that results from each of the following special cases. How does it relate to other algorithms we have discussed.

  Describe why a brute-force attack does not work

Explain exactly why an exhaustive key search will not succeed even though sufficient computational resources are available. This is a paradox since we know that the OTP is unconditionally secure.

  Explain two possible solution-fill in blank squares by words

The objective is to fill in blank squares using words from the list. Your task is to formulate problem as constraint satisfaction problem. Explain two possible solutions.

  Analyze the time-space complexity of algorithms

How a vEB tree can be used to support these three operations and analyze the time/space complexity of your algorithms.

  Discuss new security features in windows server

Which of the system changeover methods is the most expensive? Why? Which of the system changeover methods is the most risky? Why?

  Content of the queue at the beginning

Assume you are at the airport, waiting for the security check. There is one line (which is a FIFO queue), and 5 security check gates. Each person reaching in front of the queue is checked by the first available security gate.

  Decision tree to help someone

Create a decision tree to help someone determine what meal to buy at a fast food restaurant. The structure of your tree should be similar to the one on page 699.

  Design time randomized monte carlo algorithm

You have to design an O(n) time randomized Monte Carlo algorithm which computes an (1 + o)- approximate ham-sandwich cut with probability 1 - n-c for any given constant c > 0.

  Difference between workbook and worksheet

Discuss the difference between a workbook and a worksheet and explain why would you want to use individual worksheets when using Excel?

  Write a flowchart to solve any linear equation

Write a flowchart to solve any linear equation ax+b=0 -

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd