1 / 3100%
Last Name(print) ______________________ First__________________ 10/13/08 5 extra Pts
1. JApplet is an extension of Applet. What package is JApplet located in?
______________________________________
2. What layout managers could you use to place components in 4 columns over 7 rows?
_____________________________________
3. What methods must be implemented if a class implements ActionListener interface?
__________________________________________
4. If you have a JButton object named button1” and a listener class named ButtonOneListener, how do you associate
the listener with button1”?
5. Classes in a software system can have various types of relationships to each other
List the three of the most common relationships:
1. __________________________
2.__________________________
3.__________________________
6. Given the following divisions, how could this be accomplished using different layouts?
Practice Searching & Sorting– CSE 205 – Fall 2008
7. For the following Array show how the array would be sorted using Selection sort and Insertion sort after each pass of
the outer loop. [9,6,14,11,3,12,7,5]
8. What is the complexity of the following code (in terms of the length of the array), assuming someMethod has a
complexity of O(1)?
for(int i = 0; i < array.length; i++)
for(int j = 0; j < array.length; j++)
someMethod(array[j]) _____________________
9. What is the complexity of the following code (in terms of the length of the array)?
for(int i = 0; i < 5; i++)
System.out.println(array[i]); ____________________
10. Which of the following algorithms has a time complexity of O(log2 n)?
a) insertion sort
b) selection sort
c) bubble sort
d) linear search
e) binary search
11. Which of the following algorithms has a worst-case complexity of O(n2)?
a) insertion sort
b) selection sort
c) bubble sort
d) all of the above
e) neither a, b, nor c
Answer:
1. javax.swing.JApplet
2. GridLayout
3.public void actionPerformed(ActionEvent event)
4. button1.addActionListener(new ButtonOneListener());
5. Dependency: A uses B
Aggregation: A has-a B
Inheritance: A is-a B
6. Start with BorderLayout, this creates the top section (North), bottom section (South), and the left, center, and right
sections (West, Center, and East).
In the West section, use a vertical BoxLayout to create the 4 sections.
In the Center section, use GridLayout.
In the East section, use FlowLayout.
7. Selection sort:
[3,6,14,11,9,12,7,5]
[3,5,14,11,9,12,7,6]
[3,5,6,11,9,12,7,14]
[3,5,6,7,9,12,11,14]
[3,5,6,7,9,12,11,14]
[3,5,6,7,9,11,12,14]
[3,5,6,7,9,11,12,14]
Insertion sort:
[6,9,14,11,3,12,7,5]
[6,9,14,11,3,12,7,5]
[6,9,11,14,3,12,7,5]
[3,6,9,11,14,12,7,5]
[3,6,9,11,12,14,7,5]
[3,6,9,11,12,14,7,5]
[3,6,7,9,11,12,14,5]
8. The complexity of this code is O(n2).
9. The complexity of this code is O(1), since the length of the array does not matter.
10. e
11. d
Powered by TCPDF (www.tcpdf.org)
Students also viewed