Difference between revisions of "More With Arrays Review Questions and Exercises"
(→<div id="parallel arrays q">Parallel Arrays</div>) |
(→Exercises) |
||
Line 27: | Line 27: | ||
[[More With Arrays Solutions#searching arrays e sol|Solution]] | [[More With Arrays Solutions#searching arrays e sol|Solution]] | ||
+ | |||
+ | ===<div id="arrays of strings e">Work with an Array of Strings</div>=== | ||
+ | Create a program that uses an [[Arrays of Strings|array of Strings]] to print out the names of five major Canadian cities. For simplicity, the names of these cities may be hard-coded (eg. you don't need to get user input). Bonus points for using other structures in Java to make things even easier. (Just kidding.) | ||
+ | |||
+ | [[More with Arrays Solutions#arrays of strings e sol|Solution]] |
Revision as of 19:13, 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
- 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?
https://webmail.cs.umanitoba.ca/mediawiki/index.php?title=More_With_Arrays_Review_Questions_and_Exercises&action=edit§ion=1 Editing More With Arrays Review Questions and Exercises (section) - CompSciWiki Solutions
Sorting Arrays
Parallel Arrays
- How are parallel arrays tied together?
- When sorting a parallel array, should you use the same method as for a regular array?
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.)
Work with an Array of Strings
Create a program that uses an array of Strings to print out the names of five major Canadian cities. For simplicity, the names of these cities may be hard-coded (eg. you don't need to get user input). Bonus points for using other structures in Java to make things even easier. (Just kidding.)