Download Exposure C++

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Linked list wikipedia , lookup

Array data structure wikipedia , lookup

Transcript
Exposure Java Ch 12, Ch 18
Name:
Review
Date:
Period:
Short Answer
1. What is the first data structure definition?
2. What is the data structure starting point?
3. What is an array?
4. What is the “off by one” error?
5. Describe the LinearSearch? What is a synonym for linear?
6. Describe what the purpose of the outside loop on a Selection Sort? The inside loop? How does the swap
method work?
7. Write an array declaration, scores, for 100 integers.
8. Write an array declaration, list, for 100 characters.
9. Write an array declaration, word, for 25 strings.
10. Write an array declaration, gpas, which stores {2.785,3.250,3.999,2.225,1.285,2.000}
11. Write an array declaration, numerals, which stores {'0','1','2','3','4','5','6','7','8','9'}
12. Write an array declaration, students, which stores {"Tom","Jane","Mark","Rachel"}
13.
What are the 2 processes involved in array deletion?
14.
Look at Figure 18.15. The 90 is found at index [5]. What is done to all of the elements after index [5]
that essentially removes the 90 from the array?
15. Look again at Figure 18.15. Is there still a value in at index [9], and if so what is it?
16.
Refer to the previous question. What will happen to this value when a new element is added to the list?
17.
What is the difference between a search used for finding the first occurrence of an element and all
occurrences of an element from an array?
18.
What error will you get if you try to insert an item into an array that is full?
19.
Look at program Java1812.java and refer to the previous question.
What new field is added to the List class to deal with this problem?
20.
If finding the correct page in a 2000 page phone book can be done in 11 tried using the Binary Search,
how many tries would it take for a 4000 page phone book?
21.
For a Binary Search to work, what must be true of the list?
22.
The Binary Search has variables named lo and hi. What does it mean if hi becomes less than lo?
True/False
_____23. int, char, float, double, and bool are all “simple” data types.
_____24. Any data type that can store more than one value is a data structure.
_____25. A data structure is a data type whose components are smaller data structures and/or simple data
types.
_____26. The first historical data structure is a file.
_____27. A record is frequently also called a vector.
_____28. A record is a data structure with one, or more, elements, called fields, of the same or different
data types.
_____29. An array is a data structure with one of more elements of the same or different data types.
_____30. A file is an external data structure with a specified number of elements assigned to an internal
file name.
_____31. The file data structure allows transfer of data between internal and external storage.
_____32. Records, arrays, and files are all data structures.
Fill in the blank with the correct answer. Assume each statement happens in order. Each statement will affect
the next statement.
int ray = {8,5,21,66,7,3,1};
System.out.println(ray[0]);
System.out.println(ray[1]);
System.out.println(ray[5]);
System.out.println(ray[1/2]);
System.out.println(ray[2]);
System.out.println(ray[3%2]);
System.out.println(ray[ray[5]]);
System.out.println(ray.length);
33. ____________________
34. ____________________
35. ____________________
36. ____________________
37. ____________________
38. ____________________
39. ____________________
40 . ____________________
Show the output of the code below:
41. int[] nums = new int[10]; //assume all spots are set to 0
int total = 0;
for (int i=0; i<nums.length; i++)
{
nums[i] = i*3;
out.println(nums[i]);
total = total + nums[i];
}
Variables // Show the changes as they occur!!!
i total nums
0
1
0
0
2
0
3
0
4
0
5
0
Output
6
0
7
0
8
0
9
0
You must
redraw the array
each time it
changes.
An int array (list) stores the following values. Use the array to answer questions:
19
14
12
2
6
8
18
42. When searching for 2, how many times would the while loop execute using a linear/sequential search?
What value would it return?
43. What is the value of list.length; ?
44. When deleting 14? What would the array look like afterwards? What happens to size?
45. Write code to change the value of 2 to 22?
46. After four passes of the inside for loop in a selection sort, what are the contents of the array?
47. After running the selection sort, how many comparisons would be necessary when using a binary search for
the finding the number 8?
48. Rewrite the code below with the new for loop.
for (int k = 0; k < 9; k++)
System.out.print(list[k] + " ");
49. When declaring an array of ints, doubles, String and chars, what are the default values of each?
50. How is each item in the array referred by?