Interview Ready Flashcards
function isAlphanumeric(char) {
return /^[0-9a-zA-Z]+$/.test(char);
}
let formatted = s.toLowerCase().split(“”).filter(isAlphanumeric);
What is the Big O complexity of the Array.sort() method in Javascript?
A) O(1)
B) O(log n)
C) O(n)
D) O(n log n)
D
What is the time complexity of a Depth-First Search (DFS) algorithm on a graph with V vertices and E edges?
A) O(V)
B) O(E)
C) O(V + E)
D) O(V * E)
C) O(V + E)
The time complexity of Depth-First Search (DFS) on a graph with V vertices and E edges is typically O(V + E).
What is the time complexity of a Breadth-First Search (BFS) algorithm on a graph with V vertices and E edges?
A) O(V)
B) O(E)
C) O(V + E)
D) O(V * E)
C) O(V + E)
The time complexity of Breadth-First Search (BFS) on a graph with V vertices and E edges is typically O(V + E).
What is the time complexity of Binary Search when searching for an element in a sorted array with n elements?
A) O(1)
B) O(log n)
C) O(n)
D) O(n log n)
B) O(log n)
Binary Search has a time complexity of O(log n) when searching for an element in a sorted array with n elements.
In which scenario should you consider using Topological Sort?
A) Calculating the shortest path in a weighted graph.
B) Finding the strongly connected components in a directed graph.
C) Detecting a cycle in an undirected graph.
D) Scheduling tasks with dependencies.
D) Scheduling tasks with dependencies.
Option C is incorrect because Topological Sort is not typically used for detecting cycles in undirected graphs. Instead, it is primarily used for directed acyclic graphs (DAGs).