Lab 3
Lab 3
Lab 3: Sorting
Each group chooses either of the following sets to complete the project.
• Set 1 (7 algorithms): Selection Sort, Insertion Sort, Bubble Sort, Heap Sort, Merge Sort, Quick
Sort, and Radix Sort.
• Set 2 (11 algorithms): Selection Sort, Insertion Sort, Bubble Sort, Shaker Sort, Shell Sort, Heap
Sort, Merge Sort, Quick Sort, Counting Sort, Radix Sort, and Flash Sort.
1 Programming
1.1 Algorithms
You are asked to implement ALL algorithms (for ascending order only) present in the set you have
selected, using C/C++ programming language.
1.2 Experiments
The experiments necessary for this project should be conducted following the below scenario.
1.2.1 Data Order Examine the selected sorting algorithms on different data arrangements, in-
cluding Sorted data (in ascending order), Nearly sorted data, Reverse sorted data, and
Randomized data. See DataGenerator.cpp for more information.
1.2.2 Data Size Examine the selected sorting algorithms on data of the following sizes: 10,000,
30,000, 50,000, 100,000, 300,000, and 500,000 elements.
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 1 / 7
Data Structures & Algorithms Knowledge Engineering Department
1. Algorithm mode: In this mode, you are asked to run a specified sorting algorithm on the input
data, which is either given or generated automatically and presents the resulting running time
and/or number of comparisons.
• Command 2: Run a sorting algorithm on the data generated automatically with specified
size and order.
– Prototype: [Execution file] -a [Algorithm] [Input size] [Input order]
[Output parameter(s)]
– Ex: a.exe -a selection-sort 50 -rand -time
– Console output:
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 2 / 7
Data Structures & Algorithms Knowledge Engineering Department
2. Comparison mode: In this mode, you have to run TWO specified sorting algorithms on the
input data, which is either given or generated automatically and presents the resulting running
times and/or numbers of comparisons.
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 3 / 7
Data Structures & Algorithms Knowledge Engineering Department
3. Input arguments: The following arguments are applied for both modes.
a. Mode:
• -a: Algorithm mode
• -c: Comparison mode
b. Algorithm name: Lowercase, words are connected by "-" (Ex: selection-sort, binary-
insertion-sort, ...)
c. Input size: Integer (≤ 1, 000, 000)
d. Input order:
• -rand: randomized data
• -nsorted: nearly sorted data
• -sorted: sorted data
• -rev: reverse sorted data
e. Given input (file): Path to the input file. The file format is as follows.
• 1st line: an integer n, indicating the number of elements in the input data
• 2nd line: n integers, separated by a single space.
f. Output parameters
• -time: algorithms’s running time.
• -comp: number of comparisions.
• -both: both above options.
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 4 / 7
Data Structures & Algorithms Knowledge Engineering Department
4. Writing files: Besides the console output described above, you are required to write down the
corresponding input(s) or output(s).
• For Command 1 and Command 2: Write down the sorted array to the "output.txt" file.
• For Command 2 and Command 5: Write down the generated input to the "input.txt" file.
• For Command 3: Write down all four generated input:
– "input_1.txt": random order data
– "input_2.txt": nearly sorted data
– "input_3.txt": sorted data
– "input_4.txt": reversed data
The file format (for both input and output files) is as follows.
• 1st line: an integer n, indicating the number of elements in the input data
• 2nd line: n integers, separated by a single space.
2 Report
Your report file should include the following sections:
1. Information page
2. Introduction page
3. Algorithm presentation: In this section, you present the algorithms implemented in the
project: ideas, step-by-step descriptions, and complexity evaluations (in terms of time com-
plexity and space complexity, if possible). Variants/improvements of an algorithm, if there are
any, should be also mentioned.
• You are required to organize the experimental results into FOUR tables, each representing
one Data order. In each table, present the resulting statistics (i.e., running times or numbers
of comparisons) of all sorting algorithms following a specific data arrangement. The table
template is shown below:
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 5 / 7
Data Structures & Algorithms Knowledge Engineering Department
Figure 1: An example of a line graph for visualizing the algorithms’ running times on randomized input data.
– There will be four BAR CHARTs, each of which corresponds to a table of numbers of
comparisons. In every graph, the horizontal axis is for Data Size, and the vertical axis
is for the number of comparisons, as shown in Figure 2.
• Make comments based on your own observations on each graph (e.g., the fastest / slowest
or the most / least comparisons algorithm(s) in each case, time or comparisons acceleration
of algorithms, etc.). Explain your comments.
• Make an overall comment of algorithms on all Data Order and all Data Size (the fastest /
slowest algorithms overall, grouping the stable/unstable algorithms, etc.)
5. Project organization and Programming notes: A brief explanation of how you organized
your source codes, and notes of any special libraries/data structures used.
6. List of references.
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 6 / 7
Data Structures & Algorithms Knowledge Engineering Department
Figure 2: An example of a bar chart for visualizing the algorithms’ numbers of comparisons on randomized input data.
3 Submission
This is a 4-person group project. Formation of groups with less than 4 members requires permission
from the lecturers. Individual assignments will not be accepted.
– SOURCE folder: the project’s source codes, only files of extensions .cpp and .h are required.
– Report.pdf: the report file of extension .pdf.
– Checklist.xlsx: the Excel template file filled with your own information.
• Compress the above folder into a file of extension zip or rar and name it following your Group ID
(Ex: "23127996-23127997-23127998-23127999.rar"). Group ID is the combination of all Student
IDs from the group members, sorted increasingly.
Plagiarism and Cheating will result in a "0" (zero) for the entire course and will be subject to
appropriate referral to the Management Board for further action.
This is the personal asset of the Department of Knowledge Engineering. Please do not copy. Page 7 / 7