Difference between revisions of "More With Arrays Review Questions and Exercises"

From CompSciWiki
Jump to: navigation, search
(<div id="searching arrays e">Apply the Binary Search</div>)
Line 1: Line 1:
{{Template:1010Topic|Chapter_TOC=[[Selection Search Algorithm]]|Introduction=
+
{{Template:1010Topic|Chapter_TOC=[[More With Arrays]] > [[Review Questions and Exercises]]|Introduction=
 
|Overview=}}
 
|Overview=}}
  

Revision as of 14:37, 3 December 2007

COMP 1010 Home > More With Arrays > Review Questions and Exercises


{{{Body}}}

Review Questions

Passing Arrays using Methods

Working with Paritally Filled Arrays

Arrays of Strings

Searching Arrays

  1. Does the array have to be sorted to use a linear search?
  2. Does the array have to be sorted to use a binary search?
  3. Which algorithm is more efficient: linear search, or binary search?
  4. Referring to the "phone book" example, which search algorithm uses the "cut the phone book in half" method - linear or binary search?

Solutions

Sorting Arrays

Parallel Arrays

Exercises

Apply the Binary Search

Modify the binarySearch() algorithm to keep count of how many elements the algorithm checks to find the desired element. Print out each checked element's value (in other words, the value compared with the search value.)

Solution