cs180_hw2-final

.pdf

School

University of California, Los Angeles *

*We aren’t endorsed by this school

Course

180

Subject

Computer Science

Date

Oct 30, 2023

Type

pdf

Pages

7

Uploaded by GrandLeopardPerson487

Report
CS 180 HW2 Arjun Raj Loomba 605809574 Problem 1 (a) We define a graph G ⇒ ∃ tree, back/forward, and cross edges. DFS cannot result in cross-edges and only in back/forward edges, and tree edges, which we will analyse. As- sume V is the set of all nodes, and E is a set of all edges in G .We establish that u v and v , v u ( u, v ) V . To prove that if removing an edge e E that connects the vertices u and v will disconnect the graph, we first prove that removing a back-edge will not disconnect the graph. Then, we prove that removing a tree-edge will disconnect the graph. In a situation where there are multiple subtrees of v that are represented by the set S where v S and multiple back-edges from S to u or any other ancestor of u, then even if edge e , which in this case is a back-edge is removed, there still remains other back-edges which will connect the graph. This proves by contradiction that it can’t be a back-edge. The same would hold for a case with forward edges. Since this is DFS on an undirected graph any cross-edge, because it would aldready be traversed, therefore we only traverse through descendants and ancestors of u . This leaves only tree-edges, where if we remove a tree edge e , and forward/backward edges from u k v , then DFS will not traverse through all ancestors, and descendants. In this case, the above statement of removing edge e disconnecting the graph if it’s a tree edge is True (b) Assuming we have an undirected connected Graph ( V , E ) G , we prove that removing 2 nodes from any G wouldn’t disconnect G . We divide all undirected graphs into 2 categories: Cyclic and Acyclic. Trees: All acyclic connected graphs : In this case, an undirected graph G forms a tree, which is defined as a connected, acyclic, undirected graph. This also includes other seemingly different acyclic graphs, such as a complete bipartite graph or a star. In all such cases, more than 1 node with degree equal to 1. If both such nodes are removed then the graph’s connectivity is unaffected. These nodes will either have indegree = 0 or outdegree = 0. Either, there will be 2 nodes that don’t have any descendants (like a conventional binary tree or a star) or a single node with no ancestors and another node with no descendants. This proves that no acyclic, undirected graph G is disconnected if 2 specific nodes are removed. All other graphs such as Cyclic, connected graphs: In this case, an undirected graph has a cycle if a path that starts and ends at the same node ( v 1 , v 2 , ..., v n 1 , v n ) : v n = v 1 Using BFS (Breath First Search), we can convert the cyclic graph into a BFS tree. This BFS tree structure can now employee above case for Trees: All acyclic connected graphs . There’s also another proof if each node in our cycle has degree 2. Removing the 2 nodes that are adjacent in the cycle G will not disconnect the graph. In the above example, this implies removing node v n 1 and v 1 = v n , will still leave the graph connected. Since proven for all cases of possible undirected graphs, the statement is True 1
CS 180 HW2 Arjun Raj Loomba 605809574 (c) Assume that a graph G is not connected, for a solution with proof by contradiction, to prove that v V (set of all Nodes in the graph), if deg ( n ) n 2 , then G is connected. Assuming that G is not connected and it consists of more than 1 connected component C i : i (1 , 2 , ..., n 1 , n ): C = { C 1 , C 2 , C 3 , ..., C n } For our proof, we can consider only 2 connected components, C 1 , C 2 : ( C 1 , C 2 ) G and | C 1 | ≤ | C 2 | . This implies that C 1 is the smallest connected component ⇒ | C 1 | ≤ n 2 . Let’s assume that we have a node u : u C 1 . Then even in the best case, where all other nodes in C 1 are connected to u , deg ( u ) is | C 1 |− 1. In all cases: | C 1 | − 1 < n 2 | C 1 | − 1 n 2 1 n 2 1 < n 2 Since u can’t possibly have a degree of n 2 , then every node doesn’t have a degree n 2 , if the graph G is not connected. Therefore, by contradiction, if deg ( u ) n 2 then it has to be connected. Therefore, the given statement is True 2
CS 180 HW2 Arjun Raj Loomba 605809574 Problem 2 (a) A min heap is typically used to discern the minimum value in a given set of num- bers. In this case, however, we’re tasked to find the K th smallest value without removing it. Assuming that our algorithm is defined as a class, then upon initializing this class into an object, the value of k is defined to start with. We assume that the set S with values from 0 , 1 , ..., n is aldready in sorted order. Data Structure Construction : Based on the value of K , our data-structure, is a max- heap and an array. The max-heap will contain all values from (1 st , 2 nd , ..., ( k 1) st ) < k th , and will be heapified when the class is initiated based on the value of k (i.e. the root node is the k th node). All remaining values can be stored in an array with values from k + 1 , k + 2 , ..., n 1 , n . The K th smallest value becomes the largest value, i.e. the head-node of the heap. Therefore, there may be operations on the heap in O ( logK ) time. Since the K th smallest element is the root node of the heap, the function Find Kmin will return the head/root node of the heap, which is the K th smallest value in the set. Since O (1), which is the time complexity of accessing the root node, as we point to the root node to begin with: O (1) = O ( logK ). If we wish to insert a value into our new data-structure in log ( k ) time, then there are two different cases. Let’s assume, we wish to insert a value: v . First, we must check whether v k min or is v < k min : v K min , then our new value v is pushed onto the end of of our array in O (1) = O ( logK ) time. v < K min , then v is added, as a leaf node to the leftmost empty position on the heap. Then the max-heap is heapified up, where key ( w ), which is assumed as the value associated with the parent node must be key ( v ) Since there are k elements to deal with, this algorithm must be completed in O ( logK ) time. It’s important to note that because the total number of nodes must equal k in the heap to preserve O ( logK ) time. Therefore, the current K th smallest value node will be popped in O (1) time and pushed onto the array, and a new k t h smallest value will be determined. O ( logK + 1) = O ( logK ), which is also valid. (b) In part (a) , a max-heap and an array is employed, with an array. However, to support pop() functionality, the data structure implementation must be partially different. Data Structure Construction: A max-heap like (a), that contains all values from (1 st , 2 nd , ..., ( k 1) st ) < k th . For the remaining values there’s a min-heap ( k + 1) st < ( k + 2) nd , ..., ( n 1) st , n th The min-heap is essential for the pop() operation which is explained in the list below. And replaces the array in (a) 3
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

Browse Popular Homework Q&A

Q: 800 9001000 min = Q₁ = Q₂ Q3 (b) Approximately what percenta Approximately% (c) Approximately what…
Q: The incomplete ques
Q: The graph of f(x) is shown. वि | 45 6 7 X fl=o at x = ? DIY'S_
Q: Questions 1. What are two advantages of online ordering in a fast-food restaurant such as Domino's…
Q: A horizontal rifle is fired at a bull's-eye. The muzzle speed of the bullet is 650 m/s. The gun is…
Q: Ginny currently earns a    (a. nominal; b. real)    wage of $12.00 per hour; in other words, the…
Q: Match the graph to the correct exponential functions. Select all that apply. -10 -6 □y=-2(3)^…
Q: A row of long cylindrical power cables that are spaced 2 cm evenly apart is placed in parallel with…
Q: Required information Use the following information for the Quick Studies below. (Algo) Rafner…
Q: QUESTION 1 You and 3 friends go bowling. You bowl for 2.5 hours. You play 3 games and the total cost…
Q: 1.12 Choose the equation below that can be used to determine the value of "P" for a known interest…
Q: The first part of the assignment is to open Excel and in column A starting in row 1 and down to row…
Q: Which type of performance evaluation you thinks works best, a criteria based or a competency based…
Q: Below are listed molecules with different chemical characteristics. Knowing that all molecules will…
Q: An ampule of naphthalene in hexane contains 1.00×10-4 naphthalene. The naphthalene is excited with a…
Q: this was completely wrong, and it took me more than hour
Q: Br H3C CH3 a b с ionization d 1-propanol e Prelab Question #4 Homework Unanswered H H 8+ With…
Q: (a) State the null hypothesis H and the alternate hypothesis H₁. H₁:0 H₁:0 (b) Determine the type of…
Q: O ATOMS, IONS AND MOLECULES Counting protons and electrons in atoms and atomic ions Fill in the…
Q: Evaluate √ √R 6xy5 dydx R where the region is bounded by the curves y = = x² 1 and y = 1-². Sketch…
Q: A travel magazine conducts an annual survey where readers rate their favorite cruise ship. Ships are…
Q: MEAN=50 STANDARD DEVIATION =7 P(3440)= *Round to 4 decimal as needed*