Binary Search

Introduction

Create an interactive program to demonstrate a binary search.

Design

  1. The program will search positive integers
  2. The program will display the search results (found, not found)
  3. The program will start with 20 random numbers in sort order
  4. The program will loop until the user enters the "quit" command
  5. The program will display information explaining the commands
  6. The program will accept commands (strings) from the user
  7. Commands are case insensitive
  8. The first non-blank characters entered will be the command
  9. Blank commands (empty strings) are ignored
  10. Illegal commands will generate an error message
  11. The commands are
    • D - display the numbers
    • S - search the numbers for a specified value
    • G - generate a new set of random numbers in sort order
    • Q - quit the program
    • # - change the number of numbers to search (0 to 40)
            (a new set of random numbers will be generated in sort order)

Binary Search Algorithms

Wikipedia - Binary Search
Binary Search – Data Structure and Algorithm Tutorials
Search algorithms/Binary_search

Try This

Use positive and negative integers.
Use floating point numbers.
Search (case insensitive) strings rather than numbers.
Show each step of the search.