Skip to main content

CSE 331 Homework 0: Course Survey and Paper Programming Exercise

Due Friday, October 2 at 11:59pm (late policy).

Part 1: Brief survey

Please fill out the course survey.

Part 2: Programming on paper

For this part, please find a blank sheet of paper and a writing utensil. Please write a Java method that solves the problem below. Do not compile or test your program on a computer. Do not use external resources such as web searches or AI to help you with this problem. Since you do not have access to a compiler or normal reference materials, you will not lose points for minor syntax/formatting errors. Just try to make it clear what you were trying to do.

/**
 * Reorder the elements of the given array so that all the negative numbers come
 * first, followed by all the zeros, followed by all the positive numbers.
 *
 * For example, if, before the method runs, the array stores
 *     [5, -1, 0, -1, 0, 5, -2, 7]
 * then, after the method runs, the array might store
 *     [-1, -1, -2, 0, 0, 5, 5, 7]
 * or
 *     [-1, -2, -1, 0, 0, 7, 5, 5]
 * or any other ordering of the negatives amongst themselves and positives
 * amongst themselves.
 *
 * Notice how any order amongst the negative elements is allowed, as long as all
 * negative elements come before the zeros. Similarly, any order of positive
 * elements is allowed as long as they come after the zeros.
 *
 * You may assume the array is not null.
 */
void kindaSort(int[] a) {
  // your code here
}

You should try your best to make sure your code is correct, even though you did not compile or test it.

If you like, you may write swap(a, i, j); to mean "swap elements at indices i and j of array a".

Full credit requires a correct solution that runs in linear time in the length of a and uses no auxiliary data structures: no second array, list, or map, just a and a few variables. A good-faith attempt that falls short of that earns partial credit.

Even better, if possible, your code should make a single pass over the array. You will not lose points for not meeting this one.

The staff solution is approximately 15 lines of code not including the starter code or blank lines or comments.

Take a picture of your sheet of paper and upload it to the "HW0 programming on paper" assignment on Gradescope.

Please do not spend more than 1 hour on this part. If you get to the end of 1 hour and are not done yet, write "I spent 1 hour on this, and this is what I have so far" and turn it in.