Analysis of Algorithms

Similar documents
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Introduction to Algorithms Third Edition

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

Contents. 1 Introduction. 2 Searching and Traversal Techniques. Preface... (vii) Acknowledgements... (ix)

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Table of Contents. Chapter 1: Introduction to Data Structures... 1

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Fundamentals of Discrete Mathematical Structures

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

DESIGN AND ANALYSIS OF ALGORITHMS

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

The Algorithm Design Manual

A Programming Approach with C DHARMENDER SINGH KUSHWAHA

Virtual University of Pakistan

COURSE: DATA STRUCTURES USING C & C++ CODE: 05BMCAR17161 CREDITS: 05

Topic Analysis PART-A

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

Lecture 1. Introduction

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

5105 BHARATHIDASAN ENGINEERING COLLEGE

Model Answer. Section A Q.1 - (20 1=10) B.Tech. (Fifth Semester) Examination Analysis and Design of Algorithm (IT3105N) (Information Technology)

L.J. Institute of Engineering & Technology Semester: VIII (2016)

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

Review of course COMP-251B winter 2010

ECE250: Algorithms and Data Structures Final Review Course

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS


Chapter 1 Introduction

( ) 1 B. 1. Suppose f x

CS201 Design and Analysis of Algorithms Max.Marks:75

MICROPROCESSOR 8085 AND ITS INTERFACING SUNIL MATHUR. Second Edition A 1 ALE AD 0 - AD 7. Latch. Keyboard data V CC 8 P A D D 0 7 STB STB G G A

Data Structures and Algorithm Analysis in C++

END-TERM EXAMINATION

R13 SET - 1. ''' '' ''' ' blog: anilkumarprathipati.wordpress.com. Code No: RT32054

( ) n 3. n 2 ( ) D. Ο

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN. Sec. Name Office Office hour Mail id

Chapter 9 Graph Algorithms

DESIGN AND ANALYSIS OF ALGORITHMS

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Department of Information Technology

TOTAL CREDIT UNITS L T P/ S SW/F W. Course Title: Analysis & Design of Algorithm. Course Level: UG Course Code: CSE303 Credit Units: 5

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

COMP 251 Winter 2017 Online quizzes with answers

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

INSTITUTE OF AERONAUTICAL ENGINEERING

CLASSIC DATA STRUCTURES IN JAVA

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

CS521 \ Notes for the Final Exam

Object-Oriented Analysis and Design Using UML

Algorithms and Data Structures

VALLIAMMAI ENGINEERING COLLEGE

CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS

( D. Θ n. ( ) f n ( ) D. Ο%

Acknowledgments I INTRODUCTION 1

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

Overview of Data Structures, Algorithm Analysis

Microcontrollers. Principles and Applications. Ajit Pal +5 V 2K 8. 8 bit dip switch. P2 8 Reset switch Microcontroller AT89S52 100E +5 V. 2.

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

Algorithm Design (8) Graph Algorithms 1/2

Course Review for Finals. Cpt S 223 Fall 2008

About the Author. Dependency Chart. Chapter 1: Logic and Sets 1. Chapter 2: Relations and Functions, Boolean Algebra, and Circuit Design

Chapter 9 Graph Algorithms

COMPUTER GRAPHICS, MULTIMEDIA AND ANIMATION, Second Edition (with CD-ROM) Malay K. Pakhira

Question Paper Code : 97044

Algorithms and Data Structures CS-CO-412

Chapter 9 Graph Algorithms

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

INDEX. Cambridge University Press How to Think About Algorithms Jeff Edmonds Index More information

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

n 2 ( ) ( ) + n is in Θ n logn

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

Ph.D. Written Examination Syllabus

Data Structures and Algorithms

CS 445: Data Structures Final Examination: Study Guide

CSci 231 Final Review

Test points UTA Student ID #

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

CLOUD COMPUTING. M.N. Rao

) $ f ( n) " %( g( n)

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur

SRI VENKATESWARA COLLEGE OF ENGINEERING. COURSE DELIVERY PLAN - THEORY Page 1 of 6

MICROPROCESSOR Architecture, Programming and Interfacing SUNIL MATHUR. Assistant Professor Maharaja Agrasen Institute of Technology Delhi

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

22 Elementary Graph Algorithms. There are two standard ways to represent a

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Lecture 6 Basic Graph Algorithms

Lecture Summary CSC 263H. August 5, 2016

INTERNATIONAL INSTITUTE OF MANAGEMENT, ENGINEERING & TECHNOLOGY, JAIPUR (IIMET)

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Transcription:

Second Edition Design and Analysis of Algorithms Prabhakar Gupta Vineet Agarwal Manish Varshney

Design and Analysis of ALGORITHMS SECOND EDITION PRABHAKAR GUPTA Professor, Computer Science and Engineering Shri Ram Murti Smarak College of Engineering and Technology (SRMSCET) Bareilly VINEET AGARWAL Professor, Computer Science and Engineering Rakshpal Bahadur College of Engineering and Technology Bareilly MANISH VARSHNEY Associate Professor and Head Computer Science and Information Technology Shri Siddhi Vinayak Institute of Technology Bareilly New Delhi-110001 2012

DESIGN AND ANALYSIS OF ALGORITHMS, Second Edition Prabhakar Gupta, Vineet Agarwal, and Manish Varshney 2012 by PHI Learning Private Limited, New Delhi. All rights reserved. No part of this book may be reproduced in any form, by mimeograph or any other means, without permission in writing from the publisher. ISBN-978-81-203-4663-5 The export rights of this book are vested solely with the publisher. Third Printing (Second Edition) September, 2012 Published by Asoke K. Ghosh, PHI Learning Private Limited, M-97, Connaught Circus, New Delhi-110001 and Printed by Meenakshi Art Printers, Delhi-110006.

Contents Preface Preface to the First Edition Acknowledgements xi xiii xv 1. INTRODUCTION TO ALGORITHMS 1 34 1.1 Definition 1 1.2 Expression and Implementation of Algorithms 2 1.3 Characteristics of Algorithms 4 1.4 Analysis of Algorithms 5 1.5 Algorithm Complexity 6 1.5.1 Space Complexity 7 1.5.2 Time Complexity 8 1.6 Determination of Complexities 9 1.7 Cases of Complexity 12 1.8 Importance of Constants during the Analysis of Algorithms 12 1.9 Growth of Functions 13 1.9.1 Asymptotic Notations 13 1.9.2 Types of Asymptotic Notations 14 1.9.3 Summary of Asymptotic Notations 18 1.10 Designing of Algorithms 18 1.10.1 Approaches for Designing Algorithm 19 1.10.2 Difference between Incremental and Divide-and-Conquer Approach 23 1.11 Recurrence Relation 23 1.11.1 Solving Recurrence Relations 24 Summary 32 Exercises 33 iii

iv Contents 2. SORTING AND ORDER STATISTICS 41 88 2.1 Introduction 35 2.2 Insertion Sort 37 2.2.1 Algorithm: The Insertion Sort 39 2.2.2 Code in C Language 41 2.2.3 Complexity of Insert Sort 42 2.2.4 Advantage of Insertion Sort 43 2.2.5 Disadvantage of Insertion Sort 43 2.3 Bubble Sort 43 2.3.1 Procedure: Bubble Sort 44 2.3.2 Code in C Language 44 2.3.3 Complexity of Bubble Sort 45 2.3.4 Advantages of Bubble Sort 46 2.3.5 Disadvantages of Bubble Sort 47 2.4 Selection Sort 47 2.4.1 Procedure: Selection Sort 48 2.4.2 Code in C Language 48 2.4.3 Complexity of Selection Sort 50 2.4.4 Advantages of Selection Sort 50 2.4.5 Disadvantages of Selection Sort 50 2.5 Shell Sort/Diminishing Increment Sort/Comb Sort 51 2.5.1 Procedure: Shell Sort 52 2.5.2 Code in C Language 53 2.5.3 Complexity of Shell Sort 54 2.5.4 Advantages of Shell Sort 54 2.5.5 Disadvantages of Shell Sort 55 2.6 Merge Sort 55 2.6.1 Procedure: Merge Sort 57 2.6.2 Code in C Language 58 2.6.3 Complexity of Merge Sort 60 2.6.4 Different Kinds of Merge Sort 60 2.7 Heap Sort 60 2.7.1 Heap Description 61 2.7.2 Operations on Heap 63 2.7.3 Analysis of Heap Sort 68 2.7.4 Graphical Representation of Heap Sort Algorithm 68 2.7.5 Application of Heaps 69 2.8 Quick Sort 69 2.8.1 Pictorial Representation of Quick Sort 73 2.8.2 Features of Quick Sort Algorithm 74 2.8.3 Analysis of Quick Sort 74 2.8.4 Graphical Representation of Quick Sort Algorithm 77 2.8.5 Implementation of Quick Sort Algorithm in C Language 77

Contents v 2.9 Sorting in Linear Time 78 2.9.1 Counting Sort 79 2.9.2 Radix Sort 80 2.9.3 Bucket Sort 82 2.10 Medians and Order Statistics 84 2.10.1 Selection Problem 85 Summary 86 Exercises 87 3. ELEMENTARY DATA STRUCTURE 89 143 3.1 Stack 89 3.1.1 Operations on a Stack 89 3.1.2 Program to Implement the Push, Pop and Display Function of Stack Using Array 92 3.1.3 Program to Implement the Stack with the Help of Linked List 95 3.2 Queue 97 3.2.1 Operations on a Queue 98 3.2.2 Program to Implement the Queue with the Help of Array 98 3.2.3 Program to Implement the Queue with the Help of Linked List 100 3.3 Linked List 102 3.3.1 Classification of Linked List 103 3.3.2 Applications of Linked Lists 129 3.3.3 Difference between Linked List and Array 129 3.3.4 Difference between Doubly-linked List and Linear-linked List 130 3.4 Binary Tree 130 3.4.1 Types of Binary Trees 131 3.5 Binary Search Tree 131 3.5.1 Operations 132 Summary 141 Exercises 142 4. ADVANCED DATA STRUCTURE 144 221 4.1 Red-Black Tree 144 4.1.1 Properties of Red-Black Tree 144 4.1.2 Graphical Representation of Red-Black Tree 145 4.1.3 Operations on Red-Black Tree 145 4.1.4 Application of Red-Black Tree 169 4.2 AVL Tree 170 4.2.1 Balance Factor 171 4.2.2 Rotations in AVL Tree 172 4.2.3 AVL Tree Operations 174 4.3 Difference between AVL Tree and Red-Black Tree 178

vi Contents 4.4 Augmenting Data Structure 179 4.4.1 Problems Related to Augmented Data Structure 179 4.5 B-Trees 182 4.5.1 Graphical Representation of B-Tree 183 4.5.2 Properties of B-Tree 183 4.5.3 Insertion into a B-Tree 184 4.5.4 Representation of B-Tree in Computer Memory 189 4.5.5 Deletion from B-Tree 189 4.5.6 Searching in a B-Tree 194 4.5.7 Applications of B-Tree 194 4.6 B+ Tree 194 4.6.1 Graphical Representation of B+ Tree 195 4.7 B*-Tree 196 4.8 Binomial Tree 196 4.8.1 Properties of Binomial Tree 197 4.9 Binomial Heap 198 4.9.1 Properties of a Binomial Heap 198 4.9.2 Operations of a Binomial Heap 199 4.9.3 Explanation of Binomial-Heap-Union Operation 205 4.10 Fibonacci Heap 207 4.10.1 Representation of a Fibonacci Heap 208 4.10.2 Properties of Fibonacci Heap 209 4.10.3 Operations of a Fibonacci Heap 209 4.10.4 Algorithm for FIB-HEAP-DELETE 215 4.10.5 Graphical Representation of All Operations 216 4.11 Disjoint Set Data Structure 216 4.11.1 Operations of Disjoint Set 217 4.11.2 Applications of Disjoint Set Data Structures 218 4.11.3 The Disjoint Set Representation 219 Summary 219 Exercises 220 5. DIVIDE AND CONQUER 222 234 5.1 Introduction 222 5.2 General Issues in Divide and Conquer 222 5.3 Sorting 223 5.3.1 Merge Sort 223 5.3.2 Quick Sort 226 5.3.3 Randomization Quick Sort 228 5.4 Matrix Multiplication 229 5.5 Binary Search 231 5.6 Convex Hull 232 5.6.1 Divide and Conquer Approach 232 Summary 233 Exercises 234

Contents vii 6. ADVANCED DESIGN AND ANALYSIS TECHNIQUES PART I 235 267 6.1 Dynamic Programming 235 6.1.1 Definition 235 6.2 Approaches of Dynamic Programming 236 6.3 Application of Dynamic Programming 236 6.4 Steps Involved in the Implementation of Dynamic Programming 236 6.5 Elements of Dynamic Programming 248 6.6 Greedy Algorithms 250 6.6.1 Functions of Greedy Algorithms 251 6.6.2 Structure of Greedy Algorithm 251 6.6.3 Properties of Greedy Algorithm 251 6.7 Problems Solved by Greedy Approach 252 Summary 265 Exercises 266 7. ADVANCED DESIGN AND ANALYSIS TECHNIQUES PART II 268 287 7.1 Amortized Analysis 268 7.1.1 Aggregate Method 268 7.1.2 Accounting Method 270 7.1.3 Potential Method 272 7.2 Backtracking 276 7.3 General Method for Backtracking 276 7.4 Queens Problem for Backtracking 277 7.5 n-queens Problem 278 7.6 Sum of Subsets Problem for Backtracking 281 7.7 Graph Colouring Problem for Backtracking 283 7.8 Hamiltonian Cycles for Backtracking 284 7.9 Zero-n Knapsack Problem 285 Summary 286 Exercises 287 8. GRAPH 288 345 8.1 Graph 288 8.1.1 Representation of Graph 288 8.1.2 Program for Addition and Deletion of Nodes and Edges in a Graph Using Adjacency Matrix 290 8.1.3 Program for Creation of Adjacency Matrix 293 8.2 Graph Traversal 294 8.2.1 Breadth-First Search 295 8.2.2 Depth-First Search 300 8.3 Topological Sort 303 8.4 Strongly-Connected Components 304

viii Contents 8.5 Minimum Spanning Tree 306 8.5.1 Kruskal s Algorithm 307 8.5.2 Prim s Algorithm 310 8.6 Shortest Path Algorithms 312 8.6.1 Single-Source Shortest Path 313 8.6.2 Dijkstra s Algorithm 314 8.6.3 Bellman-Ford Algorithm 318 8.7 All-Pairs-Shortest-Path Problem 322 8.7.1 Optimum Matrix Multiplication or Shortest Path and Matrix Multiplication 322 8.7.2 Floyd-Warshall Algorithm 324 8.8 Sparse Graphs 328 8.8.1 Johnson s Algorithm 330 8.9 Maximum Flow 332 8.9.1 Ford-Fulkerson Algorithm 332 8.10 Travelling Salesman Problem 334 8.10.1 Improved Greedy Solutions 335 8.10.2 Branch-and-Bound Solution 338 8.10.3 Alternative Approaches 344 Summary 345 Exercises 345 9. PATTERN MATCHING ALGORITHMS 346 367 9.1 Randomized Algorithms 346 9.2 Motivation of Randomized Algorithms 347 9.3 Complexity 348 9.4 Applications of Randomized Algorithm 349 9.5 Derandomization 349 9.6 Advantages of Randomized Algorithm 349 9.7 String-Matching 350 9.8 String-Matching Algorithm 351 Summary 366 Exercises 366 10. NP-COMPLETENESS 368 389 10.1 NP-Complete 368 10.2 Importance of NP-Completeness 369 10.3 Polynomial Time 370 10.4 The Classes P and NP 371 10.5 Example of NP-Complete Problems 372 10.6 NP-Hard 384 10.7 Difference between NP-Hard and NP-Complete 385

Contents ix 10.8 Approximation Algorithm 385 10.8.1 Approximating Vertex Cover 388 Summary 389 Exercises 389 GLOSSARY 391 401 REFERENCES 403 INDEX 405 408

Design And Analysis Of Algorithms 25% OFF Publisher : PHI Learning ISBN : 9788120346635 Author : Gupta And Prabhakar Type the URL : http://www.kopykitab.com/product/7779 Get this ebook