Jotto! JRsSRsElderly A word-guessing game similar to mastermind… slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate.

Slides:



Advertisements
Similar presentations
Jotto! JRsSRsElderly slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate 1 This term's last class to have its word.
Advertisements

§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
Jotto! JRsSRs other diner 1 This term's first class to guess another's word earns 1 problem... diner 1diner 2 This term's last class to have its word guessed.
Greed is good. (Some of the time)
ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Jotto! SophsJrsSrs audio 1audio 2audio 1 Frosh audio 2 graze 3graze 1 graze 2 alloy 1 alloy 2 fresh 2fresh 1fresh 2fresh 1 This term's first class to guess.
Chapter 3 The Greedy Method 3.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Searching/Sorting Introduction to Computing Science and Programming I.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 Algorithms and Analysis CS 2308 Foundations of CS II.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
WEIGHTED GRAPHS. Weighted Graphs zGraph G = (V,E) such that there are weights/costs associated with each edge Õw((a,b)): cost of edge (a,b) Õrepresentation:
The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Greedy methods Prudence Wong
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
© Peter Andreae CS4HS Algorithms Searching for an item in a list Sorting a list Searching for a word in text Analysing Networks.
ACM Welcome! Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Binary Search From solving a problem to verifying an answer.
ACM today! Nice work to everyone in the qualifiers and evening lab... Today: BS! Next 11/2: guest speaker... On 11/9: final lab session 11/13: regionals.
Curricularizing the ACM... ? Zach Dodds ~ November 13, 2010.
알고리즘 설계 및 분석 Foundations of Algorithm 유관우. Digital Media Lab. 2 Chap4. Greedy Approach Grabs data items in sequence, each time with “best” choice, without.
CPSC 320: Intermediate Algorithm Design & Analysis Greedy Algorithms and Graphs Steve Wolfman 1.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
CSCI2100 Data Structures Tutorial 12
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
Harbin, China 2010 finals ACM today… ! (2009) Knapsack DP for NP! Floyd-Warshall DP for APSP! Max Flow.
Searching/Sorting. Searching Searching is the problem of Looking up a specific item within a collection of items. Searching is the problem of Looking.
Shortest Paths.
Minimum Spanning Trees
Randomized Min-Cut Algorithm
CSCE 411 Design and Analysis of Algorithms
COMP108 Algorithmic Foundations Greedy methods
ACM so far… Sep 6 Welcome! and DP problems ~ 5 problems
Shortest Paths and Minimum Spanning Trees
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Lesson Objectives Aims Understand the following “standard algorithms”:
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2
Graph Algorithm.
Minimum Spanning Tree.
Minimum Spanning Trees
Shortest Paths.
CSE 373 Data Structures and Algorithms
Jotto! Sophs Jrs Srs Profs pluot 1 pluot 2 pluot 1 pluot 2 squid 2
Graph Searching.
ACM today… ! DP for NP! DP for APSP! Knapsack Floyd-Warshall
CSCI2100 Data Structures Tutorial
CSE 373: Data Structures and Algorithms
Graphs.
What is Computer Science About? Part 2: Algorithms
Shortest Paths.
Minimum spanning trees
CSE 373: Data Structures and Algorithms
Lecture 14 Minimum Spanning Tree (cont’d)
Presentation transcript:

Jotto! JRsSRsElderly A word-guessing game similar to mastermind… slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate 1 This term's last class to have its word guessed earns 1 problem... Sophs slate 1 flair 0flair 1flair 2flair 0 Pomona slate 3 flair 2 stems 3stems 1stems 2stems 1stems 2 flair 0flair 1flair 2flair 0flair 2 stems 3stems 1stems 2stems 1stems 2

ACM today “Nice” enforcement One of our Nice enforcers! Be nice! "HAL" Stuart and Paul Carl Problem-solving strategies...

ACM today “Nice” enforcement One of our Nice enforcers! Be nice! "HAL" Stuart and Paul Carl Problem-solving strategies... nice -19 /cs/ACM/acmSubmit file.X does this work?

Remote broadcast message (Tue Feb 1 21:59: ): Attention Knuth users: if you are currently experiencing excruciating slowness, that is because several people have been running Practicum problems without nicing them. THIS IS BAD. If you think that a program you are running might be using a lot of CPU and/or RAM for longer than a few seconds, please nice it like so: nice -n 19 [your process] If you've already started running a process that you think might need to be niced, there are plenty of ways to do so: 1. Invoke "renice" from the command line: renice -n 19 [process id] 2. Open "top", hit 'r', and type in the PID of the process you want to renice, and then give it the priority (19 unless you have good reason to do otherwise). 3. Open "htop", find your process, and repeatedly hit F8 to increase its niceness. ACM today Problem-solving strategies... “Nice” enforcement One of our Nice enforcers! Being nice...

Today: two graph algorithms APSP all-pairs shortest paths MST minimum spanning tree Floyd-Warshall algorithm Prim's algorithm

Floyd Warshall ! Directed graph as adjacency matrix: Directed graph: src "from" dst "to" 100inf inf50 14 inf intermediate nodes an algorithm that finds ALL shortest paths

Thanks, Kevin!

Idea: consider waypoints 1 at a time src "from" dst "to" 100inf inf50 14 inf intermediate nodes check each src to each dst THROUGH 1 Step 1 1 entry will change – which?

src "from" dst "to" 100inf inf50 14 inf intermediate node(s) 1 check each src to each dst THROUGH Step entries will change – which?

src "from" dst "to" inf50 14 inf intermediate node(s) 1 check each src to each dst THROUGH Step 3 2 entries will change – which?

src "from" dst "to" inf28 14 inf intermediate node(s) 1 check each src to each dst THROUGH Step 3 3 entries will change – which?

src "from" dst "to" intermediate node(s) 1 O( ) Done! Minimum distance from src to dst using intermediate nodes 1..k min T[src][dst][k] = T[src][dst][k-1] T[src][k][k-1] + T[k][dst][k-1]

Kevin Oelze's code is available on the ACM website – see if you can spot the FW problem this week... min = T[src][dst][k-1] T[src][k][k-1] + T[k][dst][k-1] T[src][dst][k] use-it-or-lose-it! use k lose k

This week's problems… bestspot meetplace mtwalk phoneline water Alert! A non-FW graph problem! Tree problem... Challenge problems... Floyd Warshall!

MST Minimum spanning tree: (Prim’s algorithm) Goal: find the lowest-cost tree that touches each vertex Strategy: ?

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree. Goal: find the lowest-cost tree that touches each vertex Strategy: Greed!

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree.

MST Minimum spanning tree: (Prim’s algorithm) Start anywhere and repeatedly choose the next- smallest edge out from your current tree. Done!

This week: water Input Cost of drilling a well in each field Cost of placing a pipe from field src to field dst Number of fields needing water src dst Output ? The minimum possible cost to provide water to all of the fields...

This week: water Input Output Cost of drilling a well in each field Cost of placing a pipe from field src to field dst Number of fields needing water 9 The minimum possible cost to provide water to all of the fields... src dst How is this MST?

Jotto! JRsSRsElderly A word-guessing game similar to mastermind… slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate 1 This term's last class to have its word guessed earns 1 problem... Sophs slate 1 flair 0flair 1flair 2flair 0 Pomona slate 3 flair 2 stems 3stems 1stems 2stems 1stems 2 flair 0flair 1flair 2flair 0flair 2 stems 3stems 1stems 2stems 1stems 2

This week: binary search If a desired value is difficult to compute but easy to check and 1d (or broken into 1d subproblems) then we can binary search across all the possible values for it, checking as we go... !

Binary search in a sorted list... LOW Is an item "present" – or is a problem solvable? MIDHIGH 1 1,

Binary search in a sorted list... available on the ACM website in Python

This week: aggr Input Output Number of stalls in which cows can be placed The locations of stalls Number of cows to house in the new barn… 3 The largest minimum spacing possible after placing the cows

aggr in Python (in part) # get the # of stalls (N) and cows (C) S = [] for i in range(N): S += [input()] # get the stalls' locations S.sort() # sort them lo = 0 hi = max(S)-min(S)+1 input

aggr in Python (in part) # get the # of stalls (N) and cows (C) S = [] for i in range(N): S += [input()] # get the stalls' locations S.sort() # sort them lo = 0 hi = max(S)-min(S)+1 while True: mid = (lo + hi)/2 # no overflow in Python, right? if mid == hi or mid == lo: break # does mid work? if CHECKS_OUT( mid, C, S ): lo = mid # worked! look higher (set lo to mid) else: hi = mid # did not work... look lower (set hi to mid) print mid binary search input still left to do?

This bug went undetected in Java's libraries for years...

This week's problems… phoneline hunger aggr cowblank btwr this problem is only for those new to ACM... but if you're returning, you can solve it in web-form for credit: you should use HTML 5's canvas object directly (or libraries that use it) to draw the scenario and results...

Web versions! Web frameworks are welcome... As are libraries, e.g., JQuery and its variants The locations of stalls This week: HMTL 5 canvas objects cows!

This week's problems… phoneline hunger aggr cowblank btwr this problem is only for those new to ACM... but if you're returning, you can solve it in web-form for credit: you should use HTML 5's canvas object directly (or libraries that use it) to draw the scenario and results...

This week: phoneline Input Output # of telephone poles, N 4 The minimium possible length of remaining largest cable needed to connect #1 and #N # of edges available # of cables you get for free #1 is connected to the phone network

Try this week's problems! phoneline hunger aggr cowblank btwr this problem is only for those new to ACM... but if you're returning, you can solve it in web-form for credit: you should use HTML 5's canvas object directly (or libraries that use it) to draw the scenario and results...

Jotto! SophsJrsSrs audio 1audio 2audio 1 Frosh audio 2 graze 3graze 1 graze 2 alloy 1 alloy 2 fresh 2fresh 1fresh 2fresh 1 This term's first class to guess another's word earns 1 problem... This term's last class to have its word guessed earns 1 problem... armor 2 armor 1armor 2 brave 3brave 1 brave 2

Last week: wifi InputOutput The # of access points and the # of houses The # of test cases... Locations of the houses The smallest max distance achievable

This week: city Input Output dist cost of 1 st story # of people to house 194 The minimium cost to house the specified # of people cost per unit distance from (0,0) maximum # of stories per building the central station where everyone works is at (0,0) distances to it are considered to be |x|+|y|-1 0 dist 1 dist 2 dist 1 dist 3 dist

This week: cowset Input Output ID # for 1 st cow # of cows available, up to 34 5 The number of subsets whose IDs sum between min and max minimum ID sum maximum ID sum Farmer Ran is willing to play frisbee with any subset of cows whose IDs sum to any value between the min and max... ID # for 2 nd cow ID # for 3 rd cow Try all subsets...?

This week: cowset Input Output ID # for 1 st cow # of cows available, up to 34 5 The number of subsets whose IDs sum between min and max minimum ID sum maximum ID sum Farmer Ran is willing to play frisbee with any subset of cows whose IDs sum to any value between the min and max... ID # for 2 nd cow ID # for 3 rd cow Takes too long to try all subsets...! How could Bin Search speed it up?

Problem D from the 2009 World Finals in Stockholm: Pipe Packing Given a set of four wire diameters: What is the minimum diameter of pipe that can contain all four wires? (Constraint: pipes only come in millimeter sizes)

A lower bound: sum of largest two wire-diameters An upper bound: sum of all four wire-diameters l Binary search between lower bound and upper bound l Given a pipe diameter and four wire diameters, can you pack the wires inside the pipe? l Choose the smallest integer pipe diameter that fits Intuition: Solve this problem by binary search

Problem D from the 2009 World Finals in Stockholm: Pipe Packing Given a set of four wire diameters: What is the minimum diameter of pipe that can contain all four wires? (Constraint: pipes only come in millimeter sizes)

A lower bound: sum of largest two wire-diameters An upper bound: sum of all four wire-diameters l Binary search between lower bound and upper bound l Given a pipe diameter and four wire diameters, can you pack the wires inside the pipe? l Choose the smallest integer pipe diameter that fits Intuition: Solve this problem by binary search

ACM this week!?