Algorithm 1
Algorithm 1
Introduction
This course introduces the fundamental concepts of Designing Strategies, analysis of Algorithms. Also, it
includes the basic concepts on Complexity theory. Moreover; it outlines problems on searching, sorting,
divide and conquer and Graph theory methods.
Prerequisites
The students should have basic knowledge of programming and mathematics. The students should know
data structure very well. Moreover, it is preferred if the students have basic understanding of Formal
Language and Automata Theory.
References
1. Algorithms 4th Edition by Robert and Kevin,
2. Design and Analysis of Algorithm,
3. Data structures and algorithm analysis in C++ 4th Edition by Mark Allen and
4. Websites and YouTube.
1. Basics of Algorithm
An algorithm is known since early years in 9 decade. It has been invented by a Muslim scientist
Muhammad ben Musa Al-Khwarizmi. He lived in Bagdad in 780 - 847.
1.1. Definitions:
An Algorithm can be defined as writing in human language a sequence of finite logical steps for solving a
specific problem. An algorithm is an efficient method that can be expressed within finite amount of time and
space. Also, it is the best way to represent the solution of a particular problem in a very simple and efficient
way. Therefore; Design and Analysis of Algorithm (DAA) is very important for solving different types of
problems in the branch of computer science and information technology. If we have an algorithm for a
specific problem, then we can implement it in any programming language, meaning that the algorithm is
independent from any programming languages.
Algorithm also; can be defined as step by step procedure (process) for solving a specific problem.
A program is a written sequence of finite steps in one of programming language for solving a particular
problem. Each of these steps is a command to the computer to do a specific operation. Therefore a program
is a set of instructors to the computer to perform a specific task.
1
Lecture one: Introduction to Algorithms (Basics of Algorithm)
By Dr. Milad Elgargni
2. Algorithm Design
The important aspect for designing an algorithm is to create it in an efficient way in order to solve a problem
in a minimum time and space. To solve a problem, different approaches can be followed. Some of them can
be efficient with respect to time consumption, whereas other approaches may be memory efficient.
However, one has to keep in mind that both time consumption and memory usage cannot be optimized all
together. If we require an algorithm to run in lesser time, we have to invest in more memory and if we
require an algorithm to run with lesser memory, we need to have more time.
2
Lecture one: Introduction to Algorithms (Basics of Algorithm)
By Dr. Milad Elgargni
3
Lecture one: Introduction to Algorithms (Basics of Algorithm)
By Dr. Milad Elgargni
Algorithm: sumOfArray
Start
Step 1: Input an array A of integers of length n.
Step 2: Keep S equal to 0.
Step 3: add array elements to the S one by one.
Step 5: Print the value of S (Output of sum of array elements)
Step 6: Stop
Here is a pseudo code, which describes how the high level abstract process mentioned above in the
algorithm Insertion-Sort could be described in a more realistic way.
Algorithm: sum (A, n);
S 0;
n 5;
A[5] {1,2,3,4,5};
for (int i=0; i< n; i++)
4
Lecture one: Introduction to Algorithms (Basics of Algorithm)
By Dr. Milad Elgargni
S S +A[i];
printf("%d",S);
In this tutorial, algorithms will be presented in the form of pseudo code, which is similar in many respects to
C, C++, Java, Python, and other programming languages.
5.2. Flowchart
Flowchart is a way for representing an algorithm using drawing blocks as shown in example below.
Example 11:
Write an algorithm using both pseudo code and flowchart for calculating the average of three numbers.
Start
Stop
Home work:
1. Write an algorithm using both pseudo code and flowchart for calculating the average of ten numbers.
2. Write an algorithm using both pseudo code and flowchart to find the sum of array elements.