Introduction to Java Programming and Data Structures  Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134700144
Author: Liang
Publisher: PEARSON
Question
Book Icon
Chapter 19, Problem 19.7PE
Program Plan Intro

Generic binary search

Program Plan:

  • Define the class named “Exercise19_07”.
    • Define the main method.
      • Declare and initialize an array “arr[]” in type of integer.
      • Call the generic method “binarySearch()” with array and key elements. Print the resultant positions on screen.
    • Define the generic method named “binarySearch()” which passes array list and key as arguments.
      • Declare and initialize the variables “low” and “high” in type of integer.
      • Using “while” loop, check the value of “high” greater than value of “low”.
        • Calculate the middle value using “low” and “high” value.
        • Using “if” condition, compare the key value with list values.
          • If the condition is true, calculate value of “high” using formula “mid-1”.
          • Otherwise, check the condition of to calculate the “key” value with list values.
            • Return value of “mid”.
      • Return appropriate position to calling function.

Blurred answer
Students have asked these similar questions
Design and draw a high-level "as-is" process diagram that illustrates a current process related to a product or service offered through the SSDCI.gov database.
Compare last-mile connections for connecting homes and businesses to the Internet
Explain wireless networking standards
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage