Binary search algorithm

Assignment Help Data Structure & Algorithms
Reference no: EM13158721

1. Write a program to find the number of comparisons using the binary search and sequential search algorithms as follows:

Suppose list is an array of 1,000 elements.

a. Use a random number generator to fill list.

b. Use any sorting algorithm to sort list. Alternatively, you can use the function insert0rd to initially insert all the elements in the list.

c. Search the list for some items, as follows:
     i. Use the binary search algorithm to seach the list. (You might need to modify the algorithm given in this chapter to count the number of comparisons.)
     ii. Use the binary search algorithm to search the list, switching to a sequential search when the size of the search list reduces to less than 15. (Use the sequential search algorithm for a sorted list).

d. Print the number of comparisons for Steps c.i and c.ii. If the item is found in the list, then print its position.

Reference no: EM13158721

Questions Cloud

What is the new pressure of the gas : At constant volume the temperature of 2.0atm was 325K. The temperature is increased to 400K. What is the new pressure of the gas?
What about whale fins compared to fish fins : Are the limbs modified into wings of bats and the wings of birds examples of evolutionary analogy or homology? What about whale fins compared to fish fins?
Mature age a protected class : There is much debate today concerning the possibility of adding the aged as a sixth protected class. What arguments pro and con exist for making advanced or mature age a protected class?
Do you think this pattern of trade is consistent : Do you think this pattern of trade is consistent with the principle of comparative advantage?
Binary search algorithm : Use the binary search algorithm to seach the list. (You might need to modify the algorithm given in this chapter to count the number of comparisons.)
Calculate the equilibrium concentrations of ch3cl : In a basic aqueous solution, chloromethane undergoes a substitution reaction in which Cl- is replaced by OH-: CH3Cl(aq)+OH-(aq) CH3OH(aq) + Cl-(aq)
Share to common stockholders : Orchard Corporation's common stock was selling at $52 per share at the end of its fiscal year. All dividends for the year had been paid, including $4.80 per share to common stockholders.
What are the main orders of placental mammals : What are the main orders of placental mammals? What are some representative species and distinguishing features of each of those orders?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Explaining effective customer relationships and loyalty

Paws'n Tails is an online pet shop that wants to influence what customers buy and builkd effective customer relationships and loyalty.

  Determine complete list of nodes which ancestor

Let the following tree: tree a. Determine the children of Q? b. What is the complete list of nodes which have D as ancestor? c. Determine the height of this tree (as height is defined in text)?

  Write a script that checks the day of the week

Write a script that checks the day of the week, and takes one of two actions depending on the day. If the day is Monday through Friday, print the name of the day.

  Write algorithm to find schedule obtains maximum amount

Write down algorithm to find schedule which obtains maximum amount of profit, assuming that all processing times are integers between 1 and n. Determine running time of your algorithm.

  Design a linked list structure

Design a linked list structure Music that contains data fields Name, Artist, Number_of_Songs, and a pointer to the list. Design the structure with three members and fill in data for each member.

  Explain types of information systems

Question 1. Explain five types of information systems, and give an example of each. Question 2. Describe three common reasons for a systems request. Try and find one not listed in the text.

  Create algorithm to calculte and print average earnings

Create the algorithm to calculte and print average earnings, lowest earnings, and highest earnings of group of employees. Each input record will contain name and earnings of one employee.

  Creating financial tracking program

Acme Inc. is making next generation financial tracking program, and Alice has been provided the task of writing encryption component.

  Creating an array

Determine which of the following commands is used to create an array?

  Java program to make choice for a coffee cup size

Create an application that prompts the user to make a choice for a Coffee cup size, S for Small, T for Tall, G for Grande and V for Venti the rates of cup sizes will be stored in a parallel double array as $2, $2.50, $3.25, and $4.50 respectively.

  Insertion sort and merged using standard merging mechanism

Using "insertion sort" and then merged using standard merging mechanism, where k is value to be determined. How must be we select k in practice?

  Program development cycle for algorithm using pseudocode

Illustrate all your work. Use modular approach to solving this problem. Give the following submodule. Calculations - module to compute gross pay. Using the Program Development Cycle, develop an algorithm using pseudocode for the following task.

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