SlideShare a Scribd company logo
1 of 13
Ms D Seethalakshmi
Asst. Prof. of CA
BSCW
Thanjavur
• Optimal structure: optimal solution to problem
• consists of optimal solutions to subproblems
• Overlapping subproblems: few subproblems in total,
• many recurring instances of each
• Solve in “near linear” time through recursion, using a
table to show state of problem at any given moment of
time
• Reduces computation time from exponential to linear in
some cases
Dynamic programming
Greedy algorithm always makes the
choice that is the locally optimal (best) at
the moment
It can reduce complex problem to linearly
solvable time, and can be much easier to
code
3
Greedy methods
 Shortest-path problem and multiple instance
knapsack problems can be solved using
greedy approach
 Activity selection is another example
4
Greedy methods
Problem: Stampede midway problem
» Buy a wristband that lets you onto any ride
» Lots of rides, each starting and ending at different times
» Your goal: ride as many rides as possible
• Alternative goal that we don’t solve here: maximize
time spent on rides
5
Greedy methods
Let A be an optimal solution of S and let k be the
minimum activity in A (i.e., the one with the
earliest finish time). Then A - {k} is an optimal
solution to S’ = {i ∈ S: si ≥ fk}
» In words: once activity #1 is selected, the problem
reduces to finding an optimal solution for activity
selection over activities in S compatible with #1
6
Greedy algorithm
The algorithm is following:
» Sort the activities by finish time
» Schedule the first activity
» Then schedule the next activity in sorted list which
starts after previous activity finishes
» Repeat until no more activities
Idea:
Always pick the shortest ride available at the time
Greedy-choice Property.
» A globally optimal solution can be arrived at by
making a locally optimal (greedy) choice.
7
Greedy Algorithm
 Backtracking can reduce a NP compete
problem to linear problem by only going
through selected branches of the global
solution.
8
Backtracking
 Graph-coloring problem
 8 queens problem
 4 knight problem
 Perfect hash function problems
are examples of backtracking method
9
Backtracking
 The goal is to color vertices in a graph G={V,E} so that no 2 adjacent
vertices have the same color. Partial 3-coloring problem means only 3
colors are considered.
 Direct approach builds the tree of ALL possibilities in exponential time.
10
Backtracking
 Partial 3-coloring (3 colors) is solved by the following method:
 Color first vertex with 1st color, color next vertex with the next color,
check if those two vertices are adjacent, if not - coloring is legal,
proceed to next vertex, if yes and color is the same – coloring is illegal,
try next color for second vertex. If all colors tried and all colorings are
illegal, backtrack, try next color for previous vertex etc.
 Note: sometimes solution is impossible.
 Exponential O(3^n) complexity is reduced to O(n) on average.
11
Backtracking
 Finally, job scheduling problem can be solved
by converting the algebraic relationship xi-
xj>=c to directed graph with vertices xi, xj,
direction from xj to xi, and edge cost (or time
required to complete job xj) is c.
 The problem of finding time (minimum) when
the last activity can commence (i.e. all
preceding activities has been completed) is
then converted to longest path problem on
the graph.
12
Job scheduling problem
THANK YOU

More Related Content

Similar to Greedy_Backtracking graph coloring.ppt

Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
Kumar
 
Skiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challengeSkiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challenge
zukun
 

Similar to Greedy_Backtracking graph coloring.ppt (20)

35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
 
Types of algorithms
Types of algorithmsTypes of algorithms
Types of algorithms
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
 
Backtracking
Backtracking  Backtracking
Backtracking
 
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
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
 
searching
searchingsearching
searching
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 5
Unit 5Unit 5
Unit 5
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Skiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challengeSkiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challenge
 
Greedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computerGreedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computer
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
 
Graph coloring problem(DAA).pptx
Graph coloring problem(DAA).pptxGraph coloring problem(DAA).pptx
Graph coloring problem(DAA).pptx
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
 
DynamicProgramming.pptx
DynamicProgramming.pptxDynamicProgramming.pptx
DynamicProgramming.pptx
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Class scheduling
Class schedulingClass scheduling
Class scheduling
 

More from SeethaDinesh

More from SeethaDinesh (20)

Input Devices.pptx
Input Devices.pptxInput Devices.pptx
Input Devices.pptx
 
Generations of Computers.ppt
Generations of Computers.pptGenerations of Computers.ppt
Generations of Computers.ppt
 
Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.ppt
 
Arrays in JAVA.ppt
Arrays in JAVA.pptArrays in JAVA.ppt
Arrays in JAVA.ppt
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
 
Cloud Computing Basics.pptx
Cloud Computing Basics.pptxCloud Computing Basics.pptx
Cloud Computing Basics.pptx
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Structure and Union.ppt
Structure and Union.pptStructure and Union.ppt
Structure and Union.ppt
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docx
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
NME UNIT II.ppt
NME UNIT II.pptNME UNIT II.ppt
NME UNIT II.ppt
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
DW unit 3.pptx
DW unit 3.pptxDW unit 3.pptx
DW unit 3.pptx
 
DW unit 2.pdf
DW unit 2.pdfDW unit 2.pdf
DW unit 2.pdf
 
DW Unit 1.pdf
DW Unit 1.pdfDW Unit 1.pdf
DW Unit 1.pdf
 
NME WPI UNIt 3.pptx
NME WPI UNIt 3.pptxNME WPI UNIt 3.pptx
NME WPI UNIt 3.pptx
 
NME UNIT I & II MATERIAL.pdf
NME UNIT I & II MATERIAL.pdfNME UNIT I & II MATERIAL.pdf
NME UNIT I & II MATERIAL.pdf
 
graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdf
 

Recently uploaded

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
PECB
 
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
QucHHunhnh
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

Greedy_Backtracking graph coloring.ppt

  • 1. Ms D Seethalakshmi Asst. Prof. of CA BSCW Thanjavur
  • 2. • Optimal structure: optimal solution to problem • consists of optimal solutions to subproblems • Overlapping subproblems: few subproblems in total, • many recurring instances of each • Solve in “near linear” time through recursion, using a table to show state of problem at any given moment of time • Reduces computation time from exponential to linear in some cases Dynamic programming
  • 3. Greedy algorithm always makes the choice that is the locally optimal (best) at the moment It can reduce complex problem to linearly solvable time, and can be much easier to code 3 Greedy methods
  • 4.  Shortest-path problem and multiple instance knapsack problems can be solved using greedy approach  Activity selection is another example 4 Greedy methods
  • 5. Problem: Stampede midway problem » Buy a wristband that lets you onto any ride » Lots of rides, each starting and ending at different times » Your goal: ride as many rides as possible • Alternative goal that we don’t solve here: maximize time spent on rides 5 Greedy methods
  • 6. Let A be an optimal solution of S and let k be the minimum activity in A (i.e., the one with the earliest finish time). Then A - {k} is an optimal solution to S’ = {i ∈ S: si ≥ fk} » In words: once activity #1 is selected, the problem reduces to finding an optimal solution for activity selection over activities in S compatible with #1 6 Greedy algorithm
  • 7. The algorithm is following: » Sort the activities by finish time » Schedule the first activity » Then schedule the next activity in sorted list which starts after previous activity finishes » Repeat until no more activities Idea: Always pick the shortest ride available at the time Greedy-choice Property. » A globally optimal solution can be arrived at by making a locally optimal (greedy) choice. 7 Greedy Algorithm
  • 8.  Backtracking can reduce a NP compete problem to linear problem by only going through selected branches of the global solution. 8 Backtracking
  • 9.  Graph-coloring problem  8 queens problem  4 knight problem  Perfect hash function problems are examples of backtracking method 9 Backtracking
  • 10.  The goal is to color vertices in a graph G={V,E} so that no 2 adjacent vertices have the same color. Partial 3-coloring problem means only 3 colors are considered.  Direct approach builds the tree of ALL possibilities in exponential time. 10 Backtracking
  • 11.  Partial 3-coloring (3 colors) is solved by the following method:  Color first vertex with 1st color, color next vertex with the next color, check if those two vertices are adjacent, if not - coloring is legal, proceed to next vertex, if yes and color is the same – coloring is illegal, try next color for second vertex. If all colors tried and all colorings are illegal, backtrack, try next color for previous vertex etc.  Note: sometimes solution is impossible.  Exponential O(3^n) complexity is reduced to O(n) on average. 11 Backtracking
  • 12.  Finally, job scheduling problem can be solved by converting the algebraic relationship xi- xj>=c to directed graph with vertices xi, xj, direction from xj to xi, and edge cost (or time required to complete job xj) is c.  The problem of finding time (minimum) when the last activity can commence (i.e. all preceding activities has been completed) is then converted to longest path problem on the graph. 12 Job scheduling problem