1 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Applications. [ chemistry, materials.

Slides:



Advertisements
Similar presentations
Chapter Objectives To learn about recursive data structures and recursive methods for a LinkedList class To understand how to use recursion to solve the.
Advertisements

Chapter 17 Recursion.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 7: Recursion Java Software Structures: Designing and Using.
CS203 Lecture 15.
PLDI’2005Page 1June 2005 Example (C code) int double(int x) { return 2 * x; } void test_me(int x, int y) { int z = double(x); if (z==y) { if (y == x+10)
1 Convert this problem into our standard form: Minimize 3 x x 2 – 6 x 3 subject to 1 x x 2 – 3 x 3 ≥ x x 2 – 6 x 3 ≤ 5 7 x 1.
CS 267: Automated Verification Lecture 10: Nested Depth First Search, Counter- Example Generation Revisited, Bit-State Hashing, On-The-Fly Model Checking.
1 Depth First Search dfs(0, 0) open site blocked site reachable from top via open sites.
Graphs - II CS 2110, Spring Where did I leave that book?
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
CS 261 – Recitation 9 & 10 Graphs & Final review
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
COS 126 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
Multidimensional arrays Many problems require information be organized as a two- dimensional or multidimensional list Examples –Matrices –Graphical animation.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs CS-240/341. Uses for Graphs computer networks and routing airline flights geographic maps course prerequisite structures tasks for completing a.
CS 261 – Data Structures Graphs. Used in a variety of applications and algorithms Graphs represent relationships or connections Superset of trees (i.e.,
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CS305j Introduction to Computing Two Dimensional Arrays 1 Topic 22 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right.
The Power of Calling a Method from Itself Svetlin Nakov Telerik Corporation
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Recursion. Recursive Methods HAVE: 1.A base case or termination condition that causes the method to end 2.A non-base case whose actions move the algorithm.
Slides from Kevin Wayne on Union- Find and Percolotion.
Two Dimensional Arrays
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
Review Recursion Call Stack. Two-dimensional Arrays Visualized as a grid int[][] grays = {{0, 20, 40}, {60, 80, 100}, {120, 140, 160}, {180, 200, 220}};
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
“Planning is bringing the future into the present so that you can do something about it now.” – Alan Lakein Thought for the Day.
Multidimensional Arrays. 2 Two Dimensional Arrays Two dimensional arrays. n Table of grades for each student on various exams. n Table of data for each.
Two Dimensional Arrays. Two-dimensional Arrays Declaration: int matrix[4][11]; 4 x 11 rows columns
CompSci 100E 3.1 Random Walks “A drunk man wil l find his way home, but a drunk bird may get lost forever”  – Shizuo Kakutani Suppose you proceed randomly.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Problem Set 5: Problem 2 22C:021 Computer Science Data Structures.
COS 126 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
GRAPHS. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different implementations.
COS 126 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
1 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
Where’s the title? You gotta search for it!. PotW Solution String s = new Scanner(System.in).next(); int[] prev = new int[s.length() * 2 + 2]; Arrays.fill(prev,
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
CS 100Lecture 171 CS100A Lecture 17 n Previous Lecture –Programming concepts n Two-dimensional arrays –Java Constructs n Constructors for two-dimensional.
CompSci 100E 4.1 Google’s PageRank web site xxx web site yyyy web site a b c d e f g web site pdq pdq.. web site yyyy web site a b c d e f g web site xxx.
NETWORK FLOWS Shruti Aggrawal Preeti Palkar. Requirements 1.Implement the Ford-Fulkerson algorithm for computing network flow in bipartite graphs. 2.For.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: Graphs Data Structures.
2.4 A Case Study: Percolation Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008.
1 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Applications. [ chemistry, materials.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
Lecture 11 Graph Algorithms
Compsci 201, Union-Find Algorithms
Java Software Structures: John Lewis & Joseph Chase
Data Structures and Algorithms for Information Processing
Chapter 12 Recursion (methods calling themselves)
Multidimensional Arrays
COS 126 – Atomic Theory of Matter
COS 126 – Atomic Theory of Matter
Search Related Algorithms
Trees-2, Graphs Data Structures with C Chpater-6 Course code: 10CS35
Lecture 10 Graph Algorithms
2.4 A Case Study: Percolation
Presentation transcript:

1 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Applications. [ chemistry, materials science, … ] n Chromatography. n Spread of forest fires. n Natural gas through semi-porous rock. n Flow of electricity through network of resistors. n Permeation of gas in coal mine through a gas mask filter. n …

2 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Abstract model. N -by- N grid of sites. n Each site is either blocked or open. open site blocked site

3 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Abstract model. N -by- N grid of sites. n Each site is either blocked or open. n An open site is full if it is connected to the top via open sites. open site blocked site percolates (full site connected to top) full site does not percolate (no full site on bottom row)

4 A Scientific Question Random percolation. Given an N-by-N system where each site is vacant with probability p, what is the probability that system percolates? Remark. Famous open question in statistical physics. Recourse. Take a computational approach: Monte Carlo simulation. no known mathematical solution p = 0.3 (does not percolate) p = 0.4 (does not percolate) p = 0.5 (does not percolate) p = 0.6 (percolates) p = 0.7 (percolates)

5 Data Representation Data representation. Use one N -by- N boolean matrix to store which sites are open; use another to compute which sites are full open[][] shorthand: 0 for blocked, 1 for open blocked site open site

6 Data Representation Data representation. Use one N -by- N boolean matrix to store which sites are open; use another to compute which sites are full. Standard array I/O library. Library to support reading and printing 1- and 2-dimensional arrays full[][] shorthand: 0 for not full, 1 for full full site

7 Vertical Percolation Next step. Start by solving an easier version of the problem. Vertical percolation. Is there a path of open sites from the top to the bottom that goes straight down?

8 Vertical Percolation Q. How to determine if site (i, j) is full? A. It's full if (i, j) is open and (i-1, j) is full. Algorithm. Scan rows from top to bottom. row i-1 row i

9 Vertical Percolation Q. How to determine if site (i, j) is full? A. It's full if (i, j) is open and (i-1, j) is full. Algorithm. Scan rows from top to bottom. public static boolean[][] flow(boolean[][] open) { int N = open.length; boolean[][] full = new boolean[N][N]; for (int j = 0; j < N; j++) full[0][j] = open[0][j]; for (int i = 1; i < N; i++) for (int j = 0; j < N; j++) full[i][j] = open[i][j] && full[i-1][j]; return full; } find full sites initialize

10 Vertical Percolation: Testing Testing. Add helper methods to generate random inputs and visualize using standard draw. public class Percolation {... // return a random N-by-N matrix; each cell true with prob p public static boolean[][] random(int N, double p) { boolean[][] a = new boolean[N][N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) a[i][j] = StdRandom.bernoulli(p); return a; } // plot matrix to standard drawing public static void show(boolean[][] a, boolean foreground) }

11 General Percolation: Recursive Solution Percolation. Given an N -by- N system, is there any path of open sites from the top to the bottom. Depth first search. To visit all sites reachable from i-j: n If i-j already marked as reachable, return. n If i-j not open, return. n Mark i-j as reachable. n Visit the 4 neighbors of i-j recursively. Percolation solution. n Run DFS from each site on top row. n Check if any site in bottom row is marked as reachable. not just straight down

12 Depth First Search: Java Implementation public static boolean[][] flow(boolean[][] open) { int N = open.length; boolean[][] full = new boolean[N][N]; for (int j = 0; j < N; j++) if (open[0][j]) flow(open, full, 0, j); return full; } public static void flow(boolean[][] open, boolean[][] full, int i, int j) { int N = full.length; if (i = N || j = N) return; if (!open[i][j]) return; if ( full[i][j]) return; full[i][j] = true; // mark flow(open, full, i+1, j); // down flow(open, full, i, j+1); // right flow(open, full, i, j-1); // left flow(open, full, i-1, j); // up }