0% found this document useful (0 votes)
1 views2 pages

Lab 2 - DSA - 23f

The lab manual focuses on performance analysis, specifically time and space complexity, and includes tasks to implement recursive algorithms for the Fibonacci series and factorial numbers. It explains the concepts of time and space complexity, along with iterative and recursive methods for generating Fibonacci numbers. The lab tasks require students to create programs that print the Fibonacci series and calculate factorials.
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)
1 views2 pages

Lab 2 - DSA - 23f

The lab manual focuses on performance analysis, specifically time and space complexity, and includes tasks to implement recursive algorithms for the Fibonacci series and factorial numbers. It explains the concepts of time and space complexity, along with iterative and recursive methods for generating Fibonacci numbers. The lab tasks require students to create programs that print the Fibonacci series and calculate factorials.
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/ 2

DATA STRUCTURE & ALGORITHM LAB MANUAL

Lab#02
SHOW PERFORMANCE ANALYSIS
(TIME COMPLEXITY AND SPACE COMPLEXITY)
LAB OBJECTIVE:
 Show Performance Analysis (Time Complexity and Space Complexity)
 Make a program of recursive algorithms of Fibonacci series and Factorial numbers.

LAB DESCRIPTION:

Performance Analysis:
Designing of the efficient algorithm is one of the major tasks. Time and space are the two main variables
on which the efficiency of an algorithm is depended. Time-Space tradeoff is done in different conditions,
it depends that by increasing the time, the space may be reduced and vice versa.

Space Complexity: of a program is the amount of memory it needs to run to completion.

Time Complexity: of a program is the amount of computer time it needs to run to completion.

Fibonacci sequence:
A Fibonacci sequence is the sequence of integer in which each element in the sequence is the sum of the
two previous elements.
Fn = Fn-1 + Fn-2
Recursive Algorithm
A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)" input values, and which
obtains the result for the current input by applying simple operations to the returned value for the smaller
(or simpler) input.

Example:
Fibonacci: Iterative Algorithm
First we try to draft iterative algorithm for Fibonacci series.
Procedure Fibonacci(n)
declare f0, f1, fib, loop

set f0 to 0
set f1 to 1
display f0, f1

for loop ← 1 to n
fib ← f0 + f1
f0 ← f1
f1 ← fib

display fib
end for
end procedure

DEPARTMENT OF COMPUTER SYSTEM ENGINEERING Page | 1


DAWOOD UNIVERSITY OF ENGINEERING AND TECHNOLOGY
DATA STRUCTURE & ALGORITHM LAB MANUAL

Fibonacci: Recursive Algorithm


Now we shall learn how to create recursive algorithm Fibonacci series. The base criteria of recursion.
START
Procedure Fibonacci(n)
declare f0, f1, fib, loop
set f0 to 0
set f1 to 1

display f0, f1

for loop ← 1 to n

fib ← f0 + f1
f0 ← f1
f1 ← fib

display fib
end for
END

OR
1. START
2. Input the non-negative integer ‘n’
3. If (n==o || n==1)
return n;
else
return fib(n-1)+fib(n-2);
4. Print, nth Fibonacci number
5. END

LAB TASK:
1. Make a program that prints the Fibonacci series.
2. Compile an algorithm to calculate the factorial and make a program.

DEPARTMENT OF COMPUTER SYSTEM ENGINEERING Page | 2


DAWOOD UNIVERSITY OF ENGINEERING AND TECHNOLOGY

You might also like