Lecture 1
Lecture 1
• Concepts of Algorithms
o Algorithm Definition
o Characteristics of Algorithms
o Algorithm Efficiency
o Analysis and Complexity of Algorithms
2
Course Objectives
• By the end of the course, the successful student will
be able to:
3
Textbook
4
Concepts of Algorithms
5
Concepts of Algorithms
• What is an algorithm?
o Algorithms must be :
6
Concepts of Algorithms
• What is an algorithm?
7
Concepts of Algorithms
8
Algorithm 1:
Maximum element
• Given a list, how do we find the maximum element
in the list?
9
Algorithm 1:
Maximum element
• Algorithm for finding the maximum element in a list:
10
Algorithm 1:
Maximum element
procedure max (a1, a2, …, an: integers)
max := a1
for i := 2 to n
if max < ai then max := ai
max 9
7
4
a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
4 1 7 0 5 2 9 3 6 8
i 10
9
8
7
6
5
4
3
2
11
Algorithm 1:
Maximum element
12
Algorithm 2: Linear search
• Given a list, find a specific element in the list
o List does NOT have to be sorted!
13
Algorithm 2: Linear search
procedure linear_search (a_list, x_value)
for ( int i = 1 ; i <= n ; i++ )
if x_value == a_list (i)
location = i and Enf if x 3
Else location = 0 and Enf if
location 8
End for and End procedure
a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
4 1 7 0 5 2 9 3 6 8
i 1
8
7
6
5
4
3
2
14
Algorithm 2: Linear search
procedure linear_search (a_list, x_value)
for ( int i = 1 ; i <= n ; i++ )
if x_value == a_list (i)
location = i and Enf if x 11
Else location = 0 and Enf if
location 0
End for and End procedure
a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
4 1 7 0 5 2 9 3 6 8
i 1
10
9
8
7
6
5
4
3
2
11
15
Algorithm 2: Linear search
• How long does this take?
16
Questions & Answers