To optimize bubble sort, one can implement a _______ that stops iterating when no more swaps are needed.
- Binary search
- Flag-based check
- Hash table
- Recursive function
To optimize bubble sort, one can implement a flag-based check that stops iterating when no more swaps are needed. This optimization helps in breaking out of the loop early if the array is already sorted, reducing unnecessary iterations and improving the overall efficiency of the algorithm.
In DFS, the time complexity is _______ in the worst case for traversing a graph with V vertices and E edges.
- O(E)
- O(V * E)
- O(V + E)
- O(V)
The time complexity of DFS in the worst case is O(V + E), where V is the number of vertices and E is the number of edges in the graph. This is because DFS visits each vertex and edge exactly once in the worst case.
Recursive implementation of binary search involves breaking the problem into _______ subproblems until a solution is found.
- Five
- Four
- Three
- Two
Recursive implementation of binary search involves breaking the problem into two subproblems at each step, making it a logarithmic algorithm with a time complexity of O(log n), where 'n' is the number of elements.