0 0 votes Consider an Adjacency List representation of a directed graph $G=(V, E)$ with $n$ vertices and $m$ edges, implemented using Python's $\verb|dict|$ where keys are vertex IDs and values are $\verb|lists|$ of neighbor vertex IDs.Which of the following statements regarding the time complexity of operations on this structure are TRUE?Finding if a specific edge $(u, v)$ exists takes $O(1)$ time in the worst case. Computing the out-degree of a vertex $u$ takes $O(1)$ time if using Python's $\verb|len(adj[u])|$. Computing the in-degree of a vertex $u$ takes $O(n+m)$ time in the worst case. Performing a Breadth-First Search (BFS) starting from a source vertex $s$ takes $O(n+m)$ time. Programming in Python goclasses python-&-dsa goclasses-da-dpp goclasses-da-dpp-day-96 goclasses-python-&-dsa-practice-questions multiple-selects + – GO Classes 173 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes Answer: B, C, and D ExplanationA. Finding if a specific edge $\mathbf{(u, v)}$ exists takes $\mathbf{O(1)}$ time in the worst case.This is False. In an adjacency list implemented with a standard list for neighbors, finding $v$ in $u$'s neighbor list requires a linear scan, which takes $O(\text{out-degree}(u))$ time in the worst case, not $O(1)$.B. Computing the out-degree of a vertex $\mathbf{u}$ takes $\mathbf{O(1)}$ time if using Python's $\mathbf{len(adj[u])}$.This is True. Accessing adj[u] in a Python dictionary is $O(1)$ on average, and getting the length of a list using len() is also an $O(1)$ operation.C. Computing the in-degree of a vertex $\mathbf{u}$ takes $\mathbf{O(n + m)}$ time in the worst case.This is True. To find the in-degree of a specific vertex $u$, one must iterate through all adjacency lists of all vertices to count how many times $u$ appears as a neighbor. This involves checking every edge in the graph, resulting in an $O(n+m)$ time complexity.D. Performing a Breadth-First Search (BFS) starting from a source vertex $\mathbf{s}$ takes $\mathbf{O(n + m)}$ time.This is True. The standard time complexity for a BFS on an adjacency list representation is $O(V + E)$, which corresponds to $O(n+m)$ in this case, as every vertex and every edge is visited once. BooleanLattice answered Feb 3 BooleanLattice comment Share Follow 0 reply Please log in or register to add a comment.