0% found this document useful (0 votes)
11 views3 pages

Sheet 02

The assignment focuses on comparing the time and space complexities of iterative and recursive algorithms by implementing a Java program to compute the nth Fibonacci number. Students will analyze both approaches theoretically and graphically, documenting their findings in a structured format. Additionally, there are optional extra credit tasks involving runtime measurement and memory usage analysis using various tools.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Sheet 02

The assignment focuses on comparing the time and space complexities of iterative and recursive algorithms by implementing a Java program to compute the nth Fibonacci number. Students will analyze both approaches theoretically and graphically, documenting their findings in a structured format. Additionally, there are optional extra credit tasks involving runtime measurement and memory usage analysis using various tools.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EC2731 Data Structures and Algorithms In Class Assignment 2

Comparison of Time and Space Complexities of Iterative


versus Recursive Algorithms
Assignment Date March 12, 2025
Duration 1 hour 45 minutes (8.30AM-10.15AM)
Preparation Time 2 hours

Introduction to Assignment
In our previous laboratory exercise, we analyzed the time complexity of a polynomial function
using Excel as our primary tool. In this current experiment, we will implement a Java program
to compute the nth Fibonacci number through both iterative and recursive implementations.
Our objectives include comparing the time and space complexities of these two approaches and
drawing meaningful conclusions about their efficiency trade-offs.

Covered Learning Outcomes


The assignment will cover LO1 (Analyse the time and space complexity of algorithms using
asymptotic notation, including best-case, worst-case, and average-case scenarios.)

Investigation Steps
Part A: Iterative Implementation
1. Write a program, FibonacciIterative, to compute the nth Fibonacci number using an
iterative approach.

2. Perform a theoretical analysis to determine the Big-O time complexity of this Java
program.

3. Perform a theoretical analysis to determine the Big-O space complexity of this Java
program.

4. Introduce a static variable inside the innermost loop to count the number of iterations
for a given n. Determine its Big-O complexity, providing justification. You may compute
this for individual values of n or modify the program to analyze a range of n values. Use
Excel or any other tool to plot a complexity graph.

5. Modify the program to compute the space complexity. Follow a similar graphing mecha-
nism as item (4).

March 2025
Part B: Recursive Implementation
1. Write a program FibonacciRecursive to compute the nth Fibonacci number using a
recursive approach.

2. Perform a theoretical analysis to determine the Big-O time complexity of this Java
program.

3. Perform a theoretical analysis to determine the Big-O space complexity of this Java
program.

4. Introduce a static variable at the appropriate location in the program to count the number
of recursive calls for a given n. Follow a similar approach as in the iterative case.

5. Modify the program to compute its space complexity and use a similar graphing approach
as in item (4).

Submission Guidelines
Use the IC02.docx template provided on CourseWEB for your submission. Copy and paste the
Excel diagrams and tables into the template, adjusting section sizes as needed. Only one sub-
mission per group is required. Before uploading, rename the file to IC02 ¡Group Number¿.docx
and convert it to PDF before uploading.

Grading Scheme
This assignment accounts for 5% of your final grade. Each subpart is worth 10 marks, distributed
across the following criteria: accuracy of the estimates, methodology, and the explanation
provided.

Recommended Post Laboratory Investigation for Extra Credit


There are some limitations you may find interesting after investigating the cases above. Com-
plete the following tasks to deepen your understanding. The exercises given below apply to both
the iterative and recursive methods. You may use the IC02A.docx file to submit your answers.
Before uploading, rename the file to IC02A ¡Group Number¿.docx. As usual you can cut and
paste your work into the spaces provided in the document. Correct submissions will earn an
additional 25% of the grade. Submission is optional.

1. One way to measure the running time of a Java program is by using the Runtime interface
through System.nanoTime() or System.currentTimeMillis(). Modify the programs
to include additional code for measuring execution time. Analyze both the iterative and
recursive cases, graph the results, and compare them with the findings from Parts A and
B. Explain the results and determine whether this method produces the same conclusions.
If not, provide an explanation.

2. There are multiple ways to determine the memory usage of a Java program. One approach
is to use the Runtime.getRuntime() interface. Modify the programs in Sections A and B
to include this runtime interface for measuring memory usage during execution. Graph the

2
results and compare them with the findings from Parts A and B. Explain the results and
assess whether this method yields the same conclusions. If not, provide an explanation.

3. Another method for measuring execution time and memory usage is by using a profiling tool
such as VisualVM. Install VisualVM, conduct the above experiment again, and summarize
your conclusions.

Plagiarism Policy and Academic Honesty Guidelines


Academic honesty is essential for student integrity and reflects the values of the institution.
While collaboration—such as discussing assignments and sharing references—is encouraged,
plagiarism occurs when someone else’s work is presented as one’s own without proper acknowl-
edgment.
Forms of Plagiarism Include: Copying text, code, or ideas without citation. Submitting work
done by others. Using AI-generated content without disclosure. Self-plagiarism (reusing one’s
past work without approval).
Consequences of Plagiarism: Offenses may result in penalties ranging from reduced grades
to academic probation or expulsion.
How to Avoid Plagiarism: Cite all sources properly. Paraphrase correctly instead of copying.
Use plagiarism detection tools when allowed. Acknowledge contributions in group work. Ask
instructors for clarification when needed. Maintaining academic honesty ensures a fair and
ethical learning environment.

You might also like