SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Analysis and Design of Algorithms
Deepak John
Department Of Computer Applications, SJCET-Pala
Types of ProblemsTypes of Problems
 Optimization problem: construct a solution that
maximizes or minimizes some objective functionmaximizes or minimizes some objective function
 Decision problem: A question that has two possible
answers, yes and no.
Examples:
•SHORTEST-PATH (optimization)
Given G, u,v, find a path from u to v with fewest edges.
•PATH (decision)
Given G, u,v, and k, whether exist a path from u to vGiven G, u,v, and k, whether exist a path from u to v
consisting of at most k edges.
The class PThe class P
 P is the set of decision problems that can be solved in polynomial
time .if the size of the input to the problem is n then the problemp p p
can be solved in time O(nk) for some constant k.
 Polynomially bounded
an algorithm is said to be polynomilly bounded if its worst case
complexity is bounded by a polynomial function of the input
i (if th i l i l h th t f h i t f isize(if there is a polynomial p such that for each input of size n
the algorithm terminates after at most p(n)steps)
 P: Polynomial algorithms - These include all the sorting P: Polynomial algorithms These include all the sorting
algorithms, with running times on the order of n, lg n,n lg n and n2.
Class NPClass NP
 Class NP: Problems that can be solved in a polynomial number
of steps by a nondeterministic polynomial algorithms.of steps by a nondeterministic polynomial algorithms.
 A nondeterministic algorithm: a two-stage procedure that takes
as its input an instance I of a decision problem and does the
following
1. “guessing” stage: An arbitrary string S is generated that can
b h h f l i f h i ibe thought of as a guess at a solution for the given instance
2. “verification” stage: A deterministic algorithm takes both I
and S as its input and check if S is a solution to instance Iand S as its input and check if S is a solution to instance I,
(outputs yes if s is a solution and outputs no or not halt at all
otherwise)
NP-CompleateNP Compleate
 is the class of problems that are the hardest problems in NP.
 example: example:
A hamiltonian cycle of an undirected graph is a simple
cycle that contains every vertex
The Relationship between P ,NP and NPC
Approximation algorithmsApproximation algorithms
 an algorithm which return solutions that are guaranteed to
be close to an optimal solution.be close to an optimal solution.
 We use performance ratio to measure the quality of an
approximation algorithm.
 We are going to find a Near-Optimal solution for a given
problem.
 We assume two hypothesis :
1. Each potential solution has a positive cost.
2. The problem may be either a maximization or a
minimization problem on the cost.
Performance ratio
 For minimization problem, the performance ratio of algorithm A is
defined as a number r such that for any instance I of the problem,
OPT(I) is the value of the optimal solution for instance I and
A(I) is the value of the solution returned by algorithm A on instance IA(I) is the value of the solution returned by algorithm A on instance I.
 For maximization problem, the performance ratio of algorithm A is
defined as a number r such that for any instance I of the problem,
OPT(I)/A(I)
is at most r (r≥1),
Bin Packing ProblemBin Packing Problem
 Pack a set of N BINS = {1, 2, …, n} items, each with size ti , i=1,
2,…,n, into identical bins, each with capacity C.
 the bin packing problem is to determine the minimum number of bins
to accommodate all items.
 Fi di th ti l l ti i NP h d bl Finding the optimal solution is a NP-hard problem.
 Minimize the number of bins without violating the capacity constraints
Online bin packing
 Items arrive one by one.y
 Each item must be assigned immediately to a bin, without
knowledge of any future items. Reassignment is not allowed.
 There exists no online bin packing algorithm that always finds an
optimal solution.
 Next Fit (NF) First Fit (FF) Best Fit (BF) Next Fit (NF), First Fit (FF), Best Fit (BF)
Offline bin packing
 All n items are known in advance, i.e. before they have to be packed., f y p
 Initially sort the items in decreasing order of size and assign the
largest items first.
 First Fit Decreasing (FFD) ,Best Fit Decreasing (BFD)
Consider items 3; 6; 2; 1; 5; 7; 2; 4; 1; 9: with bin size 10
Next FitNext Fit
 Put the current item in the current bin if it fits, otherwise in the next
bin.
 O(n)
 Ex:[3; 6] - [2; 1; 5] -[7; 2]- [4; 1] - [9]
First Fit
 Put the current item into the first bin it fits into.
O( 2) O(n2)
 Ex:[3; 6; 1] - [2; 5; 2; 1] - [7] - [4] - [9]
Best Fit
 Assign an arriving item to the bin in which it fits bestg g
 Performance of BF and FF is similar.
 Ex:[3;6;1]-[2;5;2;1]-[9]-[4]-[9]
Algorithm First-Fit
1: forAll objects i = 1, 2, . . . , n do
2: forAll bins j = 1, 2, . . . do
3: if Object i fits in bin j then
4: Pack object i in bin j4: Pack object i in bin j.
5: Break the loop and pack the next object.
6: end if
7: end for
8: if Object i did not fit in any available bin then
9 C bi d k bj i9: Create new bin and pack object i.
10: end if
11: end for11: end for
Consider items 3; 6; 2; 1; 5; 7; 2; 4; 1; 9: with bin size 10
First Fit DecreasingFirst Fit Decreasing
1. Sort the objects in decreasing order
2. Apply First Fit strategy to this sorted list.2. Apply First Fit strategy to this sorted list.
Ex:[9; 1] -[7; 3] -[6; 4] -[5; 2; 2; 1]
Best Fit Decreasingg
1. Sort the objects in decreasing order
2. Apply Best Fit strategy to this sorted list.
Graph Coloring ProblemGraph Coloring Problem
 Graph coloring is an assignment of colors to the vertices of a graph.
no two adjacent vertices have the same color
 Chromatic number: is the smallest number of colors with which it
can be colored.
 S ti l l i d id l i Sequential coloring and widgerson coloring
Sequential Graph coloring
1 Gi G (VE) ith ti U th i t {1 2 3 } t1. Given G=(V,E) with n vertices. Use the integers {1,2,3, …, n} to
represent colors. Start by assigning 0 to every vertex. Process the
vertices one at a time.
2. For each vertex, Vi, start by coloring Vi with the color 1.
3. Check the neighbors of Vi to see if any is colored 1. If not then go
t th t t Vi+1to the next vertex, Vi+1.
4. If there is a neighbor colored 1, recolor Vi with color 2, and
repeat the neighbor searchrepeat the neighbor search.
5. Repeat the previous step incrementing the color until we find a
color c that has not been used to color any of Vi’s neighbors.
Example for sequential coloring
Widgerson coloring
 Recursive Algorithm Recursive Algorithm
 A graph with maximum degree ∆ can be easily colored using ∆ +1
colors.
 Base Case: 2 Colorable Graphs
 Find the sub graph of the Neighborhood of a given vertex,
 recursively color this sub graph.
 At most 3√n colors for an n-colorable graph.
Algorithm
Travelling Salesman ProblemTravelling Salesman Problem
 Definition: Find a path through a weighted graph which starts and
ends at the same vertex, includes every other vertex exactly once,, y y ,
and minimizes the total cost of edges.
 TSP is classify as NP-complete problem, that means no
l i l l ith t t ithi t blpolynomial algorithm can guarantee to come within countable
times of the shortest tour.
 TSP : Find a tour of minimum cost (distance)f ( )
 Problem: To find a Hamiltonian cycle of minimal cost.
Nearest Neighbor
1 Pick a reference vertex to start at1. Pick a reference vertex to start at.
2. Walk to its nearest neighbor (i.e., along the shortest possible
edge).(If there is a tie, break it randomly.)
3. At each stage in your tour, walk to the nearest neighbor that
you have not already visited.
4 h h i i d ll i h i4. When you have visited all vertices, return to the starting vertex.
Shortest-Link
 Idea: Start in the middle Idea: Start in the middle.
1. Add the cheapest available edge to your tour.(If there is a tie,
break it randomly.)
2. Repeat until you have a Hamilton circuit.
3. Make sure you add exactly two edges at each vertex.
4. Don't close the circuit until all vertices are in it.

Weitere ähnliche Inhalte

Was ist angesagt?

String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)Aditya pratap Singh
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problemJayesh Chauhan
 
Knowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceKnowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceRamla Sheikh
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemMohammad Imam Hossain
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relationsIIUM
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsackAmin Omi
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler DesignShine Raj
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 

Was ist angesagt? (20)

String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 
Knowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceKnowledge representation In Artificial Intelligence
Knowledge representation In Artificial Intelligence
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relations
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
First and follow set
First and follow setFirst and follow set
First and follow set
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Data Representation
Data RepresentationData Representation
Data Representation
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 

Andere mochten auch

Andere mochten auch (8)

Master theorem
Master theoremMaster theorem
Master theorem
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Binpacking firstfitalgorithm
Binpacking firstfitalgorithmBinpacking firstfitalgorithm
Binpacking firstfitalgorithm
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 

Ähnlich wie Analysis and design of algorithms part 4

Ähnlich wie Analysis and design of algorithms part 4 (20)

Approx
ApproxApprox
Approx
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Approximation
ApproximationApproximation
Approximation
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 5
Unit 5Unit 5
Unit 5
 
Internship
InternshipInternship
Internship
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Teori pnp
Teori pnpTeori pnp
Teori pnp
 

Mehr von Deepak John

Network concepts and wi fi
Network concepts and wi fiNetwork concepts and wi fi
Network concepts and wi fiDeepak John
 
Web browser week5 presentation
Web browser week5 presentationWeb browser week5 presentation
Web browser week5 presentationDeepak John
 
Information management
Information managementInformation management
Information managementDeepak John
 
It security,malware,phishing,information theft
It security,malware,phishing,information theftIt security,malware,phishing,information theft
It security,malware,phishing,information theftDeepak John
 
Email,contacts and calendar
Email,contacts and calendarEmail,contacts and calendar
Email,contacts and calendarDeepak John
 
Module 2 instruction set
Module 2 instruction set Module 2 instruction set
Module 2 instruction set Deepak John
 
introduction to computers
 introduction to computers introduction to computers
introduction to computersDeepak John
 
Registers and counters
Registers and counters Registers and counters
Registers and counters Deepak John
 
Computer security module 4
Computer security module 4Computer security module 4
Computer security module 4Deepak John
 
Module 4 network and computer security
Module  4 network and computer securityModule  4 network and computer security
Module 4 network and computer securityDeepak John
 
Network and computer security-
Network and computer security-Network and computer security-
Network and computer security-Deepak John
 
Computer security module 3
Computer security module 3Computer security module 3
Computer security module 3Deepak John
 
Module 4 registers and counters
Module 4 registers and counters Module 4 registers and counters
Module 4 registers and counters Deepak John
 
Module 2 network and computer security
Module 2 network and computer securityModule 2 network and computer security
Module 2 network and computer securityDeepak John
 
Computer security module 2
Computer security module 2Computer security module 2
Computer security module 2Deepak John
 
Computer security module 1
Computer security module 1Computer security module 1
Computer security module 1Deepak John
 
Network and Computer security
Network and Computer securityNetwork and Computer security
Network and Computer securityDeepak John
 
Combinational and sequential logic
Combinational and sequential logicCombinational and sequential logic
Combinational and sequential logicDeepak John
 
Module 2 logic gates
Module 2  logic gatesModule 2  logic gates
Module 2 logic gatesDeepak John
 

Mehr von Deepak John (20)

Network concepts and wi fi
Network concepts and wi fiNetwork concepts and wi fi
Network concepts and wi fi
 
Web browser week5 presentation
Web browser week5 presentationWeb browser week5 presentation
Web browser week5 presentation
 
Information management
Information managementInformation management
Information management
 
It security,malware,phishing,information theft
It security,malware,phishing,information theftIt security,malware,phishing,information theft
It security,malware,phishing,information theft
 
Email,contacts and calendar
Email,contacts and calendarEmail,contacts and calendar
Email,contacts and calendar
 
Module 1 8086
Module 1 8086Module 1 8086
Module 1 8086
 
Module 2 instruction set
Module 2 instruction set Module 2 instruction set
Module 2 instruction set
 
introduction to computers
 introduction to computers introduction to computers
introduction to computers
 
Registers and counters
Registers and counters Registers and counters
Registers and counters
 
Computer security module 4
Computer security module 4Computer security module 4
Computer security module 4
 
Module 4 network and computer security
Module  4 network and computer securityModule  4 network and computer security
Module 4 network and computer security
 
Network and computer security-
Network and computer security-Network and computer security-
Network and computer security-
 
Computer security module 3
Computer security module 3Computer security module 3
Computer security module 3
 
Module 4 registers and counters
Module 4 registers and counters Module 4 registers and counters
Module 4 registers and counters
 
Module 2 network and computer security
Module 2 network and computer securityModule 2 network and computer security
Module 2 network and computer security
 
Computer security module 2
Computer security module 2Computer security module 2
Computer security module 2
 
Computer security module 1
Computer security module 1Computer security module 1
Computer security module 1
 
Network and Computer security
Network and Computer securityNetwork and Computer security
Network and Computer security
 
Combinational and sequential logic
Combinational and sequential logicCombinational and sequential logic
Combinational and sequential logic
 
Module 2 logic gates
Module 2  logic gatesModule 2  logic gates
Module 2 logic gates
 

Kürzlich hochgeladen

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Kürzlich hochgeladen (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Analysis and design of algorithms part 4

  • 1. Analysis and Design of Algorithms Deepak John Department Of Computer Applications, SJCET-Pala
  • 2. Types of ProblemsTypes of Problems  Optimization problem: construct a solution that maximizes or minimizes some objective functionmaximizes or minimizes some objective function  Decision problem: A question that has two possible answers, yes and no. Examples: •SHORTEST-PATH (optimization) Given G, u,v, find a path from u to v with fewest edges. •PATH (decision) Given G, u,v, and k, whether exist a path from u to vGiven G, u,v, and k, whether exist a path from u to v consisting of at most k edges.
  • 3. The class PThe class P  P is the set of decision problems that can be solved in polynomial time .if the size of the input to the problem is n then the problemp p p can be solved in time O(nk) for some constant k.  Polynomially bounded an algorithm is said to be polynomilly bounded if its worst case complexity is bounded by a polynomial function of the input i (if th i l i l h th t f h i t f isize(if there is a polynomial p such that for each input of size n the algorithm terminates after at most p(n)steps)  P: Polynomial algorithms - These include all the sorting P: Polynomial algorithms These include all the sorting algorithms, with running times on the order of n, lg n,n lg n and n2.
  • 4. Class NPClass NP  Class NP: Problems that can be solved in a polynomial number of steps by a nondeterministic polynomial algorithms.of steps by a nondeterministic polynomial algorithms.  A nondeterministic algorithm: a two-stage procedure that takes as its input an instance I of a decision problem and does the following 1. “guessing” stage: An arbitrary string S is generated that can b h h f l i f h i ibe thought of as a guess at a solution for the given instance 2. “verification” stage: A deterministic algorithm takes both I and S as its input and check if S is a solution to instance Iand S as its input and check if S is a solution to instance I, (outputs yes if s is a solution and outputs no or not halt at all otherwise)
  • 5. NP-CompleateNP Compleate  is the class of problems that are the hardest problems in NP.  example: example: A hamiltonian cycle of an undirected graph is a simple cycle that contains every vertex The Relationship between P ,NP and NPC
  • 6. Approximation algorithmsApproximation algorithms  an algorithm which return solutions that are guaranteed to be close to an optimal solution.be close to an optimal solution.  We use performance ratio to measure the quality of an approximation algorithm.  We are going to find a Near-Optimal solution for a given problem.  We assume two hypothesis : 1. Each potential solution has a positive cost. 2. The problem may be either a maximization or a minimization problem on the cost.
  • 7. Performance ratio  For minimization problem, the performance ratio of algorithm A is defined as a number r such that for any instance I of the problem, OPT(I) is the value of the optimal solution for instance I and A(I) is the value of the solution returned by algorithm A on instance IA(I) is the value of the solution returned by algorithm A on instance I.  For maximization problem, the performance ratio of algorithm A is defined as a number r such that for any instance I of the problem, OPT(I)/A(I) is at most r (r≥1),
  • 8. Bin Packing ProblemBin Packing Problem  Pack a set of N BINS = {1, 2, …, n} items, each with size ti , i=1, 2,…,n, into identical bins, each with capacity C.  the bin packing problem is to determine the minimum number of bins to accommodate all items.  Fi di th ti l l ti i NP h d bl Finding the optimal solution is a NP-hard problem.  Minimize the number of bins without violating the capacity constraints
  • 9. Online bin packing  Items arrive one by one.y  Each item must be assigned immediately to a bin, without knowledge of any future items. Reassignment is not allowed.  There exists no online bin packing algorithm that always finds an optimal solution.  Next Fit (NF) First Fit (FF) Best Fit (BF) Next Fit (NF), First Fit (FF), Best Fit (BF) Offline bin packing  All n items are known in advance, i.e. before they have to be packed., f y p  Initially sort the items in decreasing order of size and assign the largest items first.  First Fit Decreasing (FFD) ,Best Fit Decreasing (BFD)
  • 10. Consider items 3; 6; 2; 1; 5; 7; 2; 4; 1; 9: with bin size 10 Next FitNext Fit  Put the current item in the current bin if it fits, otherwise in the next bin.  O(n)  Ex:[3; 6] - [2; 1; 5] -[7; 2]- [4; 1] - [9] First Fit  Put the current item into the first bin it fits into. O( 2) O(n2)  Ex:[3; 6; 1] - [2; 5; 2; 1] - [7] - [4] - [9]
  • 11. Best Fit  Assign an arriving item to the bin in which it fits bestg g  Performance of BF and FF is similar.  Ex:[3;6;1]-[2;5;2;1]-[9]-[4]-[9]
  • 12. Algorithm First-Fit 1: forAll objects i = 1, 2, . . . , n do 2: forAll bins j = 1, 2, . . . do 3: if Object i fits in bin j then 4: Pack object i in bin j4: Pack object i in bin j. 5: Break the loop and pack the next object. 6: end if 7: end for 8: if Object i did not fit in any available bin then 9 C bi d k bj i9: Create new bin and pack object i. 10: end if 11: end for11: end for
  • 13. Consider items 3; 6; 2; 1; 5; 7; 2; 4; 1; 9: with bin size 10 First Fit DecreasingFirst Fit Decreasing 1. Sort the objects in decreasing order 2. Apply First Fit strategy to this sorted list.2. Apply First Fit strategy to this sorted list. Ex:[9; 1] -[7; 3] -[6; 4] -[5; 2; 2; 1] Best Fit Decreasingg 1. Sort the objects in decreasing order 2. Apply Best Fit strategy to this sorted list.
  • 14. Graph Coloring ProblemGraph Coloring Problem  Graph coloring is an assignment of colors to the vertices of a graph. no two adjacent vertices have the same color  Chromatic number: is the smallest number of colors with which it can be colored.  S ti l l i d id l i Sequential coloring and widgerson coloring
  • 15. Sequential Graph coloring 1 Gi G (VE) ith ti U th i t {1 2 3 } t1. Given G=(V,E) with n vertices. Use the integers {1,2,3, …, n} to represent colors. Start by assigning 0 to every vertex. Process the vertices one at a time. 2. For each vertex, Vi, start by coloring Vi with the color 1. 3. Check the neighbors of Vi to see if any is colored 1. If not then go t th t t Vi+1to the next vertex, Vi+1. 4. If there is a neighbor colored 1, recolor Vi with color 2, and repeat the neighbor searchrepeat the neighbor search. 5. Repeat the previous step incrementing the color until we find a color c that has not been used to color any of Vi’s neighbors.
  • 17. Widgerson coloring  Recursive Algorithm Recursive Algorithm  A graph with maximum degree ∆ can be easily colored using ∆ +1 colors.  Base Case: 2 Colorable Graphs  Find the sub graph of the Neighborhood of a given vertex,  recursively color this sub graph.  At most 3√n colors for an n-colorable graph.
  • 19. Travelling Salesman ProblemTravelling Salesman Problem  Definition: Find a path through a weighted graph which starts and ends at the same vertex, includes every other vertex exactly once,, y y , and minimizes the total cost of edges.  TSP is classify as NP-complete problem, that means no l i l l ith t t ithi t blpolynomial algorithm can guarantee to come within countable times of the shortest tour.  TSP : Find a tour of minimum cost (distance)f ( )  Problem: To find a Hamiltonian cycle of minimal cost.
  • 20. Nearest Neighbor 1 Pick a reference vertex to start at1. Pick a reference vertex to start at. 2. Walk to its nearest neighbor (i.e., along the shortest possible edge).(If there is a tie, break it randomly.) 3. At each stage in your tour, walk to the nearest neighbor that you have not already visited. 4 h h i i d ll i h i4. When you have visited all vertices, return to the starting vertex.
  • 21. Shortest-Link  Idea: Start in the middle Idea: Start in the middle. 1. Add the cheapest available edge to your tour.(If there is a tie, break it randomly.) 2. Repeat until you have a Hamilton circuit. 3. Make sure you add exactly two edges at each vertex. 4. Don't close the circuit until all vertices are in it.