Homework5_Solutions

pdf

School

University of Texas *

*We aren’t endorsed by this school

Course

360C

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

6

Uploaded by ConstableGiraffeMaster829

Report
ECE360C: Algorithms Homework Assignment #5 University of Texas at Austin Due: October 6, 2023 (11:59pm) SOLUTIONS STUDENT CHOICE: Homework Assignment #5 – Solutions Solutions are for individual use only by students registered for ECE 360C in Spring 2023 semester. They should not be otherwise shared or posted. Problem 1: Remember [20 points] Answer the following true/false questions. True False In a directed graph, the number of entries in an adjacency list representation is exactly m . In an undirected graph, we only have to store half of the adjacency matrix, so the adjacency matrix for an undirected graph of n nodes is asymptotically smaller than the adjacency matrix for a directed graph. A graph that is connected and does not contain a cycle will always be a tree. The “frontier” in a BFS search is stored in a (“last-in-first-out”) stack data structure. If T is the tree that results from a depth first search on a graph G , and the edge ( u, v ) exists in G , then either u is the parent of v in T or v is the parent of u in T . A connected graph that has no cycles is guaranteed to have less than n edges. In an undirected graph, if u is in the BFS tree of created with the root being v , then v must be in the BFS tree created with the root being u . For the topological order on a directed graph to exist, the graph must be connected. In a greedy algorithm, we simply make some choice that appears to be the best at the moment. If a greedy algorithm is optimal (i.e., there’s no solution better than taking the greedy choice), it will always be efficient (i.e., have polynomial running times).
Homework Assignment #5: October 6, 2023 (11:59pm) 2 Problem 2: Understand (a) During the execution of depth first search, we refer to an edge that connects a vertex to an ancestor in the DFS-tree as a back edge . Either prove the following statement or provide a counter-example: if G is an undirected, connected graph, then each of its edges is either in the depth-first search tree or is a back edge. Solution This is true. Suppose it were not true. Then there would be an edge in G that is not in the DFS-tree that is also not a back edge. This edge connects a node u to a node v . When u was included in the DFS-tree, we chose not to include ( u, v ) in the DFS-tree. The only reason we would do this was if v had already been included in the DFS-tree. But v is not an ancestor of u in the DFS-tree, so v must be in some other branch of the DFS-tree. But then, when we included v in the DFS-tree (which was before we examined u and u ’s neighbors), we chose not to include the edge ( v, u ). But the only reason we would have done this would have been if u had already been in the DFS-tree. So there’s the contradiction. (b) Suppose G is a connected undirected graph. An edge whose removal disconnects the graph is called a bridge . Either prove the following statement or provide a counter-example: every bridge e must be an edge in a depth-first search tree of G . Solution This is true. Suppose it were not true. Consider the edge e that connects vertices u and v , where e is a bridge. That is, if e were removed from the graph G , then we would have a partition of the vertices of G such that no edge crosses the partition. Start a depth first search in the partition that includes u . Eventually, since G is connected, this DFS must reach vertex u . When it does, it will examine all of the vertices adjacent to u and incorporate any who have not yet been “touched” into the DFS-tree. This includes v . We are guaranteed that v has not yet been examined since the edge ( u, v ) is the only edge that crosses our partition of vertices, and we started our DFS in the partition that included u . Therefore, the edge ( u, v ) must be included in the DFS, giving us our contradition.
Homework Assignment #5: October 6, 2023 (11:59pm) 3 Problem 3: Apply [20 points] A common approach to notifying people of what to do during an emergency situation (like an inclement weather event) is using a phone tree . It’s simple – the tree has a root – a person who kicks off a series of phone calls – and when each person receives a call, they have additional designated individuals (their children in the tree) that they call. It sounds old-fashioned, but research has shown that people are more likely to take action in response to a call tree in comparison to an SMS or other passive notification 1 . We’ll investigate the creation of a phone tree based on a social network. We assume that each participant has a set of “social connections” (i.e., people whose phone numbers they have handy). Given this, we need to create a tree with a simple rule: a participant x can be a child of another participant y in the tree only if y has x ’s number. Note that social connections are not necessarily bidirectional, but for simplicity, we will assume that they are. We will formulate the creation of a call tree as a graph search problem. We are given a graph, where participants in the phone tree are nodes, and two nodes have an edge between them if the corresponding participants have each others’ phone numbers. Consider first a fully connected network, i.e., everyone has everyone else’s phone number. (a) Assume we use the tree that results from executing breadth first search as our phone tree. Describe this tree in the abstract. Assuming there are n participants, a single phone call takes k minutes, and a person can only make one call at a time, how long does it take to notify all participants of the situation using this tree ? Solution This tree has a root node, which has n-1 leaf children. In this tree, it takes O ( k ( n 1)) = O ( kn ) time to notify everyone. (b) Now assume we use the tree that results from executing depth first search as our phone tree. Describe this tree in the abstract. Assuming there are n participants, a single phone call takes k minutes, and a person can only make one call at a time, how long does it take to notify all participants of the situation using this tree ? Solution This tree is just a linear graph. Again, it takes O ( kn ) time to notify everyone. Now consider a social network with the following social connections: (c) Draw the tree that results from running breadth first search on the graph that results from the social connections in the table above. If each call takes k minutes, and each participant can only make one call at a time, how long does it take to notify everyone? Solution insert tree 1 https://pubmed.ncbi.nlm.nih.gov/30379128/
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Homework Assignment #5: October 6, 2023 (11:59pm) 4 Participant Friends Zayda Xavier Yecenia Xavier, Wesley, Uma, Tevin Xavier Zayda, Yecenia, Vesper, Uma, Tevin Wesley Yecenia Vesper (root) Xavier, Tevin Uma Yecenia, Xavier, Seneca Tevin Yecenia, Xavier, Vesper, Seneca Seneca Uma, Tevin (d) Draw the tree that results from running a depth first search on the graph that results from the social connections in the table above. If each call takes k minutes, and each participant can only make one call at a time, how long does it take to notify everyone? Solution insert tree (e) Which approach is better? Use words that describe the structure of the phone tree to explain why this result is likely to generalize. Solution The BFS tree is likely to be better because it is “bushier”, resulting in more calls that can happen in parallel. Problem 4: Analyze We have a connected graph G = ( V, E ) and a specific vertex v V . Suppose we compute a depth first search tree rooted at u and obtain a tree T that includes all nodes of G . Suppose we then compute a breadth-first search tree rooted at u and obtain the same tree T . Prove that G = T . (In other words, if T is both a depth-first search tree and a breadth-first search tree rooted at u , then G cannot contain any edges that do not belong to T .) Solution Suppose that G has an edge e = ( a, b ) that does not belong to T . Since T is a depth first search tree, one of the two ends must be an ancestor of the other. Say a is an ancestor of b . Since T is a breadth-first search tree, the distance of the two nodes from u in T can differ by at most one. But if a is an ancestor of b and the distance from u to b in T is at most one greater than the distance from u to a , then a must in fact be the direct parent of b in T . From this it follows that ( a, b ) is an edge in T , contradicting our initial assumption that ( a, b ) did not belong to T .
Homework Assignment #5: October 6, 2023 (11:59pm) 5 Problem 5: Evaluate [20 points] There is a natural intuition that two nodes that are far apart in a communication network (i.e., that are separated by many hops) have a more tenuous connection than two nodes that are close together (i.e., that are separated by just a few hops). Consider the following question related to the susceptibility of paths in communication networks to the deletion of nodes. Suppose that an n -node undirected graph G = ( V, E ) contains two nodes s and t such that the distance between s and t is strictly greater than n/ 2. (a) Show that there must exist some node v not equal to either s or t such that deleting v from G destroys all s - t paths. (In other words, the graph obtained from G by deleting v contains no path from s to t .) Consider a run of BFS starting from node s . Let d be the layer in which node t is encoun- tered. By the given properties, we have d > n/ 2. We claim first that one of the layers L 1 , L 2 , . . . , L d 1 consists of a single node. We can prove this by contradiction; if each of these layers had at least size 2, then this would account for at least 2( n/ 2) = n nodes, but G has only n nodes, and we haven’t even gotten to the layer d yet, where t is, and s is in L 0 . Therefore, there is some layer L i that has just one node. Let’s call that node v . Deleting v destroys all s - t paths. Consider the set of nodes X = { s } ∪ L 1 L 2 ∪ · · · ∪ L i 1 . Node s belongs to X , but t does not. Any edge out of X must lie in layer L i , by the properties of BFS. Since any path from s to t must leave X at some point, it must contain a node in L i , but v is the only node in L i (b) Give an algorithm with running time O ( m + n ) to find such a node v . So the algorithm is simple, given the above. Run BFS and look for layer that has only one node. Such a layer must exist. v is the single node in that layer.
Homework Assignment #5: October 6, 2023 (11:59pm) 6 Problem 6: Create [20 points] The SXSW festival is coming up. The City of Austin is finalizing its plans. One problem they noticed last year was that the placement of trash and recycle bins along 6 th street was not optimal last year. This year they want to more strategically place bins to keep trash off the street by making sure trash bins are placed along the sidewalk on each side of the street in such a way that they are within 20ft of the entrance to any establishment that serves take-away food. (a) Give an efficient greedy algorithm that finds a set of locations along one side of 6 th street for placing bins that achieves the city’s goal while minimizing the number of bins they have to place. State and briefly justify the runtime of your algorithm. (Hint: this is a one-dimensional problem, consider the sidewalk as a line and determine the locations along that line to place bins.) Start at one end of the road and begin moving along the sidewalk until the first eating establishment. Go another 20ft then place a bin. “Delete” all of the eating establishments within 20ft of this bin, then iterate on the remaining eating establishments. The running time of this algorithm: sorting the input by location O ( n log n ), and then going through the input 1 time O ( n ); thus O ( n log n ). If you assume the input is already sorted along the sidewalk since that’s how location works, O(n) is the runtime. (b) Prove that the greedy choice that your algorithm makes is the optimal choice. Let C = { c 1 , . . . , c k } denote the full set of bin locations that our greedy algorithm places, and let T = { t 1 , . . . , t m } denote the set of bin locations in an optimal solution, sorted in increasing order along the street. We must show that k = m . We do this by showing a sense in which our greedy solution C “stays ahead” of the optimal solution T . Specifically, we claim that c i t i for each i , and prove this by induction. The claim is true for i = 1 since we go as far as possible along the street before placing the first bin. Assume now that it is true for some value i 1; this means that our algorithm’s first i trash bins { c 1 , . . . , c i } cover all of the eating establishments covered by the first i trash bins { t 1 , . . . , t i } in the greedy solution. As a result, if we add t i +1 to { c 1 , . . . , c i } , we will not leave any eating establishment between c i and t i +1 uncovered. But the ( i + 1) st step of the greedy algorithm chooses c i +1 to be as large as possible subject to the condition of covering all eating establishments between c i and c i +1 , so we have c i +1 t i +1 . This proves the claim by induction. Finally if k > m , then { c 1 , . . . , c m } fails to cover all eating establishments. But s m t m , and so { t 1 , . . . , t m } also fails to cover all eating establishments—a contradiction to it being the optimal solution.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help