Difference between revisions of "More With Arrays Review Questions and Exercises"
From CompSciWiki
(→Apply the binary search) |
(→Searching Arrays) |
||
Line 7: | Line 7: | ||
===Arrays of Strings=== | ===Arrays of Strings=== | ||
===Searching Arrays=== | ===Searching Arrays=== | ||
+ | #Does the array have to be sorted to use a linear search? | ||
+ | #Does the array have to be sorted to use a binary search? | ||
+ | #Which algorithm is more efficient: linear search, or binary search? | ||
+ | #Referring to the "phone book" example, which search algorithm uses the "cut the phone book in half" method - linear or binary search? | ||
+ | |||
===Sorting Arrays=== | ===Sorting Arrays=== | ||
===Parallel Arrays=== | ===Parallel Arrays=== |
Revision as of 13:45, 30 November 2007
COMP 1010 Home > Selection Search Algorithm
{{{Body}}}
Review Questions
Passing Arrays using Methods
Working with Paritally Filled Arrays
Arrays of Strings
Searching Arrays
- Does the array have to be sorted to use a linear search?
- Does the array have to be sorted to use a binary search?
- Which algorithm is more efficient: linear search, or binary search?
- Referring to the "phone book" example, which search algorithm uses the "cut the phone book in half" method - linear or binary search?
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.)