Lecture 1 DAA
Lecture 1 DAA
of Algorithms
Lecture 1 & 2
Textbook
Introduction to Algorithms 3rd , Thomas H. Corman
Others
Introduction to The Design and Analysis of Algorithms 3rd Edition, Anany
Levitin
Course Objectives
Algorithms are the core subject in computer science when it comes to problem solving
by computers.
The main objective of this undergraduate level course is to introduce students to the
crux of algorithm design, evaluation and implementation.
Famous computer science problems will be discussed and various approaches to the
solution would be compared.
Why study this subject?
Efficient algorithms lead to efficient programs.
Efficient programs sell better
Efficient programs make better use of hardware.
Programmers who write efficient programs are more marketable than those who don’t!
Factors influencing program
efficiency
Problem being solved
Programming language
Compiler
Computer hardware
Programmer ability
Programmer effectiveness
Algorithm
This course
About performance!
Because, performance is the line between feasible and unfeasible.
o E.g. if not fast enough, can not be adopted (fast web search)
Static data structures are those whose Dynamic structures are those which
sizes and structures associated memory expands or shrinks depending upon the
locations are fixed, at compile time. program need and its execution. Also, their
associated memory locations changes.
By Storage
Primitive Data Structure Non-Primitive Data Structure
Primitive Data Structures are the basic data Non-primitive data structures are more
structures that directly operate upon complicated data structures and are derived
the machine instructions. from primitive data structures.
They emphasize on grouping same or
different data items with relationship between
each data item.
By Nature
Homogeneous Data Structure Heterogeneous Data Structure
In Linear data structures, the data items are arranged in a linear Hierarchal Access
sequence A hierarchical collection is a group of items divided into levels. An item at
one level can have successor items located at the next lower level. One
Sequential Access common hierarchical collection is the tree.
Example:
If there is a lock of 4-digit PIN. The digits to be chosen from 0-9 then the brute force will
be trying all possible combinations one by one like 0001, 0002, 0003, 0004, and so on
until we get the right PIN. In the worst case, it will take 10,000 tries to find the right
combination.
Recursive Algorithm
This type of algorithm is based on recursion. In recursion, a problem is solved by
breaking it into subproblems of the same type and calling own self again and
again until the problem is solved with the help of a base condition.
Some common problem that is solved using recursive algorithms are Factorial of
a Number, Fibonacci Series, Tower of Hanoi, DFS for Graph, etc.
Divide and Conquer Algorithm
In Divide and Conquer algorithms, the idea is to solve the problem in two
sections, the first section divides the problem into subproblems of the same
type. The second section is to solve the smaller problem independently and
then add the combined result to produce the final answer to the problem.
Some common problem that is solved using Divide and Conquers Algorithms are
Binary Search, Merge Sort, Quick Sort, Strassen’s Matrix Multiplication, etc.
Dynamic Programming Algorithms
This type of algorithm is also known as the memoization technique because in
this the idea is to store the previously calculated result to avoid calculating it
again and again. In Dynamic Programming, divide the complex problem into
smaller overlapping subproblems and store the result for future use.
Some common problems that can be solved through the Greedy Algorithm are
Dijkstra Shortest Path Algorithm, Prim’s Algorithm, Kruskal’s Algorithm, Huffman
Coding, etc.
Backtracking Algorithm
In Backtracking Algorithm, the problem is solved in an incremental way i.e. it is
an algorithmic technique for solving problems recursively by trying to build a
solution incrementally, one piece at a time, removing those solutions that fail to
satisfy the constraints of the problem at any point of time.
Some common problems that can be solved through the Backtracking Algorithm
are the Hamiltonian Cycle, M-Coloring Problem, N Queen Problem, Rat in Maze
Problem, etc.
Randomized Algorithm
In the randomized algorithm, we use a random number.it helps to decide the
expected outcome. The decision to choose the random number so it gives the
immediate benefit
Some common problems that can be solved through the Randomized Algorithm
are Quicksort: In Quicksort we use the random number for selecting the pivot.
Algorithm Specifications
Every algorithm must satisfy the following specifications...
Input - There should be 0 or more inputs supplied
externally to the algorithm.
Output - There should be at least 1 output obtained.
Definiteness - Every step of the algorithm should be
clear and well defined.
Finiteness - The algorithm should have finite number of
steps.
Correctness - Every step of the algorithm must
generate a correct output.
Algorithm Efficiency
An algorithm is said to be efficient and fast, if it
takes less time to execute and consumes less
memory space.
Performance Analysis
Performance analysis of an algorithm is the process of
calculating space required by that algorithm and time
required by that algorithm.
The performance of an algorithm is measured on the basis of
following properties: