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

  Create and implement dynamic programming algorithm

Create and implement such dynamic programming algorithm and examine it. You are not sure if CEO must get invited to party, but you suspect that you might get fired if he is not.

  Program that sorts a linked list of integers

Write a program that sorts a linked list of integers using merge sort. The program will read the integers from a file onto a linked list and then sort the linked list using MERGE SORT.

  What is the difference between syntax and semantics

Explain the distinction between an ambiguity in a proposed algorithm and an ambiguity in the representation of an algorithm.

  Recognize how many playing cards you have

Create a flowchart that programs a robot to recognize how many playing cards you have and to put them in order from smallest to largest.

  One e business failure

Discuss about one e-Business failure. Describe what happened and what you would have done differently. Explain whether or not the e-Business practiced sound financial planning.

  Database design activities

Assume Ray wishes to start a DVD rental program at his stores that he plans to call Henry's DVD Club. He refers to each of his consumers as members.

  Create a work plan

Design a dynamic programming algorithm to find the value of the optimal plan. Implement your algorithm using any programming language you prefer. Describe the recurrence relation used by your algorithm at the top of your program or in a separate f..

  Currency conversion developmentapplication-level

currency conversion developmentapplication-level requirements list1. the program will prompt the user for data input of

  What are the characteristics of a binary tree

What are the characteristics of a binary tree? Define the left child of node n in a binary tree. What are the three properties of each node n in a binary search tree

  Algorithm for finding smallest element in unsorted array

Consider the following algorithm for finding the smallest element in an unsorted array: RANDOMMIN(A[1 .. n]). What is the exact expected number of executions of line ( )?

  Describe types of information systems

Describe five types of information systems, and give an example of each and describe 3 common reasons for a systems request. Try and find one not listed in the text.

  How the regular tree walk algorithm works

We know how the regular tree walk algorithm works. If you have some values in the tree then the tree walk algorithm prints everything in order

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