Junior
Millised algoritmid omavad kvadratilist keerukust O(n²)?
sobes.tech AI
Vastus AI-lt
- Bubbling sort (Bubble Sort)
- Selection sort (Selection Sort)
- Insertion sort (Insertion Sort)
- Traversing nested loops, where each loop depends on the size of the input data (e.g., searching for pairs in an array)
Example of nested loops:
def find_pairs(arr):
n = len(arr)
for i in range(n): # O(n)
for j in range(n): # O(n)
# Some operation, e.g., printing the pair (arr[i], arr[j])
pass