DSA # 1 Introduction To DSA
DSA # 1 Introduction To DSA
Introduction
Algorithm’s Description
Describe the main purpose of the algorithm
Describe the symbols and abbreviations used
Describe inputs/outputs, Etc...
Algorithm’s Statements
Presents the steps to be executed and perform the tasks
Which would be implemented using any programming
language
Data Structure & Algorithms
8
Example “To find largest element in array”
Algorithm’s Description
A non-empty array DATA with N numerical values is given.
This algorithm finds the location LOC of the largest value
MAX of DATA.
DATA The variable K is used as counter.
Algorithm’s Statements
Step 1.
1 [Initialize]
Initialize Set K := 1, LOC := 1 and MAX := DATA[1]
Step 2.
2 [Increment counter]
counter Set K := K + 1
Step 3.
3 [Test counter]
counter if K > N, then:
write: LOC, MAX and Exit
Step 4.
4 [Compare & Update]
Update if MAX < DATA[K], then:
Set LOC := K and MAX := DATA[K]
Step 5.
5 [Repeat loop]
loop Go to Step 2
Data Structure & Algorithms
9
Example “To find largest element in array”
OR steps can be written as
Algorithm’s Statements
Step 1.
1 Set K := 1, LOC := 1 and MAX := DATA[1]
Step 2.
2 Set K := K + 1
Step 3.
3 if K > N, then:
write: LOC, MAX and Exit
Step 4.
4 if MAX < DATA[K], then:
Set LOC := K and MAX := DATA[K]
Step 5.
5 Go to Step 2