0% found this document useful (0 votes)
18 views

Week 1 - Module 1 - Introduction To Algorithms and Complexity

Uploaded by

acercrollercoil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Week 1 - Module 1 - Introduction To Algorithms and Complexity

Uploaded by

acercrollercoil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS-6202 : ALGORITHMS and COMPLEXITY

Module 1:​ ​ ​Introduction

Objectives :

At the end of the lesson, the student should be able to :

● Define algorithm
● Identify the criteria of an algorithm
● Differentiate time and space complexity
● Characterize the size of the input of an algorithm

An algorithm is a finite set of instructions, those if followed, accomplishes a particular task. It


is not language specific, we can use any language and symbols to represent instructions.

The criteria of an algorithm


1. Input:​ Zero or more inputs are externally supplied to the algorithm.
2. Output:​ At least one output is produced by an algorithm.
3. Definiteness:​ Each instruction is clear and unambiguous.
4. Finiteness: ​In an algorithm, it will be terminated after a finite number of steps for
all different cases.
5. Effectiveness:​ Each instruction must be very basic, so the purpose of those
instructions must be very clear to us.

Analysis of algorithms
Algorithm analysis is an important part of computational complexities. The complexity
theory provides the theoretical estimates for the resources needed by an algorithm to solve
any computational task. Analysis of the algorithm is the process of analyzing the
problem-solving capability of the algorithm in terms of the time and size required (the size of
memory for storage while implementation). However, the main concern of the analysis of the
algorithm is the required time or performance.

Complexities of an Algorithm

Choosing the fastest algorithm for a certain task requires that you can estimate the runtime
of an algorithm.
CS-6202 : ALGORITHMS and COMPLEXITY
Module 1:​ ​ ​Introduction

The absolute runtime of an algorithm is determined by several things, for example:

● The Hardware it is running upon


● The programming language you are using
● The compiler / runtime environment you are using

All these factors influence the actual runtime of an algorithm.To compare the runtime
behavior of algorithms is important to have a mean to eliminate all these factors and to find a
common description of the runtime.

The complexity of an algorithm computes the amount of time and spaces required by an
algorithm for an input of size (n). The complexity of an algorithm can be divided into two
types. The ​time complexity​ and ​space complexity​.

Time Complexity of an Algorithm

The time complexity is defined as the process of determining a formula for total time
required towards the execution of that algorithm. This calculation is totally independent of
implementation and programming language.
CS-6202 : ALGORITHMS and COMPLEXITY
Module 1:​ ​ ​Introduction

Space Complexity of an Algorithm


Space complexity is define as the process of defining a formula for prediction of how
much memory space is required for the successful execution of the algorithm. The
memory space is generally considered as the primary memory.

Time for an algorithm to run t(n)


In analyzing an algorithm rather than a piece of code, we will try and predict the number
of times "the principle activity" of that algorithm is performed. It means it describe
approaches to the study of the performance of algorithm.

For example, if we are analyzing a sorting algorithm we might count the number of
comparisons performed, and if it is an algorithm to find some optimal solution, the
number of times it evaluates a solution. If it is a graph coloring algorithm we might count
the number of times we check that a colored node is compatible with its neighbors.

A function of input. However, we will attempt to characterize this by the size of the input.
We will try and estimate the ​WORST CASE​, and sometimes the ​BEST CASE​, and very
rarely the ​AVERAGE CASE​.

Worst Case ​...the worst-case runtime complexity of the algorithm is the function defined
by the maximum number of steps taken on any instance of ​size a​.

Best Case ..​. the best-case runtime complexity of the algorithm is the function defined by
the minimum number of steps taken on any instance of ​size a​.

Average Case .​..the average case runtime complexity of the algorithm is the function
defined by an average number of steps taken on any instance of​ size a​.
CS-6202 : ALGORITHMS and COMPLEXITY
Module 1:​ ​ ​Introduction

​ et us consider an algorithm of sequential searching in an array of size n.


Example. L

References:

1. https://www.tutorialspoint.com/Algorithms-and-Complexities?fbclid=IwAR
0F12_mkFt8hoQLfRkWjbVhKXEvdodMDrM5fE3_MrlSBuVRo4I1OXuHt4U

2. https://www.hackerearth.com/practice/notes/complexity/

You might also like