You are on page 1of 3

ECE242 PROJECT 1: Sorting and Searching Due: September 26, 2013, 11PM on Moodle

Introduction: In todays Internet-dominated world we take for granted the ability of computers to search through vast quantities of data to find information that interests us. The ability of search engines to find data quickly is the result of many programmers and algorithm designers efforts over a number of years. In this assignment you will have the opportunity to join the ranks of this prestigious group by developing Java code which will both sort and search through a database of information related to songs. This data, which is a subset of the Million Song Dataset, provides an example of the mass quantities of data that are evaluated by computers billions of times a day. In this assignment you will read in a database of information from an Excel file that contains information about 10,000 songs. You will then perform search and sort operations on the data to demonstrate the time differences between searches. Task Overview In this assignment you will perform the following specific tasks. 1. Read in the database of songs using the ReadSongArray method that we provide. The database contains the following information for 10,000 songs (title, artist, song duration, track ID). Note that you need to make an addition to the method. 2. Use a random number generator to arbitrarily select 2000 song titles. It is OK to select the same song title multiple times. 3. Perform a linear search in the database for each of the 2000 songs based on their titles. Use System.nanoTime() to measure the time duration for each search. 4. Use bubblesort to sort the 10,000 element database based on song title. Use System.nanoTime() to measure the time duration of your bubble sort algorithm. 5. Perform a binary search in the sorted database for the same 2000 songs you used for the linear search. Time each search using System.nanoTime(). 6. Calculate the average execution time for each linear and binary search. 7. Using the information calculated above, determine how many linear searches n would be necessary before the overall run time of the linear searches would be more than the combined total of the bubblesort (only performed once) and n binary searches.

Getting started The best way to complete any programming assignment (including this one) is to take tasks stepby-step. The first decision you need to make is the number of classes you will write. For this assignment, you should have at least three (preferable more) classes, including the SongArray class, some of which is provided. Please do not place all the methods for your entire project in one class. At a minimum, consider creating a Song and a driver class which will call objects of other classes (e.g. SongArray). After you read in the database, develop a class to randomly select the 2000 songs. Required output Please provide the following output from your program: 1. Print out the title, artist, and song duration of the first 10 songs that are successfully located in the database using the linear search. 2. Print out the title, artist, and song duration of the first 10 songs in your song database after bubblesort is performed 3. Print out the title, artist, and song duration of the first 10 songs that are successfully located in the database using the binary search (Hint: this should be the same as the first 10 for the linear search). 4. Print out the average and total time for both linear and binary searches. Also, print out the time required for the bubblesort 5. Print out how many linear searches n would be necessary before the overall run time of the linear searches would be more than the combined total of the bubblesort (only performed once) and n binary searches. You can assume that each linear and binary search requires the average times you have determined above. Hints and suggestions Successfully completing the project and achieving a good grade requires completing the project as described above and clearly commenting the code. As always, it makes sense to start the project early. Unless you are an amazing programmer, you probably wont be able to finish in one day. Build your project code step by step. For example, verify that you have successfully read in the database before attempting a linear search. Then, make sure the linear search works before writing and testing code for bubblesort, etc. Additional hints are as follows:

1. Make sure that there are no print or println statements in the code you are attempting to time. The use of these statements will negatively affect recorded time values and lead to incorrect results. Your submitted bubblesort, linear search, and binary search methods should not include these statements. 2. Use the Math.random() method to identify the 2000 random titles for searching. You can use the random numbers to locate specific song indices in the song database array. Note that you must save these song titles in an additional array before you perform the bubblesort. 3. Do not modify the code portions of the ReadSongArray method that are provided. You can fill in missing code which is noted in the method. 4. The bubblesort, linear search, and binary search methods can follow in a similar format to the ones used on the Discussion 2 code. What to submit: Please submit all .java files for your project. All code should be well commented. Reminder: The course honesty policy requires you to write all code yourself, except for the code that we give to you. Your submitted code will be compared with all other submitted code for the course to identify similarities. Note that our checking program is not confused by changed variable or method names. Grading: Code works (50%) Comments (20%) Program structure (20%) Readability (10%)

You might also like