CS341 - Data Structures and Algorithms
CS341 - Data Structures and Algorithms
CS341 Lab 2
• To calculate the execution time of java program you need to insert these two lines of codes
one as a starting point and the other as a finishing one.
• Afterwards to calculate the exact time you need to declare the following:
The main objective of Lab 2 is testing the temporal execution of different algorithms with different
temporal complexities.
Exercise 1:
Write a java program that returns the first letter in a user defined string.
a. Insert two strings with VERY different lengths and calculate the time execution of your
program.
b. Save the result.
Exercise 2:
a. Test your program on two different arrays sizes. Do not forget that your array needs to be
sorted.
b. Save the result of the execution time.
1
SMU-MedTech Lab-CS341 L2-Spring24
Exercise 3:
Exercise 4:
Write a java program that calculates the factorial of a user defined integer using a loop.
a. Insert two different numbers and calculate the time execution of your program.
b. Save the result.
Reminder:
Exercise 5:
Write a java program that returns the Nth Fibonacci number. The Nth Fibonacci Number can be
found using the recurrence relation shown above:
• if n = 0, then return 0.
• If n = 1, then it should return 1.
• For n > 1, it should return Fn-1 + Fn-2
a. Calculate the time of execution of your program.
b. Save the result.
Homework
2
SMU-MedTech Lab-CS341 L2-Spring24