Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
4th Edition
ISBN: 9780133985078
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
Ideal MOSFET Current–Voltage Characteristics—NMOS Device and draw the circuit
1. Create a Person.java file. Implement the public Person and Student classes in Person.java, including all the variables and methods in the UMLS. Person -name: String -street: String -city: String +Person(String name, String, street, String, city) +getName(): String +setName(String name): void +getStreet(): String +setStreet(String street): void +getCity(): String +setCity(String City): void +toString(): String Student -Id: int +Person(String name, String, street, String, city, int Id) +getId(): int +setId(int Id): void +toString(): String 2. Create a StudentTest.java file. Implement a public StudentTest class with a main method. In the main method, create one student object and print the object using System.out.println(). Your printing result must follow the example output: name: Mike, street: Morris Ave, city: Union, Id: 1000 Hint: You need to modify the toString methods in the Student class and Person class!
1) Apply the Paint Blue algorithm discussed in class to the following Finite Automata. a a a b b a COIS-3050H-R-W01-2025WI-COMB Formal Languages & Automata a b Show the status of the Finite Automata at the conclusion of the Paint Blue Algorithm (mark the visited states with an X and only include edges that have not been followed). 2) Use the pumping lemma to prove the following language is nonregular: L= {ab} = {abbb, aabbbbbb, aaabbbbbbbbb, ...}
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning