Sobes.tech
Junior

Which algorithms have quadratic complexity O(n²)?

sobes.tech AI

Answer from AI

  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Traversal of nested loops, where each loop depends on the size of the input data (e.g., finding 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, for example, printing the pair (arr[i], arr[j])
            pass