i SYLLABUS UNIT - I CHAPTER - 1 : INTRODUCTION TO ALGORITHMS AND ELEMENTARY DATA A STRUCTURES Order Notation, Analysis of Algorithm, Review of Elementary Data Structures, Heaps and Heap Sort, Hashing, Sets Representation, UNION, FIND. UNIT - II CHAPTER - 2 : DIVIDE AND CONQUER The General Method, Binary Search, Finding Maximum Minimum, Merge Sort, Quick Sort and Selection. CHAPTER - 3 : GREEDY METHOD Knapsack Problem, Optimal Storage on Tapes, Job Sequencing With Deadlines, Optimal Merge Pattern, Minimum Spanning Trees and Single Source Shortest Paths. UNIT - III CHAPTER - 4 : DYNAMIC PROGRAMMING AND TRAVERSAL TECHNIQUES Multistage Graphs, All Pairs Shortest Paths, Optimal Binary Search Trees, 0/1 Knapsack, Reliability Design Traveling Salesman Problem, Bi Connected Components and Depth First Search. UNIT - IV CHAPTER - 5 : BACKTRACKING 8 Queens Problem, Graph Colouring, Hamiltonian Cycles, Knapsack Problem. CHAPTER - 6 : BRANCH AND BOUND 0/1 Knapsack Problem, Travelling Salesperson Problem, Lower Bound Theory. UNIT - V CHAPTER - 7 : NP HARD AND NP COMPLETE PROBLEMS Basic Concepts, Cook s Theorem, NP Hard Graph Problems and Scheduling Problem, NP Hard Code Generation Problems, Decision Problem, Node Covering Problem.
ii Contents design and analysis of algorithms FOR b.e. (o.u) Iii/I & Iii/iI semester (COMMON TO CSE AND IT) CONTENTS UNIT - I [CH. H. - 1] ] [INTRODUCTION TO ALGORITHMS AND ELEMENTARY DATA STRUCTURES]... 1.1-1.80 1.1 INTRODUCTION TO O ALGORITHM... 1.2 1.1.1 Definition of Algorithm... 1.2 1.1.2 Notation of Algorithm... 1.2 1.1.3 Properties of Algorithm... 1.3 1.1.4 Process for Design and Analysis of Algorithms... 1.4 1.1.4.1 Understanding the Problem... 1.4 1.1.4.2 Develop Problem Solving Technique echnique... 1.4 1.1.4.3 Design of an Algorithm... 1.5 1.1.4.4 Validation of an Algorithm... 1.5 1.1.4.5 Analyze the Algorithm... 1.5 1.1.4.6 Coding of an Algorithm... 1.6 1.1.4.7 Testing of an Algorithm... 1.6 1.1.5 PSUEDO Code for Expressing Algorithms... 1.7 1.2 ANALYSIS OF ALGORITHM REVIEW / PERFORMANCE ANALYSIS... 1.14 1.2.1 Space Complexity... 1.17 1.2.2 Time Complexity... 1.19 1.2.2.1 The Unit of Algorithm s Runun-Time... 1.19 1.2.2.2 The Order of Growth... 1.20
iii 1.2.2.3 Best Case, Average Case and Worst Case Efficiencies... 1.22 1.2.2.4 Solved Problems... 1.23 1.2.3 Comparison Between Priori Analysis and Posteriori Analysis... 1.26 1.3 ORDER NOTATION TION / ASYMPTOTIC TIC NOTATION TION... 1.26 1.3.1 Big Oh (O) Notation... 1.27 1.3.1.1 Big-Oh Ratio Theorem... 1.28 1.3.1.2 Basic Efficiency Classes... 1.30 1.3.2 Omega (Ω) ) Notation... 1.32 1.3.2.1 Big Omega Ratio Theorem... 1.33 1.3.2.2 Little-Omega Notation (ω)... 1.33 1.3.3 Theta (θ) ) Notation... 1.34 1.3.3.1 Theta Ratio Theorem... 1.34 1.3.4 Small oh (o) Notation... 1.35 1.3.5 Order of Growth Using Limits (Alternative Definitions for Asymptotic Notations)... 1.36 1.4 ELEMENTAR ARY Y DATA A STRUCTURES... 1.39 1.4.1 Priority Queues... 1.39 1.4.2 Heaps... 1.40 1.4.3 Heap Sort... 1.45 1.5 HASHING... 1.53 1.6 SETS REPRESENTATION TION... 1.53 1.6.1 Introduction to Sets... 1.53 1.6.2 Standard Representation of Sets... 1.54 1.6.3 Cardinality of Set... 1.54 1.6.4 Types of Sets... 1.54
iv Contents 1.6.5 Operations on Sets... 1.57 1.6.5.1 Union of Two sets... 1.57 1.6.5.2 Union of More than Two Sets... 1.57 1.6.5.3 Intersection of Two Sets... 1.57 1.6.5.3.1 Intersection of More Than Two Sets... 1.57 1.6.5.4 Complement of a Set... 1.57 1.6.5.4.1 Difference (or) Relative Complement of Sets... 1.58 1.6.5.4.2 Symmetric Difference of Sets... 1.58 1.6.6 Laws of Set Theory... 1.58 1.7 DISJOINT SETS... 1.59 1.7.1 Disjoint Set Operations... 1.60 1.8 UNION AND FIND... 1.61 1.8.1 UNION Operation... 1.61 1.8.2 FIND Operation... 1.62 1.8.3 Weighting Rule ule for UNION (i, j)... 1.64 1.8.4 Collapsing Rule for Find (i)... 1.65 1.9 TREES... 1.67 1.9.1 Tree ree Traversals... 1.67 1.9.1.1 Preorder Traversal raversal... 1.67 1.9.1.2 Inorder Traversal raversal... 1.68 1.9.1.3 Postorder Traversal... 1.69 1.10 GRAPHS AND ITS REPRESENTATION TION... 1.70 1.10.1 Basic Definitions... 1.70 1.10.2 Graph Traversals raversals... 1.73 1.10.2.1 Breadth First Search (BFS)... 1.73 1.10.2.2 Depth First Search (DFS) and Traversal (DFT)... 1.76 Expected University Questions with Solutions... 1.79-1.80
v UNIT - II [CH. H. - 2] ] [DIVIDE AND CONQUER]... 2.1-2.36 2.1 INTRODUCTION TO DIVIDE AND CONQUER... 2.2 2.1.1 Advantages of Divide and Conquer Approach... 2.2 2.2 GENERAL METHOD... 2.3 2.2.1 Control Abstraction For Divide and Conquer... 2.4 2.2.2 Methods for Solving Recurrence Relations... 2.5 2.2.2.1 Iterative Substitution Method... 2.5 2.2.2.1.1 Solved Problems... 2.6 2.2.2.2 The Master Theorem... 2.8 2.2.2.2.1 Solved Problems... 2.8 2.3 BINARY SEARCH... 2.9 2.3.1 Time Complexity of Algorithm... 2.11 2.3.2 Modified Binary Search Algorithm... 2.12 2.4 FINDING MAXIMUM AND MINIMUM... 2.13 2.4.1 Conventional Method for Maximum and Minimum... 2.13 2.4.2 Divide and Conquer Method for Maximum and Minimum... 2.14 2.5 MERGE SORT... 2.17 2.5.1 Time Complexity of an Algorithm... 2.21 2.5.2 Space Complexity of an Algorithm... 2.22 2.6 QUICK SORT... 2.22 2.6.1 Time Complexity of an Algorithm... 2.26 2.6.2 Randomized Quick Sort... 2.29 2.7 SELECTION SORT... 2.30 2.8 STRASSEN S MATRIX MULTIPLICA TIPLICATION TION... 2.31 2.8.1 Strassen s Algorithm... 2.33 Expected University Questions with Solutions... 2.35-2.36
vi Contents UNIT - II [CH. H. - 3] ] [GREEDY METHOD]... 2.37-2.84 3.1 INTRODUCTION TO GREEDY METHOD... 2.38 3.1.1 Divide and Conquer Approach Vs Greedy Approach... 2.39 3.2 GREEDY METHOD... 2.40 3.2.1 Control Abstraction of Greedy Method... 2.41 3.3 KNAPSACK PROBLEM... 2.43 3.3.1 Time Complexity of the Algorithm... 2.44 3.3.2 Solved Problems... 2.44 3.4 OPTIMAL STORA ORAGE ON TAPES... 2.49 3.5 JOB SEQUENCING WITH DEADLINES... 2.52 3.5.1 Time Complexity of the Algorithm... 2.52 3.5.2 Solved Problems... 2.53 3.6 OPTIMAL MERGE PATTERN... 2.56 3.6.1 Huffman Codes... 2.62 3.7 MINIMUM COST SPANNING TREES... 2.65 3.7.1 Prim rim s s Algorithm... 2.67 3.7.2 Kruskal s Algorithm... 2.70 3.7.3 Solved Problems... 2.74 3.8 SINGLE SOURCE SHORTEST PATHS... 2.80 3.8.1 Solved Problems... 2.82 Expected University Questions with Solutions... 2.84 UNIT - III [CH. - 4] ] [DYNAMIC PROGRAMMING AND TRAVERSAL TECHNIQUES]... 3.1-3.64 4.1 INTRODUCTION TO O DYNAMIC PROGRAMMING... 3.2 4.1.1 Key Elements of Dynamic Programming... 3.2 4.1.2 Principle of Optimality... 3.3 4.1.3 Comparison Between Dynamic Programming and Greedy Method... 3.4 4.1.4 Comparison Between Dynamic Programming and Divide and Conquer... 3.5
vii 4.2 GENERAL METHOD... 3.5 4.2.1 General Characteristics of Dynamic Programming... 3.6 4.3 MULTIST TISTAGE GRAPHS... 3.6 4.4 ALL PAIRS SHORTEST PATHS THS... 3.12 4.4.1 Time Complexity of the Algorithm... 3.12 4.4.2 Solved Problem... 3.13 4.5 OPTIMAL BINARY SEARCH TREES... 3.15 4.5.1 Time Complexity of the Algorithm... 3.17 4.5.2 Solved Problems... 3.18 4.6 0/1 KNAPSACK... 3.27 4.6.1 Time Complexity of the Algorithm... 3.28 4.6.2 Solved Problem... 3.29 4.7 RELIABILITY DESIGN... 3.31 4.7.1 Solved Problem... 3.32 4.8 TRAVELING SALESPERSON PROBLEM... 3.37 4.8.1 Solved Problems... 3.41 4.9 CONNECTED COMPONENTS... 3.46 4.10 BICONNECTED COMPONENTS AND DFS... 3.48 4.10.1 Articulation Point... 3.48 4.10.2 Problem of Identifying the Articulation points and Biconnected Components... 3.51 4.10.3 Depth First Spanning Tree Properties roperties... 3.53 4.10.4 Algorithm to Find DFN s and L Values... 3.55 4.10.5 Algorithm to Find BiConnected Components... 3.58 4.10.6 Depth First Search (DFS) and Traversal (DFT)... 3.60 Expected University Questions with Solutions... 3.63-3.64
viii Contents UNIT - IV [CH. H. - 5] ] [BACKTRACKING BACKTRACKING]... 4.1-4.42 5.1 INTRODUCTION TO BACK CKTRA TRACKING... 4.2 5.1.1 Constraints for Backtracking... 4.6 5.1.2 Comparison Between Backtracking and Brute Force Approach... 4.7 5.2 GENERAL METHOD... 4.7 5.2.1 Estimating the Efficiency of Backtracking... 4.9 5.3 N QUEENS PROBLEM (4 QUEENS AND 8 QUEENS PROBLEM)... 4.11 5.3.1 4 Queens Problem... 4.12 5.3.2 8 Queens Problem... 4.15 5.4 GRAPH COLORING PROBLEM... 4.15 5.4.1 Algorithm for M Coloring Graph... 4.18 5.4.1.1 Analysis of the M coloring Algorithm... 4.22 5.5 HAMILTONIAN CYCLES CLES... 4.22 5.5.1 Solved Problem... 4.28 5.6 KNAPSACK PROBLEM... 4.31 5.6.1 Solved Problems... 4.33 Expected University Questions with Solutions... 4.42 UNIT - IV [CH. - 6] ] [BRANCH AND BOUND]... 4.43-4.90 6.1 INTRODUCTION TO O BRANCH AND BOUND METHOD... 4.44 6.1.1 Comparison Between Backtracking and Branch and Bound... 4.44 6.2 GENERAL METHOD... 4.45 6.2.1 LC (Least Cost) Search... 4.45 6.2.1.1 Control Abstraction for LC Search... 4.47 6.2.1.2 Properties of LC Search... 4.49 6.2.1.3 Example : The 15-Puzzle Problem... 4.49
ix 6.2.2 Bounding... 4.50 6.2.3 FIFO Branch and Bound... 4.54 6.2.4 LIFO Branch and Bound... 4.54 6.3 0/1 KNAPSACK PROBLEM... 4.55 6.3.1 Using LC Branch and Bound Solution... 4.55 6.3.1.1 Solved Problem... 4.56 6.3.2 FIFO Branch and Bound Solution... 4.61 6.3.2.1 Solved Problems... 4.64 6.4 TRAVELLING SALESPERSON PROBLEM... 4.71 6.4.1 Solved Problems... 4.72 6.5 LOWER BOUND THEORY... 4.85 6.5.1 Comparison Trees rees... 4.86 6.5.1.1 Ordered Searching... 4.86 6.5.1.2 Sorting... 4.87 6.5.1.3 Selection... 4.88 Expected University Questions with Solutions... 4.89-4.90 UNIT - V [CH. - 7] ] [NP HARD AND NP COMPLETE PROBLEMS]... 5.1-5.34 7.1 BASIC CONCEPTS... 5.2 7.2 NON DETERMINISTIC ALGORITHMS... 5.3 7.2.1 Non-Deterministic Algorithm for Searching... 5.4 7.2.2 Non-Deterministic Algorithm for Sorting... 5.5 7.2.3 Decision Problem and Optimization Problem... 5.6 7.2.4 Satisfiability... 5.9 7.3 NP-HARD AND NP-COMPLETE CLASSES... 5.10 7.3.1 The Complexities of NP-Hard and NP-Complete... 5.12 7.3.2 Relationship Between P and NP Problems... 5.12
x Contents 7.3.3 Relationship Between NP Hard and NP Complete Problems... 5.13 7.3.4 Halting Problem... 5.13 7.4 COOK S THEOREM... 5.14 7.5 NP HARD GRAPH PROBLEMS... 5.15 7.5.1 Clique Decision Problem (CDP)... 5.16 7.5.2 Node Cover Decision Problem (NCDP)... 5.17 7.5.3 Chromatic Number Decision Problem (CNDP)... 5.18 7.5.4 Directed Hamiltonian Cycle... 5.20 7.5.5 Travelling Salesperson Decision Problem (TSP)... 5.24 7.5.6 AND/OR Graph Decision Problem (AOG)... 5.24 7.6 NP HARD SCHEDULING PROBLEMS... 5.25 7.6.1 Scheduling Identical Processors... 5.25 7.6.2 Flow Shop Scheduling... 5.26 7.6.3 Job Shop Scheduling... 5.28 7.7 NP HARD CODE GENERATION... 5.29 7.7.1 Code Generation With Common Subexpressions... 5.29 7.7.2 Implementing Parallel Assignment Instructions... 5.30 7.8 SOME SIMPLIFIED NP HARD PROBLEMS... 5.32 Expected University Questions with Solutions... 5.33-5.34 PREVIOUS UNIVERSITY QUESTION PAPERS [April/May - 2013] [Main]... QP.1.1 - QP.2.2 [May/June - 2011] [Main]... QP.3.3 - QP.4.4 [June - 2011] [Supplementary]... QP.5.5 - QP.6.6 [June - 2010] [Main]... QP.7.7 - QP.8.8 [December - 2009] [Supplementary]...QP QP.9.9 - QP.10
xi [April/May - 2009] [Main]... QP.11 - QP.12 [April/May - 2008] [Main]... QP.13 - QP.14 [December - 2008] [Supplementary]... QP.15 - QP.16