Programming and Computer Science in Java:
Quiz #2 (even version):
More Sorting Algorithms and Chapter 2

    David Kosbie, 2002-2003
See Course Home Page

Quiz Date:  Fri, Feb 7, 2003

Important note:  Quiz difficulty levels will increase with each of the first few quizzes.  That is, this quiz is quite a bit less difficult than future quizzes in this class.

Problem 1:  State whether you are on an EVEN or an ODD computer.

Problem 2:  State (in 10 words or less) the difference between "print" and "println".

Problem 3:  Explain (in 20 words or less) how Insertion Sort works.

Problem 4:  What will the following program fragment print out?

int x, y;
x = 5;
y = 2;
System.out.println(y);
y = x/2;
System.out.println(y);

Problem 5:  What will the following program fragment print out?

int x;
x = 1 + 2 * 4 - 3;
System.out.println(x);

Problem 6:  Given the following stack of cards, what will the stack be after one full pass of the Bubble Sort algorithm?

17  22  12  19  4  55  8

Problem 7:  Given the following stack of cards, what will the stack be after one full pass of the Quick Sort algorithm?

17  22  12  19  4  55  8

Problem 8:  Consider the following Java program fragment:

line 1:  int a, q;
line 2:  // initialize
line 3:  a = 15;
line 4:  q = 12;
line 5:  // now loop
line 6:  while (a < q)
line 7:  {
line 8:     q = q - 1;
line 9:     a = a + 1;
line 10: }

List each of the following as they occur in this fragment:
8a)  All the variables
8b)  All the values
8c)  All the keywords
8d)  The line #'s of all the declarations
8e)  The line #'s of all the assignments
8f)  The line #'s of all the comments
8g)   All the operators
8h)  Extra credit:  what value will "q" have at the end of this fragment?

Good luck!

DK


See Course Home Page