You are on page 1of 10

Algorithms

(CS3401 – Algorithms)

As per the Latest Syllabus of Anna University, Chennai

(Regulation 2021)

Dr. S. Nithyanantham,

Assistant Professor,
School of Engineering,
Computer Science and Engineering,
Presidency University,
Bangalore.

Mrs. R. Shalini, B.E., M.E., (Ph.D.),

Research scholar,
National Institute of Technology,
Tirchy.

Mr. K. Sriram Kumar, B.E., M.E., (Ph.D.),


Assistant Professor,
Department of Information Technology,
Karpagam Institute of Technology,
Coimbatore

Mr. P. Krishna Sankar, B.E., M.E.,

Freelance Entrepreneur / Consultant,


Kavindapadi

A.R.S. Publications
No. 11, Veerabathra Nagar, Part II,
8th Street, Medavakkam,
Chennai – 600 100, Tamil Nadu, India.
Phone: 044 – 48587467, Mobile: 9840025186
eMail: arspublications@gmail.com
web: www.arspublications.com
PREFACE
This book “Algorithms” is about analysis of algorithm and its complexity techniques. It helps to
analyse the efficiency of various graph traversal algorithms. It provides the ability to solve various
problems using linear and state space tree approach. It gives an understanding towards various classes of
problems in polynomial and non-polynomial approaches.

Unit I: Introduction towards algorithm analysis with time and space complexities. It provides an
understanding towards asymptotic notations. Contributes a knowledge on several search
and sort algorithms with its efficiency notation.
Unit II: Outline on representing and traversing on graphs. It provides the practical approach
towards the construction of minimum spanning tree and shortest path detection along
with network flow.
Unit III: Transitory awareness on divide and conquer methodology adapted to perform merge and
quick sort. Provides a procedure to perform dynamic programming on matrix-
multiplication, multi-stage graph and optimal binary search trees. Able to understand the
greedy approach and its applicability on problem solving techniques.
Unit IV: Brief knowledge over state space tree approach on the backtracking and branch and
bound techniques. It provides detailed procedures for solving problems n-Queens,
Hamiltonian, Subset sum, Graph colouring, 15-Puzzle, Assignment, Knapsack and
Travelling salesman.
Unit V: Provides a study over tractable and intractable problems with bin packing problem.
Understanding towards problem reduction, approximation and randomized algorithms
with travelling salesman.
ACKNOWLEDGEMENT

Primarily, we would like to thank God. In the process of putting this book together, we realized
how true this gift of writing is for us to share our knowledge. You give us the power to believe in our
passion and pursue our dreams. We could never have done this without the faith we have in you, the
Almighty.

We wholeheartedly thank next God, thy Parents, for showing faith with us and giving us
liberty to choose what we desire. We salute you all for the selfless love, care, pain and sacrifice you did to
shape our life.

We sincerely thank our Colleagues, Friends and Well-wishers for their understanding, patience in
addition, constant encouragement.

Finally, we offer our special thanks to Thiru. A. Ramesh, A. R. S. Publishers and his Colleagues for
their tireless effort in overseeing the production of the book.

The authors would be happy to collect opinion for supplementary improvement of the book.

Dr. S. Nithyanantham
Mrs. R. Shalini
K. Sriram Kumar
Mr. P. Krishna Sankar
CS3401 ALGORITHMS LTPC
3024

UNIT I INTRODUCTION 9
Algorithm analysis: Time and space complexity - Asymptotic Notations and its properties Best
case, Worst case and average case analysis – Recurrence relation: substitution method - Lower
bounds – searching: linear search, binary search and Interpolation Search, Pattern search: The
naïve string matching algorithm - Rabin-Karp algorithm - Knuth-Morris-Pratt algorithm. Sorting:
Insertion sort – heap sort.

UNIT II GRAPH ALGORITHMS 9


Graph algorithms: Representations of graphs - Graph traversal: DFS – BFS - applications -
Connectivity, strong connectivity, bi-connectivity - Minimum spanning tree: Kruskal’s and Prim’s
algorithm- Shortest path: Bellman-Ford algorithm - Dijkstra’s algorithm - Floyd-Warshall algorithm
Network flow: Flow networks - Ford-Fulkerson method – Matching: Maximum bipartite matching.

UNIT III ALGORITHM DESIGN TECHNIQUES 9


Divide and Conquer methodology: Finding maximum and minimum - Merge sort - Quick sort
Dynamic programming: Elements of dynamic programming — Matrix-chain multiplication - Multi
stage graph - Optimal Binary Search Trees. Greedy Technique: Elements of the greedy strategy
- Activity - selection problem –- Optimal Merge pattern - Huffman Trees.

UNIT IV STATE SPACE SEARCH ALGORITHMS 9


Backtracking: n-Queens problem - Hamiltonian Circuit Problem - Subset Sum Problem – Graph
colouring problem Branch and Bound: Solving 15-Puzzle problem - Assignment problem –
Knapsack Problem - Travelling Salesman Problem.

UNIT V NP-COMPLETE AND APPROXIMATION ALGORITHM 9


Tractable and intractable problems: Polynomial time algorithms – Venn diagram representation -
NPalgorithms - NP-hardness and NP-completeness – Bin Packing problem - Problem reduction:
TSP – 3-CNF problem. Approximation Algorithms: TSP - Randomized Algorithms: concept
and application - primality testing - randomized quick sort - Finding kth smallest number.
CONTENTS
UNIT I

INTRODUCTION
1.1 Algorithm analysis 2

1.1.1 Analysis Framework 2


1.1.2 Time and space complexity 5

1.1.3 Asymptotic Notations and their properties 6

1.1.4 Worst-Case, Best-Case, and Average-Case Efficiencies 12

1.2 Recurrence relation 13

1.2.1 Substitution method 14

1.2.2 Lower bounds 15

1.3 Searching 16

1.3.1 Linear search 16

1.3.2 Binary search 17

1.3.3 Interpolation Search 19


1.4 Pattern search 22

1.4.1 Naïve string-matching algorithm 23


1.4.2 Rabin-Karp algorithm 25

1.4.3 Knuth-Morris-Pratt algorithm 28

1.5 Sorting 34

1.5.1 Insertion sort 35

1.5.2 Heap sort 38

UNIT – II
GRAPH ALGORITHMS

2.1 Representation of Graphs 2

2.1.1 Adjacency Matrix 2

2.1.2 Adjacency Lists 4


2.1.3 Incidence Matrix 6
2.1.4 Adjacency multi-lists 7

2.2 Graph Traversal 8


2.2.1 Depth-First Search 8

2.2.2 Breadth-First Search 9

2.2.3 Applications of graph traversal 10

2.3 Connectivity 13

2.3.1 Cut Vertex 14

2.3.2 Cut Edge (Bridge) 16

2.3.3 Cut Set 17

2.3.4 Edge Connectivity 18


2.3.5 Vertex Connectivity 19

2.3.6 Strong Connectivity 20


2.3.7 Bi-Connectivity 21

2.4 Minimum Spanning Tree 22


2.4.1 Kruskal’s algorithm 22

2.4.2 Prim’s algorithm 26

2.4.3 Difference between Prims and Kruskal Algorithm 30

2.5 Shortest path 31

2.5.1 Bellman-Ford algorithm 31


2.5.2 Dijkstra’s algorithm 34

2.5.3 Floyd warshall algorithm 40

2.6 Network Flow 43

2.6.1 Flow networks 44

2.6.2 Ford-Fulkerson method 45

2.7 Matching 49

2.7.1 Maximum Bipartite Matching 50

2.7.2 Finding a maximum bipartite matching 51


UNIT – III
Algorithm Design Techniques

3.1 Divide and Conquer Methodology 2


3.1.1 Finding maximum and minimum 2

3.1.2 Merge sort 3

3.1.3 Quick Sort 5

3.2 Dynamic Programming 7

3.2.1 Elements of dynamic programming 7

3.2.2 Matrix-chain multiplication 9

3.2.3 Multi-stage graph 11

3.2.4 Optimal Binary Search Trees 16


3.3 Greedy Techniques 18

3.3.1 Elements of greedy strategy 18


3.3.2 Activity Selection problem 19

3.3.3 Optimal merge pattern 22


3.3.4 Huffman Trees 26

UNIT IV

STATE SPACE SEARCH ALGORITHMS

4.1 Backtracking 2
4.1.1 n-Queen problem 3

4.1.2 Hamiltonian Circuit Problem 5

4.1.3 Subset Sum Problem 7

4.1.4 Graph colouring problem 8

4.2 Branch and Bound 11

4.2.1 LIFO Search and FIFO search 12

4.2.2 Solving 15-Puzzle problem 14

4.2.3 Assignment problem 17

4.2.4 Knapsack Problem 21


4.2.5 Travelling Salesman Problem 23

UNIT V
NP-COMPLETE AND APPROXIMATION ALGORITHM

5.1 Tractable and intractable problems 2

5.1.1 Polynomial time algorithms 3

5.1.2 NP algorithms 4

5.1.3 Venn diagram representation 6

5.1.4 NP-hardness and NP-completeness 7

5.1.5 Bin Packing problem 8

5.2 Problem reduction 9


5.2.1 TSP 10

5.2.2 3-CNF problem 11


5.3 Approximation Algorithms 11

5.3.1 TSP 13
5.4 Randomized Algorithms 21

5.4.1 Concept and application 21

5.4.2 Primality testing 22

5.4.3 Randomized quick sort 23

5.4.4 Finding kth smallest number 25

You might also like