Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
Question
Book Icon
Chapter 9, Problem 7PE
Program Plan Intro

Search Benchmarks

Program Plan:

  • Include the required header files.
  • Declare the necessary function prototype and constants.
  • Define the main () function.
    • Declare the necessary variables.
    • Declare and define the array values.
    • Get the number that is to be searched from the user.
    • Call the function “searchlinear()” to perform linear search and count the number of comparisons made during  the search.
    • Display the number of comparison made by the linear search.
    • Call the function “searchbinary()” to perform binary search and count the number of comparisons made during  the search.
    • Display the number of comparison made by the binary search.
  • Define the “searchlinear()” method,
    • Declare the necessary variables
    • Use a loop that iterates for the elements that is present in the array.
    • A counter variable that gets incremented is used inside the loop to count the number of comparison made to find the target element.
    • A condition statement is used to compare the values of the array and the search element.
    • Return the count of the comparisons made.
  • Define the “searchbinary()” method,
    • Declare the necessary variables.
    • A loop that iterates to search the elements those are present in the array.
    • A counter variable that gets incremented to count the number of comparison that is being made.
    • A condition statement that validates the position of the search element in the array.
    • Based on the position of the array the search is performed with the count of the comparison that is made.
    • Return the count of the comparison made.

Blurred answer
Students have asked these similar questions
Search Benchmarks Design an application in pseudocode that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values. The module should keep a count of the number of comparisons it makes until it finds the value. Then the program should call another module that uses the binary search algorithm to locate the same value. It should also keep a count of the number of comparisons it makes. Display these values on the screen.
Design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values. The module should keep a count of the number of comparisons it makes until it finds the value. Then the program should call another module that uses the binary search algorithm to locate the same value. It should also keep a count of the number of comparisons it makes. Display these values on the screen.
Array Manipulation In this question you develop a code capable of doing array manipulation. Your program will have the following menu. This code should be completely modular so that for each of the menu options (except for probably a couple of them) a function should be called. 1- Enter the size of the array 2- Enter the array elements 3- Sort the array 4- Find a number within the array 5- Print the array 6- Reverse print the array 7- Quit A sample run of the program is as follows: 1- Enter the size of the array 2- Enter the array elements 3- Sort the array 4- Find a number within the array 5- Print the array 6- Reverse print the array 7- Quit Please enter your choice: 0 That’s not a valid choice Please enter your choice: 2 You should first set the size of the array 1- Enter the size of the array 2- Enter the array elements 3- Sort the array 4- Find a number within the array 5- Print the array 6- Reverse print the array 7- Quit Please enter your choice: 3 Your array is not…
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,