hw6sol - Homework 6 Oral Presentations Name NetID #1 (a)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Homework 6 Oral Presentations Name NetID #1 (a) (b) (c) 1 2 1 1 1 2 1 1 Total Indiv. Group Average #2 (a) (b) 1 3 1 1 3 1 Total Indiv. Group Average #3 2½ 2½ 3 2 Scale Total Indiv. Group Average 1 CS 473 Homework 6 Solutions Spring 2010 1. Describe and analyze an algorithm to compute the size of the largest connected component of black pixels in an n × n bitmap B [ 1.. n ,1.. n ] . (a) Solution: Treat the bitmap as a graph, with a vertex for every black pixel and an edge between every adjacent pair of black pixels. Each black pixel is adjacent to at most four other black pixels, in the four compass directions. Thus, this graph has at most n 2 vertices and at most 2 n 2 edges. It’s not necessary to actually compute the adjacency list for this graph; we can get all the information our algorithm needs directly from the bitmap. Now every black component in the bitmap is just a connected component in the graph. We can compute the size of any component with whatever-first search, by incrementing a counter whenever we mark a vertex. We traverse every component of the bitmap with the T RAVERSEALL wrapper algorithm, keeping track of the largest component seen so far. The running time of the algorithm is O ( V + E ) = O ( n 2 ) . Rubric: 4 points max = 1 for correctly interpreting the bitmap as a graph + 2 for WFS + 1 for time analysis. The running time must be expressed as a function of the input parameter n , not V and E . (b) Design and analyze an algorithm B LACKEN ( i , j ) that colors the pixel B [ i , j ] black and returns the size of the largest black component in the bitmap. For full credit, the amortized running time of your algorithm (starting with an all-white bitmap) must be as small as possible. Solution: We maintain a disjoint sets (“U NION-FIND”) data structure, where the elements are black pixels and the sets are connected black components. In addition, every set stores its number of elements; this requires one extra line in the U NION algorithm. We also maintain the size of the largest set in a separate global variable, biggest . Initially, we have an all-white bitmap, represented by the empty collection of sets, and biggest = 0. To simplify the B LACKEN algorithm, we add a one-pixel buffer of white pixels all around the input bitmap during...
View Full Document

This note was uploaded on 04/18/2011 for the course CS 473 taught by Professor Chekuri,c during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 5

hw6sol - Homework 6 Oral Presentations Name NetID #1 (a)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online