Consider a directed graph \( G = (V,E) \), where \( V = \{0,1,2,\dots,100\} \) and
\[ E = \{(i,j) : 0 < j - i \leq 2, \text{ for all } i,j \in V \}. \] Suppose the adjacency list of each vertex is in decreasing order of vertex number, and depth-first search (DFS) is performed at vertex 0. The number of vertices that will be discovered after vertex 50 is:
A recursive function is given:
def mystery(n):
if n $<=$ 0:
return 1
else:
return mystery(n-1) + mystery(n-2)
Find the value of mystery(4).
def fun(L, i=0):
if i $>=$ len(L) - 1:
return 0
if L[i]> L[i+1]:
L[i+1], L[i] = L[i], L[i+1]
return 1 + fun(L, i+1)
else:
return fun(L, i+1)
data = [5, 3, 4, 1, 2]
count = 0
for _ in range(len(data)):
count += fun(data)
print(count)
| Column 1 | Column 2 | ||
| (p) | First In First Out | (i) | Stacks |
| (q) | Lookup Operation | (ii) | Queues |
| (r) | Last In First Out | (iii) | Hash Tables |