COP 3530 Discussion Session #6 Yilin Shen. Outline Chapter 7 o Q35p 250 o Q39p 265 Chapter 8 o Problem 8.5.3: Rearranging Railroad carsp 289 o Problem.

Slides:



Advertisements
Similar presentations
Lectures on Graph Algorithms: searching, testing and sorting
Advertisements

Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
Lecture 19: Parallel Algorithms
電腦視覺 Computer and Robot Vision I
Queues CSE, POSTECH 2 2 Queues Like a stack, special kind of linear list One end is called front Other end is called rear Additions (insertions or enqueue)
Queue Chapter 9 Stacks Last in first out (LIFO)Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top.
Chapter 8, Part I Graph Algorithms.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
Digital Image Processing Lecture 12: Image Topology
Chapter 2 Matrices Finite Mathematics & Its Applications, 11/e by Goldstein/Schneider/Siegel Copyright © 2014 Pearson Education, Inc.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Contour Tracing Seo, Jong-hoon Media System Lab. Yonsei University.
Lesson 8 Gauss Jordan Elimination
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
1 Lecture 25: Parallel Algorithms II Topics: matrix, graph, and sort algorithms Tuesday presentations:  Each group: 10 minutes  Describe the problem,
Algorithm Design Techniques: Induction Chapter 5 (Except Section 5.6)
1 Parallel Algorithms III Topics: graph and sort algorithms.
Chapter 8 Arrays and Strings
Linear Programming Applications
1 Parallel Algorithms IV Topics: image analysis algorithms.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
CS Data Structures Chapter 3 Stacks and Queues.
Stacks CSE, POSTECH. 2 2 Stacks Linear list One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
EGRE 427 Advanced Digital Design Figures from Application-Specific Integrated Circuits, Michael John Sebastian Smith, Addison Wesley, 1997 Chapter 7 Programmable.
Digital Image Processing
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
Row rows A matrix is a rectangular array of numbers. We subscript entries to tell their location in the array Matrices are identified by their size.
Fundamentals of Python: From First Programs Through Data Structures Chapter 14 Linear Collections: Stacks.
1 More Sorting radix sort bucket sort in-place sorting how fast can we sort?
CS 6825: Binary Image Processing – binary blob metrics
Chapter 8 Arrays and Strings
BSG-Route: A Length-Matching Router for General Topology T. Yan and M. D. F. Wong University of Illinois at Urbana-Champaign ICCAD 2008.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
QUANTITATIVE ANALYSIS FOR MANAGERS TRANSPORTATION MODEL
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Linked List (Part II). Introduction  Definition of equivalence relation: A relation ≡ over a set S, is said to be an equivalence relation over S iff.
Introduction Image geometry studies rotation, translation, scaling, distortion, etc. Image topology studies, e.g., (i) the number of occurrences.
B-Escape: A Simultaneous Escape Routing Algorithm Based on Boundary Routing L. Luo, T. Yan, Q. Ma, M. D.F. Wong and T. Shibuya Department of Electrical.
Digital Image Fundamentals Faculty of Science Silpakorn University.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
For more notes and topics VISIT: IMPLEMENTATION OF STACKS eITnotes.com.
Applications of Stacks and Queues Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
CS654: Digital Image Analysis Lecture 5: Pixels Relationships.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
COSC 2007 Data Structures II
1 Chapter 6 Queues. 2 Topics FIFO (first0in-first0out) structure Implementations: formula-based and linked classes Applications: –railroad-switching problem.
SNU IDB Lab. Ch10. Queues © copyright 2006 SNU IDB Lab.
Nottingham Image Analysis School, 23 – 25 June NITS Image Segmentation Guoping Qiu School of Computer Science, University of Nottingham
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Boolean Logic.
Linear Programming Chap 2. The Geometry of LP  In the text, polyhedron is defined as P = { x  R n : Ax  b }. So some of our earlier results should.
An Algorithm for the Consecutive Ones Property Claudio Eccher.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
1 Chapter 5 Stacks. 2 Topics LIFO (last-in-first-out) structure Implementations –Use class LinearList or Chain –from scratch Applications –parentheses.
Image Sampling and Quantization
IT472: Digital Image Processing
A vertex u is reachable from vertex v iff there is a path from v to u.
Introduction to Polygons
Pushdown Automata.
Constraint Satisfaction Problems vs. Finite State Problems
B+ Tree.
Mathematical Structures for Computer Science Chapter 6
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2002 Bin Sort, Radix.
Lectures on Graph Algorithms: searching, testing and sorting
Queues.
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2001 Bin Sort, Radix.
Computer and Robot Vision I
Prof. Ramin Zabih Graph Traversal Prof. Ramin Zabih
Presentation transcript:

COP 3530 Discussion Session #6 Yilin Shen

Outline Chapter 7 o Q35p 250 o Q39p 265 Chapter 8 o Problem 8.5.3: Rearranging Railroad carsp 289 o Problem 8.5.4: Switch Box Routingp 294 Chapter 9 o Problem 9.5.3: Image-Component Labelingp 341 o Explain the code of Problem 9.5.3

Q35 An n × n square matrix M is an antidiagonal matrix iff all entries M(i, j) with i + j ≠ n + 1 equal zero. o Give a sample of a 4 × 4 antidiagonal matrix. o Show that the antidiagonal matrix M has at most n nonzero entries. o Devise a way to represent an antidiagonal matrix in a one-dimensional array of size n. o Use the representation of (c) to arrive at the code for the C++ class antidiagonalMatrix that includes methods for the get and set operations. o What is the time complexity of your get and set codes? o Test your code.

Solution A sample antidiagonal matrix is given below: In an antidiagonal matrix there can be at most one nonzero entry in each row; for row i, this nonzero entry is in column n+1-i. Therefore, an n x n antidiagonal matrix can have at most n nonzero entries. We can put the antidiagonal element M(i, n+1-j) in position i-1 of a one-dimensional array.

Q39 Suppose that a 500 × 500 matrix that has 2000 nonzero terms is to be represented. How much space is needed when a 500×500 two-dimensional array of type int is used? How much space is needed when sparseMatrix is used? How many nonzero elements must an m × n matrix have before the space required by sparseMatrix exceeds that required by an m × n two-dimensional array? You may assume that T is int.

Solution We shall ignore the space overheads of the array of arrays representation used by C++ and consider only the space for the elements in the 500 x 500 array. At 4 bytes per element, this works out to bytes. When a sparseMatrix is used, we need 12 bytes for each nonzero element. So, the 2000 nonzero element matrix takes bytes. Using the same assumptions as in (a), 4mn bytes are taken by the two-dimensional array representation and 12p (p is the number of nonzero terms) by the sparse matrix representation. The sparse matrix representation takes more space when p > mn/3

Problem 8.5.3: Problem 8.5.3: Rearranging Railroad Cars A freight train has n railroad cars. o Each is to be left at a different station. o Assume that the n stations are numbered 1 through n and that the freight train visits these stations in the order n through 1. The railroad cars are labeled by their destination. To facilitate removal of the railroad cars from the train, we must reorder the cars so that they are in the order 1 through n from front to back. o When the cars are in this order, the last car is detached at each station. We rearrange the cars at a shunting yard that has an input track, an output track, and k holding tracks between the input and output tracks.

Example Figure 8.6(a) shows a shunting yard with k = 3 holding tracks H1, H2, and H3. The n cars of the freight train begin in the input track and are to end up in the output track in the order 1 through n from right to left. In Figure 8.6(a), n = 9; the cars are initially in the order 5, 8, 1, 7, 4, 2, 9, 6, 3 from back to front. Figure 8.6(b) shows the cars rearranged in the desired order. Figure: A three-track example InitialFinal

Solution Strategy To rearrange the cars, we examine the cars on the input track from front to back. o If the car being examined is the next one in the output arrangement, we move it directly to the output track. o If not, we move it to a holding track and leave it there until it is time to place it in the output track. The holding tracks operate in a LIFO manner and only the following moves are permitted o A car may be moved from the front (i.e., right end) of the input track to the top of one of the holding tracks or to the left end of the output track. o A car may be moved from the top of a holding track to the left end of the output track.

Solution of the Example 369 H1H1 H2H2 H3H Input Track Holding Track Output Track 8

Assignment Rule The least restrictions on future car placement arise when the new car u is moved to the holding track that has at its top a car with smallest label v such that v > u Time Complexity o O(numberOfTracks ∗ numberOfCars) o Better Analysis --- Using Binary Search Tree O(numberOfCars ∗ log(numberOfTracks))

Problem 8.5.4: Switch Box Routing Given a rectangular routing region with pins at the periphery, determine routable switch box Pairs of pins are to be connected together by laying a metal path between the two pins. This path is confined to the routing region and is called a wire Wire intersections are forbidden Each pair of pins that is to be connected is called a net Segments that are not parallel to these axes as well as segments that are not straight lines are permissible

Example The wire routing of Figure 8.8(b) has a pair of intersecting wires (those for nets (1, 4) and (2, 3)) The routing of Figure 8.8(c) has no intersections. Since the four nets can be routed with no intersections routable switch box

Solution Strategy Idea: when a net is connected, the wire partitions the routing region into two regions o If there is now a net with one pin in one region and the other in a different region, this new net cannot be routed and the routing instance is unroutable o If there is no net with this property, then since the wires cannot cross between regions, we can attempt to determine whether each region is independently routable

Cont. Suppose the nets for Figure 8.8(a) are (1, 5), (2, 3), (4, 7), and (6, 8), is it routable? Routable if stack is empty at last Time Complexity? O(n) Stack

Problem 9.5.3: Image-Component Labeling A digitized image is an m × m matrix of pixels. In a binary image each pixel is either 0 or 1 o A 0 pixel represents image background o A 1 represents a point on an image component Component Pixels o Two pixels are adjacent if one is to the left, above, right, or below the other o Two component pixels that are adjacent are pixels of the same image component The objective of component labeling is to label the component pixels so that two pixels get the same label iff they are pixels of the same image component

Example A 7 x 7 gridLabeled Components Figure: Image-Component Labeling example

Solution Strategy The components are determined by scanning the pixels by rows and within rows by columns When an unlabeled component pixel is encountered, it is given a component identifier / label. This pixel forms the seed of a new component Determine the remaining pixels in the component by identifying and labeling all component pixels that are adjacent to the seed

Time Complexity Θ(m) time to initialize the wall of background pixels Θ(1) time to initialize offsets For each component O(number of pixels in component) The total time spent identifying and labeling nonseed component pixels is O(number of component pixels in image) Overall Complexity O(m 2 )

Code // initialize offsets position offset[4]; offset[0].row = 0; offset[0].col = 1; // right offset[1].row = 1; offset[1].col = 0; // down offset[2].row = 0; offset[2].col = -1; // left offset[3].row = -1; offset[3].col = 0; // up // initialize wall of 0 pixels for (int i = 0; i <= size + 1; i++) { pixel[0][i] = pixel[size + 1][i] = 0; // bottom and top pixel[i][0] = pixel[i][size + 1] = 0; // left and right }

Cont. // neighbors of a pixel position int numOfNbrs = 4; // scan all pixels labeling components arrayQueue q; position here, nbr; int id = 1; // component id for (int r = 1; r <= size; r++) { for (int c = 1; c <= size; c++) { if (pixel[r][c] == 1) {// new component // get next id pixel[r][c] = ++id; here.row = r; here.col = c; while (true) {// find rest of component for (int i = 0; i < numOfNbrs; i++) {// check all neighbors of here nbr.row = here.row + offset[i].row; nbr.col = here.col + offset[i].col; if (pixel[nbr.row][nbr.col] == 1) {// pixel is part of current component pixel[nbr.row][nbr.col] = id; q.push(nbr); }

// any unexplored pixels in component? if (q.empty()) break; here = q.front(); // a component pixel q.pop(); } // end of if } } // end of for c, and for r

Questions? Have a good evening!