Spring25 ProgrammingProject
Spring25 ProgrammingProject
Programming Project
Posted on March 14, due on April 25
1. Introduction
This is an individual project, meaning each student must complete it independently. The primary
objectives of this project are (1) to empirically observe the computational complexities of different
algorithms solving the same problem, and (2) to analyze how well theoretical complexity estimates
align with actual execution times.
Students will implement and compare two algorithms (ALG1 and ALG2) that solve the same
problem. The implementation must strictly follow the pseudocode covered in class; please refer to
the lecture notes and textbook for guidance. Students may use C, C++, Java, or Python. If you
wish to use a different programming language, consult the instructor beforehand.
This project is individual work. Students must write their own code and prepare their own report.
Plagiarism and unauthorized collaboration are strictly prohibited. Ensure compliance with the
Honor Code Policy in the syllabus, specifically the Regulation 4.001 Code of Academic Integrity.
Carefully review the definitions of cheating and plagiarism to avoid violations.
Each student must submit the Project Report, Source Code, and Project Demo. Further details on
submission requirements will be provided later in this document.
Students will implement and compare two algorithms: Brute-Force (ALG1) and Divide-and-
Conquer (ALG2).
The Brute-Force (ALG1) algorithm, covered in Module 4, has a running time of Θ(n2). The Divide-
and-Conquer (ALG2) algorithm, discussed in Module 2, has a running time of Θ(nlog2n).
When implementing these two algorithms, students must adhere to the following requirements:
• Follow the algorithms taught in class (e.g., from the textbook or lecture notes). If the
algorithm includes a while loop to traverse the array, students must use a while loop as well.
Implementing or using alternative versions from external sources, such as the internet, will
not receive credit.
• Indexing adjustments: The algorithms discussed in class use 1-based indexing (e.g., points
P1, P2, …, Pn). Since most programming languages use 0-based indexing, students may
convert the pseudocode to use indices ranging from 0 to n-1 as needed.
1
COT 6405: Analysis of Algorithms
• Choose a programming language: You may use C, C++, Java, or Python for your
implementation.
• Input sizes for measuring running time (RT):
The RT will be measured for the following input sizes:
n=10000, 20000, 30000, 40000, …, 100000 (i.e., 10 values from 10k to 100k, with an increment
of 10k).
Alternative option: If n=100k takes too long on your machine, you may instead use:
n=10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000 (i.e., 10 values
from 10k to 55k, with an increment of 5k).
• Number of iterations per input size:
Each input size n will be tested 10 times (m=10 iterations).
For example, for n = 10k elements, you will measure the RT on 10 different randomly
generated arrays of length 10k and report the average RT.
• Use the same input for both algorithms:
Each pair of algorithms must be tested on identical input arrays to ensure a fair comparison.
• Generating random points:
The x and y coordinates of the n points should be randomly generated. Ensure that all n points
are distinct (i.e., no two points should have the same x, y coordinates).
One approach is to use rand(), which generates a random number between 0 and RAND_MAX
(32,767). If using C, include the header #include<stdlib.h>.
• Measuring running time:
To measure execution time, use a function that returns the current time. In C, gettimeofday
provides time in seconds and microseconds. You can view its manual with "man gettimeofday".
Call this function before and after executing the algorithm and compute the elapsed time as the
difference between the two values.
• Memory allocation considerations (C/C++ users):
Do not allocate large arrays or vectors on the stack, as this may cause a stack overflow error.
Incorrect (Stack allocation - will cause errors):
int solution_alg(....) {
int very_large_array[1000000];
// THIS GOES ON THE STACK AND IT GETS ERROR
....
Correct (Heap allocation - recommended for large arrays):
Use malloc/calloc/new for heap allocation, and remember to deallocate when no longer needed.
Another option in C++ is to declare the array as a global variable.
2
COT 6405: Analysis of Algorithms
Tables
Background:
The theoretical complexity is computed using a “static” analysis, i.e. looking at the pseudocode.
The constant c accounts for instructions which are not in the loops and it also depends on the
technology, such as the Python interpreter used and the speed of the computer running our code.
We will compute an estimate of the constant c using a “dynamic” analysis, which involves running
the code.
For each algorithm, we use a Table to compute the hidden constant c. The table has the following
columns: n, TheoreticalRT, EmpiricalRT, Ratio, PredictedRT. See the example below.
Table ALG1
n TheoreticalRT EmpiricalRT Ratio = Predicted
n2 (msec) (EmpiricalRT)/(TheoreticalRT) RT
PredictedRT = c1∗TheoreticalRT
PredictedRT = c1∗n2
3
COT 6405: Analysis of Algorithms
Graphs
When drawing the graphs, do not smooth the plot; ensure that discrete data points are clearly
displayed using markers for each value of n.
The report must include the following three graphs:
1. Empirical Running Time Comparison
o X-axis: n=104, 2∗104, 3∗104, ….10∗104
o Y-values: ALG1:EmpiricalRT and ALG2:EmpiricalRT
2. Brute-Force Algorithm (ALG1): Empirical vs. Predicted Running Time
o X-axis: n=104, 2∗104, 3∗104, ….10∗104
o Y-values: ALG1:EmpiricalRT and ALG1:PredictedRT
3. Divide-and-Conquer Algorithm (ALG2): Empirical vs. Predicted Running Time
o X-axis: n=104, 2∗104, 3∗104, ….10∗104
o Y-values: ALG2:EmpiricalRT and ALG2:PredictedRT.
6. Project Demo
The demo must be recorded using a screen video capture tool such as Camtasia or VLC.
Alternatively, you may use Zoom to record your project demo. The video must be uploaded to
YouTube or another freely accessible video-sharing platform that does not require registration or
login to watch. Include the video link in your report. The video duration must not exceed 3
minutes, so plan accordingly to efficiently demonstrate that your code runs properly. Your demo
must include:
• Compilation and Execution: Show how you compile and run the algorithms on simple test
cases.
• Input Generation and Consistency: Explain how the input values are generated and
demonstrate that both algorithms are executed on the same input.
• Average Running Time Calculation: Show how you compute the average values over
m=10 runs.
4
COT 6405: Analysis of Algorithms
Please refer to the Grading Rubric posted on Canvas for detailed evaluation criteria.