Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

Similar documents
b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

CS 461, Lecture 17. Today s Outline. Example Run

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

COMP108 Algorithmic Foundations

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

CS 241 Analysis of Algorithms

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

Planar Upward Drawings

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

0.1. Exercise 1: the distances between four points in a graph

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

1 Introduction to Modulo 7 Arithmetic

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

1. Determine whether or not the following binary relations are equivalence relations. Be sure to justify your answers.

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

QUESTIONS BEGIN HERE!

CSI35 Chapter 11 Review

12. Traffic engineering

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

QUESTIONS BEGIN HERE!

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

Jonathan Turner Exam 2-10/28/03

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

Garnir Polynomial and their Properties

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Constructive Geometric Constraint Solving

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

Outline. Binary Tree

Chapter 18. Minimum Spanning Trees Minimum Spanning Trees. a d. a d. a d. f c

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

Present state Next state Q + M N

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Section 10.4 Connectivity (up to paths and isomorphism, not including)

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

N=4 L=4. Our first non-linear data structure! A graph G consists of two sets G = {V, E} A set of V vertices, or nodes f

EE1000 Project 4 Digital Volt Meter

Numbering Boundary Nodes

Examples and applications on SSSP and MST

14 Shortest Paths (November 8)

Solutions to Homework 5

Section 3: Antiderivatives of Formulas

Minimum Spanning Trees

CS September 2018

Problem solving by search

Chem 104A, Fall 2016, Midterm 1 Key

Trees as operads. Lecture A formalism of trees

Weighted Graphs. Weighted graphs may be either directed or undirected.

Binomials and Pascal s Triangle

Instructions for Section 1

Graph Contraction and Connectivity

Module 2 Motion Instructions

Floating Point Number System -(1.3)

Floating Point Number System -(1.3)

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Designing A Concrete Arch Bridge

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

OpenMx Matrices and Operators

CS 103 BFS Alorithm. Mark Redekopp

Complete Solutions for MATH 3012 Quiz 2, October 25, 2011, WTT

(a) v 1. v a. v i. v s. (b)

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

13. Binary tree, height 4, eight terminal vertices 14. Full binary tree, seven vertices v 7 v13. v 19

SOLVED EXAMPLES. be the foci of an ellipse with eccentricity e. For any point P on the ellipse, prove that. tan

Construction 11: Book I, Proposition 42

Seven-Segment Display Driver

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Organization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs

Transcription:

CS Avn Dt Struturs n Algorithms Exm Solution Jon Turnr //. ( points) Suppos you r givn grph G=(V,E) with g wights w() n minimum spnning tr T o G. Now, suppos nw g {u,v} is to G. Dsri (in wors) mtho or trmining i T is still minimum spnning tr or G. Exmin th pth in T rom u to v. I ny vrtx on this pth hs wight lrgr thn tht o th nw g, thn T is no longr n MST. W n moiy T to otin nw MST y rmoving th mx wight g on this pth n rpling it with th nw g. Explin how your mtho n implmnt to run in O(n) tim i oth G n T r provi s instns o th wgrph t strutur. Using th wgrph or T, w n o rursiv tr trvrsl in T, strting t vrtx u. On th trvrsl rhs v, w unwin th rursion, n s w o so, w look or th mx wight g long th u,v pth. Th runtim or tr trvrsl is O(n) n th rquir hngs to T n on in onstnt tim. Suppos tht inst o singl g, you r givn st o k nw gs to to G. For smll nough k it mks sns to pply your lgorithm rptly in orr to upt th MST, ut i k is too lrg, it s mor iint to r-omput th MST rom srth. How ig os k hv to (s untion o m n n) in orr or this to ttr hoi? Assum tht th MST is omput using Prim s lgorithm with -hp, whr =. Whn =, th running tim or Prim s lgorithm is O(m log n), so i kn grows str thn this, it mks sns to romput rom srth. So, i k>(m/n) log n, it mks sns to romput th MST. - -

. ( points) Suppos w pply Dijkstr s lgorithm to th grph shown low, strting rom vrtx. 7-8 8-6 g h - j i 7 6 List th irst 7 vrtis tht r snn.,,,,g,h,j In th igrm ll h vrtx with its tnttiv istn tr th irst 7 vrtis r snn n init th prnt pointr o h vrtx using n rrow pointing rom h vrtx to its prnt. List th nxt two vrtis to snn. i,j List th nxt six.,g,h,j,i,j Wht is th totl numr o snning stps tht Dijkstr s lgorithm will prorm on this grph? Th numr o stps is +(+())=9. I you xtn th grph y ing ourth imon to th lt, with g lngths o 8, 8, n -, how mny stps woul Dijkstr s lgorithm us or this grph? +(9)=6 - -

. ( points ) Consir Fioni hp ontining n unmrk no x or whih p(x), p (x),..., p 9 (x) r ll mrk, ut p (x) is not (whr p(x) is th prnt o x, p (x) th grnprnt, n so orth). Suppos tht ruky oprtion is prorm t x tht mks th ky o x smllr thn th ky o p(x). Do ny prviously unmrk nos om mrk s rsult o this oprtion? I so, whih ons? Assum tht p (x) is not tr root. p (x) oms mrk. I k is th numr o rits n to mintin th rit invrint, in th mortiz nlysis or th ruky oprtion, how mny rits r n tr th oprtion. Th numr o mrk non-root nos gos own y 8, whil th numr o trs gos up y. So, th numr o rits n to mintin th invrint gos own y 6 to k 6. Rll tht uring ltmin, th si stp involvs insrting tr root into n rry, t position trmin y its rnk. In som stps, th urrnt tr root ollis with tr root tht ws insrt rlir. In othr stps, thr is no ollision. Suppos tht ltmin is on on this hp n tht uring th ltmin, thr r stps uring whih no ollision ours. Giv n xprssion (in trms o φ=(+ / )/) tht rprsnts lowr oun on th numr o nos in th hp. Justiy your nswr. I thr ltmin stps with no ollision, thn t th n o th ltmin, thr must som no with rnk t lst qul to 9. From th nlysis w know tht th numr o nos in hp with rnk k is t lst φ k, so φ 7 in this s. W n tully gt ttr lowr oun y noting tht i thr wr stps with no ollision, thn tr th ltmin, th hp ontins t lst trs with rnks o t lst,,,,,...,9. Consquntly, th numr o nos in th hp is t lst +φ+φ + +φ 7. - -

. ( points) Th rsiul grph shown low is or som low on low grph G. s 7 t Wht is th pity o th g onnting n in G? Justiy your nswr. This g hs pity 7 in th rsiul grph us th sum o th rsiul pitis in opposit irtions is qul to th originl pity. Is th g in G irt rom to or rom to. Justiy your nswr. (Hint: onsir th totl inoming low t.) You my ssum tht thr is no mor thn on g joining ny two vrtis, ut you shoul not ssum nything out th irtion o th gs t s n t (tht is, G my hv gs ntring s or lving t). Consir vrtx. Sin this is not th sour or th sink, it must stisy low onsrvtion. For h or its thr inint gs, thr r two possil low vlus ntring. For th g, th inlow is ithr or. For th t g, th inlow is ithr or -. For th g, th inlow is ithr or -. Sin th sum o th inlows must, th inlow on th g must, th inlow on th t g must - n th inlow on th g must. This implis tht th g is irt rom to. Fin shortst ugmnting pth rltiv to. Drw th rsiul grph tht rsults rom ing s muh low s possil to this pth. Th pth is st n th nw rsiul grph pprs low. s t - -

. ( points) Lt R rsiul grph or min-ost low, lt p sour-sink pth in R with ost n lt q sour-sink pth in R with ost. Lt + th low w gt whn w nough low to p to sturt it n lt R + th rsulting low grph. Dos R ontin ngtiv yl? Explin your nswr. No, us is min-ost low n min-ost lows nnot ontin ngtiv yls. I R + hs no ngtiv yl, wht os tht tll us out p? Explin. It implis tht p is min-ost ugmnting pth, us th sn o ngtiv yl implis tht R + is min-ost low n sin w otin + y ugmnting long p, it ollows tht p is min-ost ugmnting pth. I < os R + ontin ngtiv yl. Explin. Ys. < implis tht p is not min-ost ugmnting pth, so + must not min-ost low, n th rsiul grph or non min-ost low must ontin ngtiv yl. I (u,v) is in R + ut not in R, wht os tht tlls us out (u,v)? Explin. It tlls us tht (v,u) is on p, sin nw g n only pprs in th rsiul grph whn low is in th opposit irtion. I (u,v) is in R ut not in R +, wht os tht tll us out ist (u) n ist (v) (whr ist (x) is th lngth o th shortst pth rom th sour s to x in R )? This mns tht (u,v) is on p, so ist (v)=ist (u)+ost(u,v) - -

6. ( points) Th grph t lt low hs ngtiv lngth gs. In th igrm t right, giv trnsorm g lngths tht prsrv th rltiv lngths o shortst pths whil liminting ngtiv g lngths. -9-9 - 7 6 - - 6 - - Th numrs nxt to th vrtis in th lt-hn grph rprsnt th shortst pth istns rom n sour vrtx with zro ost g to h originl vrtx. Th right hn grph shows th trnsorm g lngths omput using ths istn vlus. Lt G n ritrry grph with ngtiv lngth gs n lt lngth (u,v) th trnsorm g lngth or (u,v). Suppos p is pth rom x to y with lngth(p)= 8 n lngth (p)=. I q is nothr pth rom x to y with lngth(q)=7, wht is lngth (q)? lngth (q) = lngth(q) + (lngth (p) - lngth(p)) = 7 + ( - (-8)) = - - 7 In th min-ost ugmnting pth lgorithm (or th min-ost low prolm) using trnsorm g osts, nw shortst pth tr is omput uring h stp, n th shortst pth istns r us to moiy th g osts. Wht is th totl ost o th gs in th shortst pth tr, using th nwly moii osts? Explin. Th totl ost is. For h g (u,v), th nw ost (u,v) = ost(u,v) + ist(u) ist(v). I (u,v) is n g in th shortst pth tr, thn ist(v) = ist(u) + ost(u,v), n hn ost (u,v)=. Sin this is tru or ll gs in th shortst pth tr, th totl ost is. - 6 -

7. ( points) In th gr-onstrin sugrph prolm, w r givn grph G=(V,E) n gr oun (u) or vry vrtx u. Th ojtiv is to in sugrph o G in whih vry vrtx u hs t most (u) inint gs. In th grph t right, in gr-onstrin sugrph with 6 gs. Init th gs in th sugrph y mking thm hvir wight. In th wight vrsion o th prolm, h g hs wight w() n w r intrst in th gr-onstrin sugrph o mximum wight. Dsri (in wors) n lgorithm to solv this prolm whn th grph is iprtit. Us th grph shown t right to illustrt your solution. (You n not tully prou mx wight sugrph.) Not tht th shps o th vrtis in th ivision o th vrtis into susts. W solv th prolm y onvrting it to min-ost low prolm, s w i or th mx wight mthing prolm. Tht is, w sour vrtx with n g to vry vrtx in th lt sust o vrtis n sink with n g rom vry vrtx in th right sust. Th gs (s,u) hv pity (u) n ost. Th gs (u,t) hv pity (u) n ost. Eh originl g {u,v} is turn into irt g rom th lt vrtx u to v, with ost(u,v)= wt(u,v) n p(u,v)=. W thn low to th grph using th min-ost ugmnting pth mtho. Th lgorithm hlts or ining mximum low i th nxt min-ost ugmnting pth hs non-ngtiv ost. At tht point th gs in th ntrl prt o th grph tht hv positiv low in gr-oun sugrph o mximum wight. g 6 g pity, ost s,,,,,-,-6,-,-,-,-,-,-,- g,,, t - 7 -