Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

1-1 Basics

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

ANALYSIS & DESIGN OF ALGORITHMS

(CS6401/CS5401)

Open Elective-II

Prof. Shilpa Verma (Coordinator & Instructor)


Prof. Arun Singh Pundir (Instructor)
Prof. Shweta Sharma (Instructor)
Google Classroom

Classroom link: https://meet.google.com/tqf-mbzj-jrj

Classroom Code: gpsc56z


Analysis & Design of Algorithms
(CS6401/CS5401)
• Course Name : Analysis & Design of Algorithms
• Course Code : CS6401/CS5401
• Credits : 4
•L T P : 3 0 2
• Mode : Offline
Analysis & Design of Algorithms
(CS6401/CS5401)
Course Objectives:
 To analyze various algorithms mainly for time and space complexity

 To develop algorithm for solving various computational problems by applying


various algorithm design strategies

 To understand the affect of choice of data structures on the complexity of


algorithm
Analysis & Design of Algorithms
(CS6401/CS5401)
Course Outcomes: At the end of the course, students will be able to:
 Demonstrate the ability to select the best data structure for
designing an algorithm to solve a given problem
 Demonstrate the ability to compare algorithms with respect to
time and space complexity
 Develop algorithms to solve various computational problems
Analysis & Design of Algorithms
(CS6401/CS5401)
Analysis & Design of Algorithms
(CS6401/CS5401)
Marks Distribution:

Total Marks 100


End Term 40%
Mid Term 20%
Lab Viva/Quiz and Assignment 20%
Quizzes on Analysis and Design 20%
of Algorithms
(Best 2 out of 3)
Introduction to Algorithms

A set of steps or
instructions to
accomplish a task

Dr. Shweta Sharma, PEC Chandigarh


Dr. Shweta Sharma, PEC Chandigarh
Introduction to Algorithms

Technically,
Algorithm is a set
of steps or  Google Meet
instructions for a  Video Conferencing
computer  Google classroom
program to solve
a problem or
accomplish a task

Dr. Shweta Sharma, PEC Chandigarh


Notion of Algorithm

• Need for studying algorithms:


• It can be recognized as the core of computer science.
Computer programs would not exist without algorithms.
• With computers becoming an essential part of our
professional & personal life’s, studying algorithms becomes
a necessity, more so for computer science engineers.
• Another reason for studying algorithms is that if we know a
standard set of important algorithms, They further enhance
our analytical skills & help us in developing new algorithms
for required applications
Algorithm (Definition)
• Definition (Wikipedia)
• An algorithm is an effective method for solving a
problem using a finite sequence of instructions.
• Definition (Donald Knuth)
• An algorithm is a finite, definite, effective procedure,
with some output.
• Definition (Britannica.com)
• Systematic procedure that produces – in a finite number
of steps – the answer to a question or the solution of a
problem.
Algorithm
• An algorithm is finite set of instructions that is followed, accomplishes a
particular task.
• In addition, all algorithms must satisfy the following criteria:
1. Input. Zero or more quantities are externally supplied.
2. Output. At least one quantity is produced.
3. Definiteness. Each instruction is clear and unambiguous.
4. Finiteness. If we trace out the instruction of an algorithm, then for all
cases, the algorithm terminates after a finite number of steps.
5. Effectiveness. Every instruction must be very basic so that it can be
carried out, in principal, by a person using only pencil and paper. It is
not enough that each operation be definite as in criterion 3; it also
must be feasible.
Algorithm
• Algorithms that are definite and effective are also
called computational procedures.
• The same algorithm can be represented in several ways
• Several algorithms can be used to solve the same
problem
• Different ideas may have different time to complete
task
• Eg, prime number (basic use n complexity while AKS
algo Used squareroot(n) complexity
Fundamentals of Algorithmic Solving
Understanding the Problem
• First thing you need to do before designing an algorithm is
to understand completely the problem given.
• Read the problem’s description carefully and ask questions
if you have any doubts about the problem,
• Do a few small examples by hand, think about special cases,
and ask questions again if needed.
• If the problem in question is one of them, you might be able
to use a known algorithm for solving it. Of course, it helps
to understand how such an algorithm works and to know its
strengths and weaknesses, especially if you have to choose
among several available algorithms.
Ascertaining the Capabilities of the
Computational Device
• In sequential processing, central assumption is that
instructions are executed one after another, one
operation at a time. Accordingly, algorithms designed to
be executed on such machines are called sequential
algorithms.
• The central assumption of the RAM model does not
hold for some newer computers that can execute
operations concurrently, i.e., in parallel. Algorithms that
take advantage of this capability are called parallel
algorithms.
Choosing between Exact and Approximate
Problem Solving
• The next principal decision is to choose between solving the
problem exactly or solving it approximately.
• In the former case, an algorithm is called an exact algorithm;
in the latter case, an algorithm is called an approximation
algorithm.
• Why would one opt for an approximation algorithm? First,
there are important problems that simply cannot be solved
exactly for most of their instances; examples include
extracting square roots, solving nonlinear equations.
• Second, available algorithms for solving a problem exactly
can be unacceptably slow because of the problem’s intrinsic
complexity.
Algorithm Design Techniques
• An algorithm design technique (or “strategy” or
“paradigm”) is a general approach to solving
problems algorithmically that is applicable to a
variety of problems from different areas of
computing.
Designing an Algorithm and Data Structures

• One should pay close attention to choosing data


structures appropriate for the operations performed
by the algorithm.
• For example, phone book in phone would run
longer if we used a linked list instead of Trie
(“retrieval”-a sorted tree) data structure in its
implementation
Proving an Algorithm’s Correctness

• Once an algorithm has been specified, you have to


prove its correctness. That is, you have to prove that the
algorithm yields a required result for every legitimate
input in a finite amount of time.
• For some algorithms, a proof of correctness is quite
easy; for others, it can be quite complex. A common
technique for proving correctness is to use mathemati-
cal induction because an algorithm’s iterations provide
a natural sequence of steps needed for such proofs.
Analyzing an Algorithm

• We usually want our algorithms to possess several


qualities.
• After correctness, by far the most important is
efficiency.
• In fact, there are two kinds of algorithm efficiency:
time efficiency, indicating how fast the algorithm
runs, and space efficiency, indicating how much
extra memory it uses.
Important Problem Types

• Sorting
• Searching
• String processing (e.g. string matching)
• Graph problems (e.g. graph-traversal algorithms)
• Combinatorial problems (e.g. maximizes a cost)
• Geometric problems (e.g. convex-hull problem that
asks to find the smallest convex polygon that would
include all the points of a given set. )
• Numerical problems (e.g. solving equations )
Fundamentals of the Analysis of Algorithm
Efficiency
• Fundamentals of Analysis of Algorithm:

• 1 Analysis of Framework

• 2 Measuring an input size

• 3 Units for measuring runtime

• 4 Worst case, Best case and Average case

• 5 Asymptotic Notations
1. ANALYSIS FRAME WORK

• There are two kinds of efficiency

• ♦ Time efficiency - indicates how fast an algorithm


in question runs.

• ♦ Space efficiency - deals with the extra space the


algorithm requires.
2. MEASURING AN INPUT SIZE

• An algorithm's efficiency as a function of some


parameter n indicating the algorithm's input size.
• In most cases, selecting such a parameter is quite
straightforward.
• For the problem of evaluating a polynomial p(x) =
x^n+ . . . + 0 of degree n, it will be the polynomial's
degree or the number of its coefficients, which is
larger by one than its degree.
2. MEASURING AN INPUT SIZE

• There are situations, of course, where the choice of


a parameter indicating an input size does matter.
• Example - computing the product of two n-by-n
matrices.
• There are two natural measures of size for this
problem.
• The matrix order n. The total number of elements N
in the matrices being multiplied
3 UNITS FOR MEASURING RUN TIME:
• We can simply use some standard unit of time measurement-a
second, a millisecond, and so on-to measure the running time of a
program implementing the algorithm.
• There are obvious drawbacks to such an approach.
They are:
• Dependence on the speed of a particular computer
• Dependence on the quality of a program implementing the
algorithm
• The compiler used in generating the machine code
• The difficulty of clocking the actual running time of the program.
• Since we are in need to measure algorithm efficiency, we should
have a metric that does not depend on these extraneous factors.
4 WORST CASE, BEST CASE AND AVERAGE
CASE EFFICIENCES
• Worst case efficiency
• The worst-case efficiency of an algorithm is its efficiency for the
worst-case input of size n, which is an input (or inputs) of size n
for which the algorithm runs the longest among all possible inputs
of that size.
• Best case Efficiency
• The best-case efficiency of an algorithm is its efficiency for the
best-case input of size n, which is an input (or inputs) of size n for
which the algorithm runs the fastest among all possible inputs of
that size.
• Average case efficiency
• It yields the information about an algorithm about an algorithm‘s
behaviour on a ―typical and ―random input.
5. Asymptotic notations
• Asymptotic notations are the mathematical notations used to describe the
running time of an algorithm when the input tends towards a particular
value or a limiting value.
• For example: In bubble sort, when the input array is already sorted, the
time taken by the algorithm is linear i.e. the best case.
• But, when the input array is in reverse condition, the algorithm takes the
maximum time (quadratic) to sort the elements i.e. the worst case.
• When the input array is neither sorted nor in reverse order, then it takes
average time. These durations are denoted using asymptotic notations.
• There are mainly three asymptotic notations:
• Big-O notation
• Omega notation
• Theta notation
Thank You

You might also like