SlideShare a Scribd company logo
Spanning Trees
Spanning trees
   Suppose you have a connected undirected graph
        Connected: every node is reachable from every other node
        Undirected: edges do not have an associated direction
   ...then a spanning tree of the graph is a connected
    subgraph in which there are no cycles




     A connected,       Four of the spanning trees of the graph
    undirected graph


                                                                  2
Finding a spanning tree
   To find a spanning tree of a graph,
       pick an initial node and call it part of the spanning tree
       do a search from the initial node:
           each time you find a node that is not in the spanning tree, add to the
           spanning tree both the new node and the edge you followed to get to
           it




      An undirected graph       One possible            One possible
                                result of a BFS         result of a DFS
                                starting from top       starting from3top
Minimizing costs
   Suppose you want to supply a set of houses (say, in a
    new subdivision) with:
       electric power
       water
       sewage lines
       telephone lines
   To keep costs down, you could connect these houses
    with a spanning tree (of, for example, power lines)
       However, the houses are not all equal distances apart
   To reduce costs even further, you could connect the
    houses with a minimum-cost spanning tree

                                                          4
Minimum-cost spanning trees
    Suppose you have a connected undirected graph with a weight
     (or cost) associated with each edge
    The cost of a spanning tree would be the sum of the costs of its
     edges
    A minimum-cost spanning tree is a spanning tree that has the
     lowest cost
                   16                                16
            A                  B               A            B
                 21 11             6                   11       6

       19                      5                            5
                     F                 C              F             C
                33        14
                                       10
            E        18        D               E     18     D
    A connected, undirected graph           A minimum-cost spanning tree
                                                                        5
Finding spanning trees
   There are two basic algorithms for finding minimum-cost
    spanning trees, and both are greedy algorithms

   Kruskal’s algorithm: Start with no nodes or edges in the
    spanning tree, and repeatedly add the cheapest edge that does
    not create a cycle
       Here, we consider the spanning tree to consist of edges only

   Prim’s algorithm: Start with any one node in the spanning
    tree, and repeatedly add the cheapest edge, and the node it leads
    to, for which the node is not already in the spanning tree.
       Here, we consider the spanning tree to consist of both nodes and edges


                                                                   6
Kruskal’s algorithm
    T = empty spanning tree;
    E = set of edges;
    N = number of nodes in graph;
    while T has fewer than N - 1 edges {
       remove an edge (v, w) of lowest cost from E
       if adding (v, w) to T would create a cycle
           then discard (v, w)
           else add (v, w) to T
    }
   Finding an edge of lowest cost can be done just by sorting
    the edges
   Efficient testing for a cycle requires a fairly complex
    algorithm (UNION-FIND) which we don’t cover in this
    course

                                                      7
Prim’s algorithm
    T = a spanning tree containing a single node s;
    E = set of edges adjacent to s;
    while T does not contain all the nodes {
       remove an edge (v, w) of lowest cost from E
       if w is already in T then discard edge (v, w)
       else {
           add edge (v, w) and node w to T
           add to E the edges adjacent to w
       }
    }
   An edge of lowest cost can be found with a priority queue
   Testing for a cycle is automatic
       Hence, Prim’s algorithm is far simpler to implement than Kruskal’s
        algorithm
                                                                  8
Mazes
           Typically,
                Every location in a maze is
                 reachable from the starting location
                There is only one path from start to
                 finish
           If the cells are “vertices” and the
            open doors between cells are
            “edges,” this describes a
            spanning tree
           Since there is exactly one path
            between any pair of cells, any
            cells can be used as “start” and
            “finish”
           This describes a spanning tree

                                        9
Mazes as spanning trees
                   While not every maze is a
                    spanning tree, most can be
                    represented as such
                   The nodes are “places” within
                    the maze
                   There is exactly one cycle-
                    free path from any node to
                    any other node




                                     10
Building a maze I

   This algorithm requires two
    sets of cells
        the set of cells already in the
         spanning tree, IN
        the set of cells adjacent to the
         cells in the spanning tree (but
         not in it themselves), called
         the FRONTIER
   Start with all walls present

   Pick any cell and put it into IN (red)
•   Put all adjacent cells, that aren’t in IN, into FRONTIER (blue)


                                                          11
Building a maze II
   Repeatedly do the
    following:
        Remove any one cell C from
         FRONTIER and put it in IN
        Erase the wall between C and
         some one adjacent cell in IN
         Add to FRONTIER all the cells
          adjacent to C that aren’t in IN
          (or in FRONTIER already)

•   Continue until there are no more cells in FRONTIER
• When the maze is complete (or at any time), choose the start
  and finish cells

                                                         12
The End




          13

More Related Content

Viewers also liked

ConexióN De Una Base De Datos De Sql Con C#
ConexióN De Una Base De Datos De Sql Con C#ConexióN De Una Base De Datos De Sql Con C#
ConexióN De Una Base De Datos De Sql Con C#LUZ ARIZPE
 
Clase redes de computadoras
Clase redes de computadorasClase redes de computadoras
Clase redes de computadoras
José Tomás Diarte Añazco
 
Presentacion unidad ii redes basico
Presentacion unidad ii redes basicoPresentacion unidad ii redes basico
Presentacion unidad ii redes basico
Alejandra Ochoa
 
Práctica de Redes LAN: Compartiendo recursos
Práctica de Redes LAN: Compartiendo recursosPráctica de Redes LAN: Compartiendo recursos
Práctica de Redes LAN: Compartiendo recursosLuis Alberto Torres Paz
 
presupuesto de red lan
presupuesto de red lanpresupuesto de red lan
presupuesto de red lan
Dyfre Memenay
 
Triggers y Stored Procedures con MicroOLAP Database Designer
Triggers y Stored Procedures con MicroOLAP Database DesignerTriggers y Stored Procedures con MicroOLAP Database Designer
Triggers y Stored Procedures con MicroOLAP Database Designervictorsalas
 
Triggers o disparadores en MySQL
Triggers o disparadores en MySQL Triggers o disparadores en MySQL
Triggers o disparadores en MySQL
Jair Ospino Ardila
 
Implementación de una red lan y Software educativo Escuela Canton Duran
Implementación de una red lan y Software educativo Escuela Canton DuranImplementación de una red lan y Software educativo Escuela Canton Duran
Implementación de una red lan y Software educativo Escuela Canton Duran
Unidad Educativa America del Sur
 
CONTINUACION DE REDES INALAMBRICAS POWER POINT.
CONTINUACION DE REDES INALAMBRICAS POWER POINT.CONTINUACION DE REDES INALAMBRICAS POWER POINT.
CONTINUACION DE REDES INALAMBRICAS POWER POINT.EvaRael
 
My sql para principiantes
My sql para principiantesMy sql para principiantes
My sql para principiantes
Michelle Torres
 
PROPUESTA DE REDES
PROPUESTA DE REDESPROPUESTA DE REDES
PROPUESTA DE REDES
johana45
 
Ejemplo de Trigger en Mysql
Ejemplo de Trigger en MysqlEjemplo de Trigger en Mysql
Redes Lan
Redes LanRedes Lan
Redes Lan
banomarcelo
 
Documentacion de una red
Documentacion de una redDocumentacion de una red
Documentacion de una redEduardo Guzman
 
Planeación y diseño de una red local
Planeación y diseño de una red localPlaneación y diseño de una red local
Planeación y diseño de una red localLeonardo Gómez
 
PROYECTO CREACIÓN DE UNA RED LOCAL
PROYECTO CREACIÓN DE UNA RED LOCALPROYECTO CREACIÓN DE UNA RED LOCAL
PROYECTO CREACIÓN DE UNA RED LOCALLuis Calero Romero
 
PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.
PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.
PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.
UNIVERSIDAD MAGISTER (Sitio Oficial)
 
6. diseño de redes de área local y documentación
6.  diseño de redes de área local y documentación6.  diseño de redes de área local y documentación
6. diseño de redes de área local y documentación
Sandy Romero
 
Proyecto de Redes - Desarrollo de un plan de trabajo
Proyecto de Redes - Desarrollo de un plan de trabajoProyecto de Redes - Desarrollo de un plan de trabajo
Proyecto de Redes - Desarrollo de un plan de trabajo
Alfredo Humberto Escalante Godinez
 

Viewers also liked (20)

ConexióN De Una Base De Datos De Sql Con C#
ConexióN De Una Base De Datos De Sql Con C#ConexióN De Una Base De Datos De Sql Con C#
ConexióN De Una Base De Datos De Sql Con C#
 
Clase redes de computadoras
Clase redes de computadorasClase redes de computadoras
Clase redes de computadoras
 
Presentacion unidad ii redes basico
Presentacion unidad ii redes basicoPresentacion unidad ii redes basico
Presentacion unidad ii redes basico
 
Práctica de Redes LAN: Compartiendo recursos
Práctica de Redes LAN: Compartiendo recursosPráctica de Redes LAN: Compartiendo recursos
Práctica de Redes LAN: Compartiendo recursos
 
presupuesto de red lan
presupuesto de red lanpresupuesto de red lan
presupuesto de red lan
 
Triggers y Stored Procedures con MicroOLAP Database Designer
Triggers y Stored Procedures con MicroOLAP Database DesignerTriggers y Stored Procedures con MicroOLAP Database Designer
Triggers y Stored Procedures con MicroOLAP Database Designer
 
Triggers o disparadores en MySQL
Triggers o disparadores en MySQL Triggers o disparadores en MySQL
Triggers o disparadores en MySQL
 
Implementación de una red lan y Software educativo Escuela Canton Duran
Implementación de una red lan y Software educativo Escuela Canton DuranImplementación de una red lan y Software educativo Escuela Canton Duran
Implementación de una red lan y Software educativo Escuela Canton Duran
 
CONTINUACION DE REDES INALAMBRICAS POWER POINT.
CONTINUACION DE REDES INALAMBRICAS POWER POINT.CONTINUACION DE REDES INALAMBRICAS POWER POINT.
CONTINUACION DE REDES INALAMBRICAS POWER POINT.
 
My sql para principiantes
My sql para principiantesMy sql para principiantes
My sql para principiantes
 
Diapositivas REDES LAN
Diapositivas REDES LANDiapositivas REDES LAN
Diapositivas REDES LAN
 
PROPUESTA DE REDES
PROPUESTA DE REDESPROPUESTA DE REDES
PROPUESTA DE REDES
 
Ejemplo de Trigger en Mysql
Ejemplo de Trigger en MysqlEjemplo de Trigger en Mysql
Ejemplo de Trigger en Mysql
 
Redes Lan
Redes LanRedes Lan
Redes Lan
 
Documentacion de una red
Documentacion de una redDocumentacion de una red
Documentacion de una red
 
Planeación y diseño de una red local
Planeación y diseño de una red localPlaneación y diseño de una red local
Planeación y diseño de una red local
 
PROYECTO CREACIÓN DE UNA RED LOCAL
PROYECTO CREACIÓN DE UNA RED LOCALPROYECTO CREACIÓN DE UNA RED LOCAL
PROYECTO CREACIÓN DE UNA RED LOCAL
 
PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.
PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.
PROPUESTA DE UN DISEÑO DE UNA TOPOLOGÍA DE RED PARA LA EMPRESA DISER S.A.
 
6. diseño de redes de área local y documentación
6.  diseño de redes de área local y documentación6.  diseño de redes de área local y documentación
6. diseño de redes de área local y documentación
 
Proyecto de Redes - Desarrollo de un plan de trabajo
Proyecto de Redes - Desarrollo de un plan de trabajoProyecto de Redes - Desarrollo de un plan de trabajo
Proyecto de Redes - Desarrollo de un plan de trabajo
 

Similar to 33 spanning-trees

Spanning trees
Spanning treesSpanning trees
Spanning trees
Shareb Ismaeel
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA2111026030
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9chidabdu
 
KRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraKRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraguest1f4fb3
 
KRUSKALS'S algorithm from chaitra
KRUSKALS'S algorithm from chaitraKRUSKALS'S algorithm from chaitra
KRUSKALS'S algorithm from chaitraguest1f4fb3
 
Graphs
GraphsGraphs
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
sakthibalabalamuruga
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
STEFFY D
 
Ram minimum spanning tree
Ram   minimum spanning treeRam   minimum spanning tree
Ram minimum spanning tree
Rama Prasath A
 
All Perfect Elimination Orderings & Minimal Vertex Seperators
All Perfect Elimination Orderings & Minimal Vertex SeperatorsAll Perfect Elimination Orderings & Minimal Vertex Seperators
All Perfect Elimination Orderings & Minimal Vertex Seperators
nazlitemu
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
SwarndeviKm
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
Alona Salva
 
trees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptxtrees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptx
TanvirAhmed166122
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
sahilpawar2426
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11chidabdu
 

Similar to 33 spanning-trees (20)

Spanning trees
Spanning treesSpanning trees
Spanning trees
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
26 spanning
26 spanning26 spanning
26 spanning
 
KRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraKRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitra
 
KRUSKALS'S algorithm from chaitra
KRUSKALS'S algorithm from chaitraKRUSKALS'S algorithm from chaitra
KRUSKALS'S algorithm from chaitra
 
Graphs
GraphsGraphs
Graphs
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Ram minimum spanning tree
Ram   minimum spanning treeRam   minimum spanning tree
Ram minimum spanning tree
 
All Perfect Elimination Orderings & Minimal Vertex Seperators
All Perfect Elimination Orderings & Minimal Vertex SeperatorsAll Perfect Elimination Orderings & Minimal Vertex Seperators
All Perfect Elimination Orderings & Minimal Vertex Seperators
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
 
trees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptxtrees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptx
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

33 spanning-trees

  • 2. Spanning trees  Suppose you have a connected undirected graph  Connected: every node is reachable from every other node  Undirected: edges do not have an associated direction  ...then a spanning tree of the graph is a connected subgraph in which there are no cycles A connected, Four of the spanning trees of the graph undirected graph 2
  • 3. Finding a spanning tree  To find a spanning tree of a graph, pick an initial node and call it part of the spanning tree do a search from the initial node: each time you find a node that is not in the spanning tree, add to the spanning tree both the new node and the edge you followed to get to it An undirected graph One possible One possible result of a BFS result of a DFS starting from top starting from3top
  • 4. Minimizing costs  Suppose you want to supply a set of houses (say, in a new subdivision) with:  electric power  water  sewage lines  telephone lines  To keep costs down, you could connect these houses with a spanning tree (of, for example, power lines)  However, the houses are not all equal distances apart  To reduce costs even further, you could connect the houses with a minimum-cost spanning tree 4
  • 5. Minimum-cost spanning trees  Suppose you have a connected undirected graph with a weight (or cost) associated with each edge  The cost of a spanning tree would be the sum of the costs of its edges  A minimum-cost spanning tree is a spanning tree that has the lowest cost 16 16 A B A B 21 11 6 11 6 19 5 5 F C F C 33 14 10 E 18 D E 18 D A connected, undirected graph A minimum-cost spanning tree 5
  • 6. Finding spanning trees  There are two basic algorithms for finding minimum-cost spanning trees, and both are greedy algorithms  Kruskal’s algorithm: Start with no nodes or edges in the spanning tree, and repeatedly add the cheapest edge that does not create a cycle  Here, we consider the spanning tree to consist of edges only  Prim’s algorithm: Start with any one node in the spanning tree, and repeatedly add the cheapest edge, and the node it leads to, for which the node is not already in the spanning tree.  Here, we consider the spanning tree to consist of both nodes and edges 6
  • 7. Kruskal’s algorithm T = empty spanning tree; E = set of edges; N = number of nodes in graph; while T has fewer than N - 1 edges { remove an edge (v, w) of lowest cost from E if adding (v, w) to T would create a cycle then discard (v, w) else add (v, w) to T }  Finding an edge of lowest cost can be done just by sorting the edges  Efficient testing for a cycle requires a fairly complex algorithm (UNION-FIND) which we don’t cover in this course 7
  • 8. Prim’s algorithm T = a spanning tree containing a single node s; E = set of edges adjacent to s; while T does not contain all the nodes { remove an edge (v, w) of lowest cost from E if w is already in T then discard edge (v, w) else { add edge (v, w) and node w to T add to E the edges adjacent to w } }  An edge of lowest cost can be found with a priority queue  Testing for a cycle is automatic  Hence, Prim’s algorithm is far simpler to implement than Kruskal’s algorithm 8
  • 9. Mazes  Typically,  Every location in a maze is reachable from the starting location  There is only one path from start to finish  If the cells are “vertices” and the open doors between cells are “edges,” this describes a spanning tree  Since there is exactly one path between any pair of cells, any cells can be used as “start” and “finish”  This describes a spanning tree 9
  • 10. Mazes as spanning trees  While not every maze is a spanning tree, most can be represented as such  The nodes are “places” within the maze  There is exactly one cycle- free path from any node to any other node 10
  • 11. Building a maze I  This algorithm requires two sets of cells  the set of cells already in the spanning tree, IN  the set of cells adjacent to the cells in the spanning tree (but not in it themselves), called the FRONTIER  Start with all walls present  Pick any cell and put it into IN (red) • Put all adjacent cells, that aren’t in IN, into FRONTIER (blue) 11
  • 12. Building a maze II  Repeatedly do the following:  Remove any one cell C from FRONTIER and put it in IN  Erase the wall between C and some one adjacent cell in IN  Add to FRONTIER all the cells adjacent to C that aren’t in IN (or in FRONTIER already) • Continue until there are no more cells in FRONTIER • When the maze is complete (or at any time), choose the start and finish cells 12
  • 13. The End 13