ECCE 342 Assignment Spring 2022

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Module Name: Data Structures/Data Structures and Algorithms

Module Code: COSC310/ECCE 342


Term: Spring 2022
Instructor: Dr. Jamal Zemerly
Lamees Alqassem, Taslim Mahbub, Farica Putri, Feruz
Lab Instructors:
Elmay, Obadah Habash, Manuel Rivera
Issue Date: 4th April 2022
Submission Deadline: 18th April 2022
Assignment Type: Individual

AIM
The aim of this assignment is to build a class (or more) and a driver class to test and
analyze the implementation and performance of various sorting algorithms.

Note: In case of any query please contact first your Lab Instructors.
TASKS
TASK 1. GENERATE DATA. [10 MARKS]
Design and write a Java class that generates data of 2000 books. The data for each book
consists of:

 Identifier. Unique 5-digit number. Digits are non-zero. Represented as DDDDD,


where D is 1 to 9.
 Title. The book title of three words maximum with a space between the words.
(FIRSTWORD SECONDWORD THIRDWORD)
 Name. The first name and last name of the author. The first and last names have
no spaces, there is comma separating two names. (LASTNAME,FIRSTNAME)
 Price. The price of the book ranges from $100 to $1,000

You will need to generate the data for the 2000 books into a text file called books.txt.
The values for all data cannot be repeated, meaning no two identifiers are the same, no
two names or titles are the same, etc. Below is a sample books.txt file.

books.txt
93842 Statistical Decision Theory Pratt,John 350
61275 Slaughterhouse Five Vonnegut,Kurt 1000

85938 Making Software Oram,Andy 150
93844 Orientalism Said,Edward 123

Your program must read and store the data of the books in an array of objects. Further,
the method should write the books data into a numbered and neatly formatted text file
called formatted_books.txt, as in the sample below. For good formatting, make
sure to use formatted printing printf().

formatted_books.txt
No. ID Name Title Price
1 93842 Pratt,John Statistical Decision Theory 350
2 61257 Vonnegut,Kurt Slaughterhouse Five 1000
...
1000 93844 Said,Edward Orientalism 123

TASK 2. SORTING DATA. [20 MARKS]


Write a sorting class which sorts the books data based on the name of the author
(ascending order). The sorting class must correctly implement the following 4 sorting
algorithms:
 ShortBubbleSort()
 QuickSort()
 HeapSort()
 MergeSort()

Use the implemented sorting algorithms on the array of books objects and write the
sorted arrays into the following numbered and neatly formatted files:

 isorted.txt (for bubble sort)


 qsorted.txt (for quick sort)
 hsorted.txt (for heap sort)
 msorted.txt (for merge sort)

Make sure that you maintain the integrity of the data after sorting.

TASK 3. QUANTITATIVE ANALYSIS. [30 MARKS]


Adjust the sorting algorithms such that you count the number of operations (type of
operations detailed below in the tables) performed. Also adjust the calling function such
that you record the time the algorithms take.

You will need to create 4 arrays of books (number of elements detailed below in the
tables) and apply the sorting algorithms on these unsorted arrays. Then again, you need
to re-apply the sorting algorithms on the sorted arrays.
TABLE 1. SHORT BUBBLE SORT ON UNSORTED ARRAY.

# Elements # Comparisons # Swaps Time (milliseconds)


500
1,000
1,500
2,000

TABLE 2. SHORT BUBBLE SORT ON SORTED ARRAY.

# Elements # Comparisons # Swaps Time (milliseconds)


500
1,000
1,500
2,000

TABLE 3. QUICK SORT ON UNSORTED ARRAY.

# Elements # Comparisons # Swaps Time (milliseconds)


500
1,000
1,500
2,000

TABLE 4. QUICK SORT ON SORTED ARRAY.

# Elements # Comparisons # Swaps Time (milliseconds)


500
1,000
1,500
2,000

TABLE 5. HEAP SORT ON UNSORTED ARRAY.

# Elements # Comparisons # Swaps # Reheap downs Time (milliseconds)


500
1,000
1,500
2,000

TABLE 6. HEAP SORT ON SORTED ARRAY.

# Elements # Comparisons # Swaps # Reheap downs Time (milliseconds)


500
1,000
1,500
2,000

TABLE 7. MERGE SORT ON UNSORTED ARRAY.

# Elements # Comparisons # Merge calls Time (milliseconds)


500
1,000
1,500
2,000

TABLE 8. MERGE SORT ON SORTED ARRAY.

# Elements # Comparisons # Merge calls Time (milliseconds)


500
1,000
1,500
2,000
TASK 4. QUALITATIVE ANALYSIS. [30 MARKS]
For each of the sorting algorithms, report on your results from the previous task, as to
how and why the algorithm performed as the number of elements increased, and as the
data got sorted.

You need to justify the retrieved number of operations in the unsorted case of 200
elements and estimate how these numbers can be calculated. Moreover, correlate the
time the algorithms took with its big-O time complexity.

Finally, investigate whether or not heap sort is a stable algorithm, and describe what
does that mean.

TASK 5. DISCUSSION. [10 MARKS]


Compare the performance of the four algorithms for the sorted and unsorted arrays in
terms of execution time and big-O time complexity – not T (n) –. Discuss and justify how
each algorithm can be optimal in a certain use case.
NOTES
HINTS
 Make sure that when you sort the books based on a certain column value, you
also sort the other parts of the books data.
 Note that you should rewrite the sorting algorithms given to you in class to cater
for ordering based on the Id, title, name, and price.
 You need to write a driver class to use the algorithms for testing.
 You need to write the program in an object-oriented style (must have at least
two classes).

CODE
 All submitted code should be properly documented and written in a good
programming style with comments and proper indentation.
 You are only allowed to use code from the notes in class or lab with no change of
structure or naming style (no internet code will be accepted).

SUBMISSION
 Submit screenshots of the results in the report (output files and console results).
 Your report must be a single Word document, containing all code, screenshots of
first and last 10 books for each run. Name your report document as
FIRSTNAME_ID.docx.
 Compress the .java files into a FIRSTNAME_ID.zip file and submit the code
along the Word document.
 Submission delay will be penalized by 5% points a day with a maximum delay of
5 days. Submissions after that will not be accepted.

WARNINGS
 No collaboration between students is allowed and any detection of plagiarism
from each other or from the internet will be penalized with zero mark for all of
those involved and will be reported to the Dean’s office to take further
disciplinary actions.

You might also like