Question: 3 . a ) Let T = ( V , E ) be a tree with the child lists Adj [ v ] , which
a Let T V E be a tree with the child lists Adjv which list vs children, and where each vertex v has a preloaded color
vcolor that equals r or g and a field vcount.
Present a linear time DFS that stores, in each vcount, the largest number of gcolored vertices on any ONE path that starts
at v and runs down to a tree leaf. So for all paths that start at v you want to use the path with the largest gcount. This
count includes v if vcolor g
b Let D V E be a DAG. Present a linear time ieV Etime DFS that stores, in each vcount, the largest
number of gcolored vertices on any ONE path that starts at v and runs down to a tree leaf. So for all paths that start at v
you want to use the path with the largest gcount. This count includes v if vcolor g
Comments: You need a driver to ensure that all leaflike vertices are processed. You are free to give v additional fields if needed.
You cannot afford to process a vertex repeatedly. Your coding will be simpler of you steal Tarjans I dont care where I start
idea as used in the driver for his postorder reverse topological sort.
c Let D V E be DAG. Present a linear time ieV Etime DFS that stores, in each vcount, the largest number
of consecutive gcolored vertices on any path where the path but not nessarily that sequence of consecutive gvertices starts
at v and runs down to a leaflike vertex in D Comments: Reread part bs comments above. They all apply here as well. In
addition, you probably need to compute two counts for each v One is the solution vcount. The other is vfromme, which
counts the largest number of consecutive g vertices on any DAG path that descends from v and where the vfromme count of
consecutive green vertices must begin with vcolor. So vfromme must be zero if vcolor r
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
