Sorting and Searching Lab:
1) Show each step as selection sort is run on the array below.
[71 86 79 36 78 35 75 86 24 11]
At each step, separate the sorted and unsorted parts with the | symbol.
Then, put this into debug using the code given on the class powerpoint page.
2) Show each step as a merge sort is run on the array below.
[71 86 79 36 78 35 75 86 24 11]
At each step, separate the sorted and unsorted parts with the | symbol.
Then, put this into debug using the code given on the class powerpoint page.
3) Comparator – Arrays.sort
Write a comparator to sort the first letter b before a, but then alphabetically. Use it to sort with Arrays.sort.
Put your array into an Arraylist and use the
Collections reverseOrder()
to just sort normally backwards and then reverseOrder(Comparator<T> cmp) to sort the b before a comparator backwards.
4) Big data
Download a book from www.gutenberg.org
Read the words from the book into an ArrayList and then sort three times, once with each sort type (Selection, merge and then Arrays or Collections sort method) . Print and calculate the elapsed time with the following, and then print the sorted list.
For each of the 3 sorts, do this: (Selection, merge and then Arrays or Collections sort method)
start = System.currentTimeMillis();
System.out.println(start);
// do your sort
end = System.currentTimeMillis();
System.out.println(end);
System.out.println("sort time span is " + (end - start));
Upload to Lab Gutenberg And Lab2 Finch when you are done.
5) Goal: Give the user 4 possible sorting methods for running the commands in a file for the finch robot.
1. Download your robot code or the Finch Arrays Sorted 2 for lab. It had a list of commands you read in and sorted, and then you let your robot run.
2. Run that and see it work first. If you prefer not to use the actual robot, you can just print the commands the robot should do on the screen in the right order.
3. Ask the user whether they want to print reverse order. If they do, copy the array list commands into a stack (for loop to push) and then pull them out in reverse order (pop).
4. Ask the user whether they want to sort by time. If they do, sort by time. Use a comparator for that sort.
5. Ask the user whether to sort by the sort column or the time, and then ask if they want ascending or descending (reverse) order, and then run the robot commands in that order. (use Collections reverseOrder method to get the reverse order.
6. Upload to Lab Gutenberg And Lab2 Finch when you are done.