Presentation is loading. Please wait.

Presentation is loading. Please wait.

Searching and Sorting Arrays Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 15-16, 2013.

Similar presentations


Presentation on theme: "Searching and Sorting Arrays Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 15-16, 2013."— Presentation transcript:

1 Searching and Sorting Arrays Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 15-16, 2013

2 Announcements CS Seminar – April 16, 2013 -- 2:00-3:00 PM in CCSB 3.0908 (Conference Room) – Maria Eskevich, Dublin City University – Title: Focus on Spoken Content in Multimedia Retrieval Lab 7 due today in lab HW 6.2, 6.6*, 6.12, 6.13 due today in lab Unit 3 Exam over Methods and 1D Arrays (Chapters 5 and 6) – Monday/Tuesday April 22/23 – Review this Wednesday/Thursday

3 Searching an Array Given an array and a value to search for, determine if the array contains that value. If so, return the index of the value; otherwise, return a negative value. Two different ways to search: – Linear search -- step through the array checking each item – Binary search -- if the array is known to already be in sorted order: check the middle item first and determine with which half to continue the search; repeatedly divide the list in half until the item is found or the there is nothing left to search. – Which way do you think is faster on the average?

4 Sorting an Array Given an array, sort the array into ascending (descending) order. Sort in place (this is usually done) or return a new copy that is in sorted order without changing the original array.

5 java.util.Arrays class Contains overloaded methods: – java.util.Arrays.sort(type[] list) – java.util.Arrays.binarySearch(type[] list, type value)

6 Class Activity Download from course website – LinearSearch.java – BinarySearch.java – SelectionSort.java Study these methods to understand how they work. Write a main program that randomly fills an integer array and then makes use of the methods. Write overloaded methods for linearSearch, binarySearch, and selectionSort for double type Try out the java.util.Arrays methods.

7 Assignments for Next Class Quiz 6 Take home questions Read Sections 6.10, 6.11, CheckPoint questions


Download ppt "Searching and Sorting Arrays Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 15-16, 2013."

Similar presentations


Ads by Google