DOC PREVIEW
UI CS 270 - Binary Search

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Binary Search examplerestated from Mastering Algorithms with Perl, O'Reilly, 1999,http://oreilly.com/catalog/9781565923980.1Binary SearchIn our program, each word is represented in Perl as a scalar, which can be an integer, a foating-point number, or (as in this case) a string of characters.The list of words is stored in a Perl array: an ordered list of scalars.Perl Notation: Scalars begin with a $ sign, Arrays begin with an @ sign. Hashes begin with a % sign.Recall that hashes (aka associative arrays) “map” one set of scalars (the “keys”) to other scalars (the “values”).2Binary Search3Binary Search4nextThe next command is like the continue statement in C; it starts the next iteration of the loop:1. LINE: while (<STDIN>) {2. next LINE if /^#/; # discard comments3. #...4. }Binary Search56Binary SearchTry it out% perl bsearch.pl binary /usr/dict/words% perl bsearch.pl binary /usr/share/dict/words # OS Xbinary occurs at position


View Full Document

UI CS 270 - Binary Search

Download Binary Search
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Binary Search and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Binary Search 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?