profbbrown / search

Classroom demonstration of linear and binary search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search Demonstration

Use this to demonstrate linear and binary search. Invoke this two ways:

You'll see seven rectangles and a target number. Click on one of the rectangles to reveal a number. The goal is to find the target number. Keep revealing numbers until the target is found.

This is intended to be an interactive, guided demonstration. Have a student come up to the front to work the controls. Use the linear search first. Challenge him or her to find the target number. Of course they will either have to click randomly or start from the left (or right).

Then you can demonstrate binary search, in which the numbers are sorted from least to greatest. Have the student try to find the target knowing they are sorted.

Some questions to ask the class:

  • What is the fewest numbers you'd have to look at?
  • What is the maximum number of guesses?
  • What is the average number of guesses?
  • Can you generalize these into functions of n?

The app will not announce when the target is found. The teacher and class will provide the fanfare.

Works well projected on a screen.

I use this on an iPad, too. Load the URLs into Safari, then create a home screen bookmark for it. When launched from its home screen icon, it will run in fullscreen mode, with no address bar or navigation buttons.

P.S. It's not possible to find the target on the first guess. It's rigged. This is to avoid this CS50 demonstration that didn't go as planned.

About

Classroom demonstration of linear and binary search


Languages

Language:JavaScript 80.1%Language:CSS 11.5%Language:HTML 8.4%