Prelim Project OOP

4
Part A. Two Searching Algorithm Part 1. The objectives of this particular case study are: 1. To learn the different searching algorithms and their behaviors. 2. To be able to implement two searching algorithms, namely: linear and binary search in Java programming language. 3. To observe the relative performance of these different searching algorithms. 4. To explore programming involving the use of arrays and get to see array’s properties and way of manipulating data. 5. To strengthen the discipline of self-study. Part 2 Requirements: Write a Java program that will do the following in sequence: Linear Search 1. Ask the user to input a positive integer value that we will denote as n. Here n represents the size of the problem space, specifically, the number of random elements. 2. For linear search, the user will input the key/value that will be searched. 3. Once the key/value is found it will display the value including the index value. 4. It will also display the time that it searched in milliseconds. Binary Search 1. Ask the user to input a positive integer value that we will denote as n. Here n represents the size of the problem space, specifically, the number of random elements. 2. For binary search, the random number will be arranged in ascending order. 3. The user will input the key/value that will be searched. 3. Once the key/value is found it will display the value including the index value. 4. It will also display the time that it searched in milliseconds. Note: the next value of n is computed as n = n * 2. For example, after n = 64 the next n is computed as 64 * 2 = 128. n linear search binary search processing time key processing time key 32 64 128 : : : : 32768 65536

Transcript of Prelim Project OOP

Page 1: Prelim Project OOP

Part A. Two Searching Algorithm Part 1. The objectives of this particular case study are: 1. To learn the different searching algorithms and their behaviors.

2. To be able to implement two searching algorithms, namely: linear and binary search in Java programming language.

3. To observe the relative performance of these different searching algorithms.

4. To explore programming involving the use of arrays and get to see array’s properties and way of manipulating data.

5. To strengthen the discipline of self-study. Part 2 Requirements: Write a Java program that will do the following in sequence: Linear Search

1. Ask the user to input a positive integer value that we will denote as n. Here n represents the size of the problem space, specifically, the number of random elements.

2. For linear search, the user will input the key/value that will be searched.

3. Once the key/value is found it will display the value including the index value.

4. It will also display the time that it searched in milliseconds.

Binary Search

1. Ask the user to input a positive integer value that we will denote as n. Here n represents the size of the problem space, specifically, the number of random elements.

2. For binary search, the random number will be arranged in ascending order.

3. The user will input the key/value that will be searched.

3. Once the key/value is found it will display the value including the index value.

4. It will also display the time that it searched in milliseconds.

Note: the next value of n is computed as n = n * 2. For example, after n = 64 the next n is computed as 64 * 2 = 128.

n linear search binary search

processing time key processing time key

32

64

128

: :

: :

32768

65536

Page 2: Prelim Project OOP

Part B. Ten Sorting Algorithms Part 1. The objectives of this particular case study are: 1. To learn the different sorting algorithms and their behaviors.

2. To be able to implement 10 sorting algorithms, namely: bubble sort, selection sort, insertion sort, quick sort, shell, merge, radix and balloon sort in Java programming language.

3. To observe the relative performance of these different sorting algorithms.

4. To explore programming involving the use of arrays and get to see array’s properties and way of manipulating data.

5. To strengthen the discipline of self-study, conducting research and working alone. 6. Add 2 more sorting algorithms of you own. Requirements: Write a Java program that will do the following in sequence: 1. Ask the user to input a positive integer value that we will denote as n. Here n represents the size of the problem space, specifically, the number of elements to be sorted.

2. Create arrays for 10 lists of n integers.

3. For one array, its initial values are to be generated randomly (use the random function/method of your chosen library).

4. Copy the contents of the first array to the other ten arrays. After these step, all arrays should contain the same sequence of integer values.

5. Introduce a count variable into each of your sorting algorithms to keep track of the number of operations. You should able to discern well as to where should it best placed to count the “important” operations.

6. Sort the first array using bubble sort. Obtain the amount of time it took for bubble sort to rearrange the array as well as the count on the number of operations.

7. Sort the second array using selection sort and obtain the time it took to rearrange the array as well as the count on the number of operations.

8. Sort the third array using insertion sort and obtain the time it took to rearrange the array as well as the count on the number of operations.

9. Sort the fourth array using quicksort and obtain the time it took to rearrange the array as well as the count on the number of operations.

10. Sort the fifth array using shell sort and obtain the time it took to rearrange the array as well as the count on the number of operations. 11. Sort the 6th to 10th array using merge, radix, balloon and 2 other sorting algorithm and obtain the time it took to rearrange the array as well as the count on the number of operations. Run the program for different values of n based on the order. Obtain the processing time for each sorting algorithm and count, and fill up the following table. The processing time should be in milliseconds.

Page 3: Prelim Project OOP

Include radix sort, balloon sort, merge sort and 2 other sorting algorithms that you chose

Include radix sort, balloon sort, merge sort and 2 other sorting algorithms that you chose Note: the next value of n is computed as n = n * 2. For example, after n = 64 the next n is computed as 64 * 2 = 128.

Draw line graphs with x coordinates representing the values of n and y axis coordinates representing the processing time for each sorting algorithm. Graphs should be overlaid. Provide a concise discussion about the resulting graphs. Discussion can be (but not limited to): (a) What observations can be made from it? Correlate the count and processing time for each sorting algorithm.

(b) Does the performance of each sorting algorithm differ or the same regardless of the sorting order?

(c) Does efficiency is seen when arranging the values in ascending order, descending order or both?

(d) Do any of the algorithms run consistently the quickest? Slowest? Part 2. Using the programs created in Part 1, test each sorting algorithm again, but this time under the following scenarios: 1. Supply randomly generated values for one array where the values must be in descending order. This set of values must be replicated in the other four arrays. Sort the array in ascending order. Obtain the processing time and count for each sorting algorithm under different values of n as done in Part 1, and provide a discussion based on the observation seen. Provide the line graph as well. 2. Perform the process in #1, but this time, the set of randomly generated values must be in ascending order and you are to sort the data in descending order. Obtain the processing time and count for each sorting algorithm under different values of n as done in Part 1, and provide a discussion based on the observation seen.

Page 4: Prelim Project OOP

Provide the line graph as well. Part 3 Provide an overall conclusion based on the experiments did in Part 1 and Part 2. You should able to consolidate your analysis from both parts, do comparison and contrast as necessary. Provide in your discussion the identified program/time complexity of these algorithms as the value of n → infinity.

General Requirements: 1. You are to submit all the works did in this project in both printed document and electronic form on or before the specified due date. Submission of the printed document should be in A4 bond paper with short, white sliding folder. Submission of both versions must be done on the same day. In the event that one of the requirements is submitted at the latter date, that date will be considered as individual’s submission.

2. This project is mandatory for all the students in the lecture and laboratory class.

3. For the electronic version of your assignment: use the concatenated last names as filename and .java as the extension. For example if your last name is SANTOS, the file name should be santos.java (for Java program). PDF version on the tables and other needed documents. Email the electronic version to ____________________________ with subject heading as: PrelimProject-<Lastname of Person 1 (ID#)>. For example: PrelimProject-Santos(100893454).

4. The printed document should contain the following:

- An introduction of the prelim project

- A presentation, discussion and illustrations for both Part A and Part B.

- Include the source code in your documentation. One column per page only.

5. The printed document should be written in single-spaced, font name: Arial, font size: 12 with one- inch margin on each side.

6. Cover page with title, name of student is included. Timeline (using MS Project) should be at the last page.

Design Day: (Project Defense) on CPE40-Oct 11; CPE41-Oct 10; CPE42-Oct 12;