Chapter 14 Graph Algorithms

Slides:



Advertisements
Similar presentations
Request Dispatching for Cheap Energy Prices in Cloud Data Centers
Advertisements

SpringerLink Training Kit
Luminosity measurements at Hadron Colliders
From Word Embeddings To Document Distances
Choosing a Dental Plan Student Name
Virtual Environments and Computer Graphics
Chương 1: CÁC PHƯƠNG THỨC GIAO DỊCH TRÊN THỊ TRƯỜNG THẾ GIỚI
THỰC TIỄN KINH DOANH TRONG CỘNG ĐỒNG KINH TẾ ASEAN –
D. Phát triển thương hiệu
NHỮNG VẤN ĐỀ NỔI BẬT CỦA NỀN KINH TẾ VIỆT NAM GIAI ĐOẠN
Điều trị chống huyết khối trong tai biến mạch máu não
BÖnh Parkinson PGS.TS.BS NGUYỄN TRỌNG HƯNG BỆNH VIỆN LÃO KHOA TRUNG ƯƠNG TRƯỜNG ĐẠI HỌC Y HÀ NỘI Bác Ninh 2013.
Nasal Cannula X particulate mask
Evolving Architecture for Beyond the Standard Model
HF NOISE FILTERS PERFORMANCE
Electronics for Pedestrians – Passive Components –
Parameterization of Tabulated BRDFs Ian Mallett (me), Cem Yuksel
L-Systems and Affine Transformations
CMSC423: Bioinformatic Algorithms, Databases and Tools
Some aspect concerning the LMDZ dynamical core and its use
Bayesian Confidence Limits and Intervals
实习总结 (Internship Summary)
Current State of Japanese Economy under Negative Interest Rate and Proposed Remedies Naoyuki Yoshino Dean Asian Development Bank Institute Professor Emeritus,
Front End Electronics for SOI Monolithic Pixel Sensor
Face Recognition Monday, February 1, 2016.
Solving Rubik's Cube By: Etai Nativ.
CS284 Paper Presentation Arpad Kovacs
انتقال حرارت 2 خانم خسرویار.
Summer Student Program First results
Theoretical Results on Neutrinos
HERMESでのHard Exclusive生成過程による 核子内クォーク全角運動量についての研究
Wavelet Coherence & Cross-Wavelet Transform
yaSpMV: Yet Another SpMV Framework on GPUs
Creating Synthetic Microdata for Higher Educational Use in Japan: Reproduction of Distribution Type based on the Descriptive Statistics Kiyomi Shirakawa.
MOCLA02 Design of a Compact L-­band Transverse Deflecting Cavity with Arbitrary Polarizations for the SACLA Injector Sep. 14th, 2015 H. Maesaka, T. Asaka,
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Fuel cell development program for electric vehicle
Overview of TST-2 Experiment
Optomechanics with atoms
داده کاوی سئوالات نمونه
Inter-system biases estimation in multi-GNSS relative positioning with GPS and Galileo Cecile Deprez and Rene Warnant University of Liege, Belgium  
ლექცია 4 - ფული და ინფლაცია
10. predavanje Novac i financijski sustav
Wissenschaftliche Aussprache zur Dissertation
FLUORECENCE MICROSCOPY SUPERRESOLUTION BLINK MICROSCOPY ON THE BASIS OF ENGINEERED DARK STATES* *Christian Steinhauer, Carsten Forthmann, Jan Vogelsang,
Particle acceleration during the gamma-ray flares of the Crab Nebular
Interpretations of the Derivative Gottfried Wilhelm Leibniz
Advisor: Chiuyuan Chen Student: Shao-Chun Lin
Widow Rockfish Assessment
SiW-ECAL Beam Test 2015 Kick-Off meeting
On Robust Neighbor Discovery in Mobile Wireless Networks
Chapter 6 并发:死锁和饥饿 Operating Systems: Internals and Design Principles
You NEED your book!!! Frequency Distribution
Y V =0 a V =V0 x b b V =0 z
Fairness-oriented Scheduling Support for Multicore Systems
Climate-Energy-Policy Interaction
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Ch48 Statistics by Chtan FYHSKulai
The ABCD matrix for parabolic reflectors and its application to astigmatism free four-mirror cavities.
Measure Twice and Cut Once: Robust Dynamic Voltage Scaling for FPGAs
Online Learning: An Introduction
Factor Based Index of Systemic Stress (FISS)
What is Chemistry? Chemistry is: the study of matter & the changes it undergoes Composition Structure Properties Energy changes.
THE BERRY PHASE OF A BOGOLIUBOV QUASIPARTICLE IN AN ABRIKOSOV VORTEX*
Quantum-classical transition in optical twin beams and experimental applications to quantum metrology Ivano Ruo-Berchera Frascati.
The Toroidal Sporadic Source: Understanding Temporal Variations
FW 3.4: More Circle Practice
ارائه یک روش حل مبتنی بر استراتژی های تکاملی گروه بندی برای حل مسئله بسته بندی اقلام در ظروف
Decision Procedures Christoph M. Wintersteiger 9/11/2017 3:14 PM
Limits on Anomalous WWγ and WWZ Couplings from DØ
Presentation transcript:

Chapter 14 Graph Algorithms ORD DFW SFO LAX 802 1743 1843 1233 337 Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in Java, Goodrich, Tamassia and Goldwasser (Wiley 2016) 1 1

Graphs 二○一七年十月二十八日 Depth-First Search D B A C E

Depth-First Search Depth-first search (DFS) is a general technique for traversing a graph A DFS traversal of a graph 𝐺 Visits all the vertices and edges of 𝐺 Determines whether 𝐺 is connected Computes the connected components of 𝐺 Computes a spanning forest of 𝐺 DFS on a graph with 𝑛 vertices and 𝑚 edges takes 𝑂(𝑛+𝑚) time DFS can be further extended to solve other graph problems Find and report a path between two given vertices Find a cycle in the graph Depth-first search is to graphs as what Euler tour is to binary trees

DFS Algorithm from a vertex Algorithm DFS(𝐺, 𝑢) Input: A graph 𝐺 and a vertex 𝑢 of 𝐺 Output: A collection of vertices reachable from 𝑢, with their discovery edges Mark 𝑢 as visited for each edge 𝑒= 𝑢, 𝑣 ∈𝐺.outgoingEdges(𝑢) do if 𝑣 has not been visited then Record 𝑒 as a discovery edge for 𝑣 DFS(𝐺, 𝑣)

Example unexplored vertex visited vertex unexplored edge Graphs 二○一七年十月二十八日 Example 𝐼(𝐵) = {𝑨, 𝐶, 𝐹} 𝐼(𝐵) = {𝐴, 𝑪, 𝐹} D B A C E F G A unexplored vertex A visited vertex unexplored edge discovery edge back edge 𝐼(𝐴) = {𝑩, 𝐶, 𝐷, 𝐸} 𝐼(𝐶) = {𝑨, 𝐵, 𝐷, 𝐸} D B A C E F G D B A C E F G Explore incident edges in order, go along the unexplored edge 1. Seeing a neighbor already explored -> check next edge 2. Reaching dead end (no more edges to explore) -> go back to parent 𝐼(𝐶) = {𝐴, 𝑩, 𝐷, 𝐸} 𝐼(𝐶) = {𝐴, 𝐵, 𝑫, 𝐸}

Example 𝐼(𝐶) = {𝐴, 𝐵, 𝑫, 𝐸} 𝐼(𝐶) = {𝐴, 𝐵, 𝐷, 𝑬} 𝐼(𝐷) = {𝑨, 𝐶} D B A C E F G D B A C E F G 𝐼(𝐷) = {𝑨, 𝐶} 𝐼(𝐸) = {𝑨, 𝐶} D B A C E F G D B A C E F G 𝐼(𝐷) = {𝐴, 𝑪} 𝐼(𝐷) = {𝐴, 𝐶} 𝐼(𝐸) = {𝐴, 𝑪} 𝐼(𝐸) = {𝐴, 𝐶}

Example 𝐼(𝐶) = {𝐴, 𝐵, 𝐷, 𝐸} 𝐼(𝐵) = {𝐴, 𝐶, 𝑭} 𝐼(𝐺) =∅ 𝐼(𝐹) = {𝐵} D B A C E F G D B A C E F G 𝐼(𝐹) = {𝐵} D B A C E F G 𝐼(𝐵) = {𝐴, 𝐶, 𝐹} 𝐼(𝐴) = {𝐴, 𝐵, 𝐶, 𝐷}

Exercise DFS Algorithm Perform DFS of the following graph, start from vertex A Assume adjacent edges are processed in alphabetical order Number vertices in the order they are visited Label edges as discovery or back edges C B A E D F

Graphs 二○一七年十月二十八日 DFS and Maze Traversal The DFS algorithm is similar to a classic strategy for exploring a maze We mark each intersection, corner and dead end (vertex) visited We mark each corridor (edge) traversed We keep track of the path back to the entrance (start vertex) by means of a rope (recursion stack) Use a rope to mark the visited route. Choose an unexplored way at the intersection 1. Seeing the rope -> choose another way 2. Reaching dead end (no more ways to explore) -> go back to the last intersection

Graphs 二○一七年十月二十八日 DFS Algorithm The algorithm uses a mechanism for setting and getting “labels” of vertices and edges Algorithm DFS(𝐺) Input: Graph 𝐺 Output: Labeling of the edges of 𝐺 as discovery edges and back edges for each 𝑣∈𝐺.vertices do setLabel 𝑣, 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 for each 𝑒∈𝐺.edges do setLabel(𝑒, 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷) if getLabel 𝑣 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then DFS(𝐺, 𝑣) Algorithm DFS(𝐺, 𝑣) Input: Graph 𝐺 and a start vertex 𝑣 Output: Labeling of the edges of 𝐺 in the connected component of 𝑣 as discovery edges and back edges setLabel(𝑣, 𝑉𝐼𝑆𝐼𝑇𝐸𝐷) for each 𝑒∈𝐺.outgoingEdges 𝑣 do if getLabel 𝑒 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷) 𝑤←𝐺.opposite(𝑣,𝑒) if getLabel 𝑤 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then setLabel(𝑒, 𝐷𝐼𝑆𝐶𝑂𝑉𝐸𝑅𝑌) DFS(𝐺, 𝑤) else setLabel(𝑒, 𝐵𝐴𝐶𝐾)

Properties of DFS v1 v2 Property 1 Property 2 DFS(𝐺, 𝑣) visits all the vertices and edges in the connected component of 𝑣 Property 2 The discovery edges labeled by DFS(𝐺, 𝑣) form a spanning tree of the connected component of 𝑣 v1 D B A C E F v2 G

Analysis of DFS Setting/getting a vertex/edge label takes 𝑂(1) time Each vertex is labeled twice once as 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 once as 𝑉𝐼𝑆𝐼𝑇𝐸𝐷 Each edge is labeled twice once as 𝐷𝐼𝑆𝐶𝑂𝑉𝐸𝑅𝑌 or 𝐵𝐴𝐶𝐾 Function DFS(𝐺, 𝑣) and the method outgoingEdges are called once for each vertex DFS runs in 𝑂(𝑛+𝑚) time provided the graph is represented by the adjacency list structure Recall that Σ 𝑣 deg 𝑣 =2𝑚 D B A C E F G

Application Path Finding We can specialize the DFS algorithm to find a path between two given vertices 𝑢 and 𝑧 using the template method pattern We call DFS(𝐺, 𝑢) with 𝑢 as the start vertex We use a stack 𝑆 to keep track of the path between the start vertex and the current vertex As soon as destination vertex 𝑧 is encountered, we return the path as the contents of the stack Algorithm pathDFS(𝐺, 𝑣, 𝑧) setLabel(𝑣, 𝑉𝐼𝑆𝐼𝑇𝐸𝐷) 𝑆.push(𝑣) if 𝑣=𝑧 return 𝑆.elements( ) for each 𝑒∈𝐺.outgoingEdges 𝑣 do if getLabel 𝑒 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷) then 𝑤←𝐺.opposite(𝑣, 𝑒) if getLabel 𝑤 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then setLabel(𝑒, 𝐷𝐼𝑆𝐶𝑂𝑉𝐸𝑅𝑌) 𝑆.push(𝑒) pathDFS 𝐺, 𝑤 𝑆.pop( ) else setLabel(𝑒, 𝐵𝐴𝐶𝐾)

Application Cycle Finding Algorithm cycleDFS(𝐺, 𝑣) setLabel(𝑣, 𝑉𝐼𝑆𝐼𝑇𝐸𝐷) 𝑆.push(𝑣) for each 𝑒∈𝐺.outgoingEdges 𝑣 do if getLabel 𝑒 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷) then 𝑤←𝐺.opposite(𝑣,𝑒) 𝑆.push 𝑒 if getLabel 𝑤 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then setLabel(𝑒, 𝐷𝐼𝑆𝐶𝑂𝑉𝐸𝑅𝑌) cycleDFS 𝐺, 𝑤 𝑆.pop( ) else 𝑇← empty stack repeat 𝑇.push(S.pop()) until 𝑇.top =𝑤 return 𝑇.elements We can specialize the DFS algorithm to find a simple cycle using the template method pattern We use a stack 𝑆 to keep track of the path between the start vertex and the current vertex As soon as a back edge 𝑣,𝑤 is encountered, we return the cycle as the portion of the stack from the top to vertex 𝑤

Directed DFS A C E B D We can specialize the traversal algorithms (DFS and BFS) to digraphs by traversing edges only along their direction In the directed DFS algorithm, we have four types of edges discovery edges back edges forward edges cross edges A directed DFS starting at a vertex 𝑠 determines the vertices reachable from 𝑠

Reachability DFS tree rooted at 𝑣: vertices reachable from 𝑣 via directed paths A C E D A C E B D F A C E B D F

Strong Connectivity Each vertex can reach all other vertices a g c d e b e f g

Strong Connectivity Algorithm Pick a vertex 𝑣 in 𝐺 Perform a DFS from 𝑣 in 𝐺 If there’s a 𝑤 not visited, print “no” Let 𝐺’ be 𝐺 with edges reversed Perform a DFS from 𝑣 in 𝐺’ Else, print “yes” Running time: 𝑂(𝑛+𝑚) c d e b f a G’: g c d e b f

Strongly Connected Components Maximal subgraphs such that each vertex can reach all other vertices in the subgraph Can also be done in 𝑂(𝑛+𝑚) time using DFS, but is more complicated (similar to biconnectivity). a d c b e f g Biconnectivity – removing any single vertex breaks connectedness { a , c , g } { f , d , e , b }

Graphs 二○一七年十月二十八日 Breadth-First Search C B A E D L0 L1 F L2

Breadth-First Search Breadth-first search (BFS) is a general technique for traversing a graph A BFS traversal of a graph 𝐺 Visits all the vertices and edges of 𝐺 Determines whether 𝐺 is connected Computes the connected components of 𝐺 Computes a spanning forest of 𝐺 BFS on a graph with n vertices and m edges takes 𝑂(𝑛+𝑚) time BFS can be further extended to solve other graph problems Find and report a path with the minimum number of edges between two given vertices Find a simple cycle, if there is one

BFS Algorithm Algorithm BFS(𝐺, 𝑠) 𝐿 0 ← 𝑠 setLabel(𝑠, 𝑉𝐼𝑆𝐼𝑇𝐸𝐷) 𝑖←0 while ¬ 𝐿 𝑖 .isEmpty( ) do 𝐿 𝑖+1 ←∅ for each 𝑣∈ 𝐿 𝑖 do for each 𝑒∈𝐺.outgoingEdges(𝑣) do if getLabel 𝑒 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then 𝑤←𝐺.opposite 𝑣, 𝑒 if getLabel 𝑤 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then setLabel(𝑒, 𝐷𝐼𝑆𝐶𝑂𝑉𝐸𝑅𝑌) setLabel(𝑤, 𝑉𝐼𝑆𝐼𝑇𝐸𝐷) 𝐿 𝑖+1 ← 𝐿 𝑖+1 ∪ 𝑤 else setLabel(𝑒, 𝐶𝑅𝑂𝑆𝑆) 𝑖←𝑖+1 The algorithm uses a mechanism for setting and getting “labels” of vertices and edges Algorithm BFS(𝐺) Input: Graph 𝐺 Output: Labeling of the edges and partition of the vertices of 𝐺 for each 𝑣∈𝐺.vertices do setLabel(𝑣, 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷) for each 𝑒∈𝐺.edges( ) do setLabel(𝑒, 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷) for each 𝑣∈𝐺.vertices( ) do if getLabel 𝑣 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then BFS 𝐺, 𝑣

Example unexplored vertex visited vertex unexplored edge C B A E D L0 L1 F A unexplored vertex A visited vertex unexplored edge discovery edge cross edge C B A E D L0 L1 F C B A E D L0 L1 F

Example L0 L1 L0 L1 L2 L0 L1 L2 L0 L1 L2 A C B A E D F C B A E D F C B discovery edge cross edge visited vertex A unexplored vertex unexplored edge Example C B A E D L0 L1 F C B A E D L0 L1 F L2 C B A E D L0 L1 F L2 C B A E D L0 L1 F L2

Example L0 L1 L2 L0 L1 L2 L0 L1 L2 A C B A E D F C B A E D F C B A E D discovery edge cross edge visited vertex A unexplored vertex unexplored edge Example C B A E D L0 L1 F L2 C B A E D L0 L1 F L2 C B A E D L0 L1 F L2

Exercise BFS Algorithm Perform BFS of the following graph, start from vertex A Assume adjacent edges are processed in alphabetical order Number vertices in the order they are visited and note the level they are in Label edges as discovery or cross edges C B A E D F

Properties Notation Property 1 Property 2 Property 3 L0 L1 L2 C B A E D F Notation 𝐺 𝑠 : connected component of 𝑠 Property 1 BFS(𝐺, 𝑠) visits all the vertices and edges of 𝐺 𝑠 Property 2 The discovery edges labeled by BFS 𝐺, 𝑠 form a spanning tree 𝑇 𝑠 of 𝐺 𝑠 Property 3 For each vertex 𝑣∈ 𝐿 𝑖 The path of 𝑇 𝑠 from 𝑠 to 𝑣 has 𝑖 edges Every path from 𝑠 to 𝑣 in 𝐺 𝑠 has at least 𝑖 edges C B A E D L0 L1 F L2

Analysis Setting/getting a vertex/edge label takes O(1) time Each vertex is labeled twice once as UNEXPLORED once as VISITED Each edge is labeled twice once as DISCOVERY or CROSS Each vertex is inserted once into a sequence 𝐿 𝑖 Method outgoingEdges( ) is called once for each vertex BFS runs in 𝑂 𝑛+𝑚 time provided the graph is represented by the adjacency list structure Recall that Σ 𝑣 deg 𝑣 =2𝑚

Applications Using the template method pattern, we can specialize the BFS traversal of a graph 𝐺 to solve the following problems in 𝑂 𝑛+𝑚 time Compute the connected components of 𝐺 Compute a spanning forest of 𝐺 Find a simple cycle in 𝐺, or report that 𝐺 is a forest Given two vertices of 𝐺, find a path in 𝐺 between them with the minimum number of edges, or report that no such path exists

DFS vs. BFS Applications DFS BFS DFS BFS Spanning forest, connected components, paths, cycles  Shortest paths Biconnected components C B A E D L0 L1 F L2 C B A E D F Biconnected component – the component remains connected if any vertex is removed DFS BFS

DFS vs. BFS Back edge 𝑣, 𝑤 Cross edge 𝑣, 𝑤 DFS BFS 𝑤 is an ancestor of 𝑣 in the tree of discovery edges Cross edge 𝑣, 𝑤 𝑤 is in the same level as 𝑣 or in the next level in the tree of discovery edges C B A E D L0 L1 F L2 C B A E D F DFS BFS

Topological Ordering Shortest Path 10/28/2017 12:38 AM BOS ORD JFK SFO MIA ORD LAX DFW SFO

DAGs and Topological Ordering B A D C E DAG G A directed acyclic graph (DAG) is a digraph that has no directed cycles A topological ordering of a digraph is a numbering 𝑣 1 ,…, 𝑣 𝑛 Of the vertices such that for every edge 𝑣 𝑖 , 𝑣 𝑗 , we have 𝑖<𝑗 Example: in a task scheduling digraph, a topological ordering a task sequence that satisfies the precedence constraints Theorem - A digraph admits a topological ordering if and only if it is a DAG B A D C E Topological ordering of G v1 v2 v3 v4 v5

Application Scheduling: edge (𝑎,𝑏) means task 𝑎 must be completed before 𝑏 can be started The good life ics141 ics131 ics121 ics53 ics52 ics51 ics23 ics22 ics21 ics161 ics151 ics171

Exercise Topological Sorting more c.s. write c.s. program dream about graphs play wake up eat nap study computer sci. work out sleep A typical student day bake cookies Number vertices, so that 𝑢,𝑣 in 𝐸 implies 𝑢<𝑣

Exercise Topological Sorting more c.s. write c.s. program bake cookies dream about graphs play wake up eat nap study computer sci. work out sleep A typical student day 1 2 3 4 5 6 7 8 9 10 11 Number vertices, so that 𝑢,𝑣 in 𝐸 implies 𝑢<𝑣

Algorithm for Topological Sorting Algorithm TopologicalSort 𝐺 𝐻←𝐺 𝑛←𝐺.numVertices while ¬𝐻.isEmpty do Let 𝑣 be a vertex with no outgoing edges Label 𝑣←𝑛 𝑛←𝑛−1 𝐻.removeVertex 𝑣

Implementation with DFS Simulate the algorithm by using depth-first search 𝑂(𝑛+𝑚) time. Algorithm topologicalDFS 𝐺 Input: DAG 𝐺 Output: Topological ordering of 𝑔 𝑛←𝐺.numVertices Initialize all vertices as 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 for each vertex 𝑣∈𝐺.vertices do if getLabel 𝑣 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then topologicalDFS 𝐺, 𝑣 Algorithm topologicalDFS 𝐺,𝑣 Input: DAG 𝐺, start vertex 𝑣 Output: Labeling of the vertices of 𝐺 in the connected component of 𝑣 setLabel(𝑣, 𝑉𝐼𝑆𝐼𝑇𝐸𝐷) for each 𝑒∈𝐺.outgoingEdges 𝑣 do 𝑤←𝐺.opposite(𝑣, 𝑒) if getLabel 𝑤 =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then //𝑒 is a discovery edge topologicalDFS 𝐺, 𝑤 else //𝑒 is a forward, cross, or back edge Label 𝑣 with topological number 𝑛 𝑛←𝑛−1

Topological Sorting Example

Topological Sorting Example 9

Topological Sorting Example 8 9

Topological Sorting Example 7 8 9

Topological Sorting Example 7 8 6 9

Topological Sorting Example 7 8 5 6 9

Topological Sorting Example 7 4 8 5 6 9

Topological Sorting Example 7 4 8 5 6 3 9

Topological Sorting Example 2 7 4 8 5 6 3 9

Topological Sorting Example 2 7 4 8 5 6 1 3 9