What is the time complexity of Insertion Sort in the worst-case scenario?
- O(log n)
- O(n log n)
- O(n)
- O(n^2)
The worst-case time complexity of Insertion Sort is O(n^2), where 'n' is the number of elements in the array. This is because it involves nested loops iterating over the elements, similar to bubble sort. The inner loop shifts elements until the correct position is found in the sorted subarray.
Loading...
Related Quiz
- Discuss a real-world application where Breadth-First Search (BFS) is commonly used.
- What are some common use cases for regular expression matching?
- Exception handling is crucial in stack operations to manage _______ scenarios.
- Consider a scenario where memory usage is critical, and you need to sort a large dataset stored on disk. Discuss the feasibility of using selection sort in this situation and propose an alternative approach if necessary.
- How does the Ford-Fulkerson algorithm find the maximum flow in a network?