Difference between revisions of "More With Arrays Review Questions and Exercises"
Line 1: | Line 1: | ||
− | {{Template:1010Topic|Chapter_TOC=[[More With Arrays]] > [[More With Arrays Review Questions and Exercises|Review Questions and Exercises]] | + | {{Template:1010Topic|Chapter_TOC=[[More With Arrays]] > [[More With Arrays Review Questions and Exercises|Review Questions and Exercises]] |
− | + | ||
|Body= | |Body= | ||
+ | |Introduction= | ||
+ | |Overview=}} | ||
+ | |||
==Review Questions== | ==Review Questions== | ||
===<div id="passing arrays using methods q">Passing Arrays using Methods=== | ===<div id="passing arrays using methods q">Passing Arrays using Methods=== |
Revision as of 21:40, 4 December 2011
COMP 1010 Home > More With Arrays > Review Questions and Exercises
Review Questions
Passing Arrays using Methods
- What do you have add to the method parameter if you are passing it an array instead of a single variable?
- How would you get the length of a Character Array?
- How would you get the length of a String?
- How would you get the length of a String Array?
Working with Partially Filled Arrays
- Why can is it useful to overwrite the default values when working with partially filled arrays?
- What purpose does using a counter serve when working with partially 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
Passing Arrays using Methods
Write a small method that accepts an array of characters, converts the characters into their ascii equivalent, then returns those values in an array of integers.
Working with Partially Filled Arrays
Write a block of code which attempts to insert a new string into a partially filled array of strings. The insert must determine whether or not the insert is feasible as soon as possible. You may assume that you have access to an int variable called 'counter' which contains the current number of filled indexes in the array. You may also assume that the empty index value for the string array is the null value.
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.)
Parallel Arrays
Write a program that uses a set of parallel arrays to store the name, age and addresses of 5 people you know (Just hard-code these). Have the program. Have the program do the following printouts separately: name and age, age and address and name and address.
- What do you have add to the method parameter if you are passing it an array instead of a single variable?
- How would you get the length of a Character Array?
- How would you get the length of a String?
- How would you get the length of a String Array?
Working with Partially Filled Arrays
- Why can is it useful to overwrite the default values when working with partially filled arrays?
- What purpose does using a counter serve when working with partially 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
Passing Arrays using Methods
Write a small method that accepts an array of characters, converts the characters into their ascii equivalent, then returns those values in an array of integers.
Working with Partially Filled Arrays
Write a block of code which attempts to insert a new string into a partially filled array of strings. The insert must determine whether or not the insert is feasible as soon as possible. You may assume that you have access to an int variable called 'counter' which contains the current number of filled indexes in the array. You may also assume that the empty index value for the string array is the null value.
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.)
Parallel Arrays
Write a program that uses a set of parallel arrays to store the name, age and addresses of 5 people you know (Just hard-code these). Have the program. Have the program do the following printouts separately: name and age, age and address and name and address.
Write a small method that accepts an array of characters, converts the characters into their ascii equivalent, then returns those values in an array of integers.
Working with Partially Filled Arrays
Write a block of code which attempts to insert a new string into a partially filled array of strings. The insert must determine whether or not the insert is feasible as soon as possible. You may assume that you have access to an int variable called 'counter' which contains the current number of filled indexes in the array. You may also assume that the empty index value for the string array is the null value.
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.)
Parallel Arrays
Write a program that uses a set of parallel arrays to store the name, age and addresses of 5 people you know (Just hard-code these). Have the program. Have the program do the following printouts separately: name and age, age and address and name and address.
Write a block of code which attempts to insert a new string into a partially filled array of strings. The insert must determine whether or not the insert is feasible as soon as possible. You may assume that you have access to an int variable called 'counter' which contains the current number of filled indexes in the array. You may also assume that the empty index value for the string array is the null value.
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.)