nodes: 0, module; 1, function_definition; 2, function_name:max_heapify; 3, parameters; 4, block; 5, identifier:arr; 6, identifier:end; 7, identifier:simulation; 8, identifier:iteration; 9, expression_statement; 10, expression_statement; 11, comment:# Iterate from last parent to first; 12, for_statement; 13, expression_statement; 14, return_statement; 15, comment:""" Max heapify helper for max_heap_sort
      """; 16, assignment; 17, identifier:parent; 18, call; 19, block; 20, assignment; 21, identifier:iteration; 22, identifier:last_parent; 23, binary_operator:(end - 1) // 2; 24, identifier:range; 25, argument_list; 26, expression_statement; 27, comment:# Iterate from current_parent to last_parent; 28, while_statement; 29, pattern_list; 30, expression_list; 31, parenthesized_expression; 32, integer:2; 33, identifier:last_parent; 34, unary_operator; 35, unary_operator; 36, assignment; 37, comparison_operator:current_parent <= last_parent; 38, comment:# Find greatest child of current_parent; 39, block; 40, subscript; 41, subscript; 42, subscript; 43, subscript; 44, binary_operator:end - 1; 45, integer:1; 46, integer:1; 47, identifier:current_parent; 48, identifier:parent; 49, identifier:current_parent; 50, identifier:last_parent; 51, expression_statement; 52, if_statement; 53, comment:# Swap if child is greater than parent; 54, if_statement; 55, identifier:arr; 56, integer:0; 57, identifier:arr; 58, identifier:end; 59, identifier:arr; 60, identifier:end; 61, identifier:arr; 62, integer:0; 63, identifier:end; 64, integer:1; 65, assignment; 66, boolean_operator; 67, block; 68, comparison_operator:arr[child] > arr[current_parent]; 69, block; 70, comment:# If no swap occured, no need to keep iterating; 71, else_clause; 72, identifier:child; 73, binary_operator:2 * current_parent + 1; 74, comparison_operator:child + 1 <= end; 75, comparison_operator:arr[child] < arr[child + 1]; 76, expression_statement; 77, subscript; 78, subscript; 79, expression_statement; 80, expression_statement; 81, if_statement; 82, block; 83, binary_operator:2 * current_parent; 84, integer:1; 85, binary_operator:child + 1; 86, identifier:end; 87, subscript; 88, subscript; 89, assignment; 90, identifier:arr; 91, identifier:child; 92, identifier:arr; 93, identifier:current_parent; 94, assignment; 95, assignment; 96, identifier:simulation; 97, block; 98, break_statement; 99, integer:2; 100, identifier:current_parent; 101, identifier:child; 102, integer:1; 103, identifier:arr; 104, identifier:child; 105, identifier:arr; 106, binary_operator:child + 1; 107, identifier:child; 108, binary_operator:child + 1; 109, pattern_list; 110, expression_list; 111, identifier:current_parent; 112, identifier:child; 113, expression_statement; 114, expression_statement; 115, identifier:child; 116, integer:1; 117, identifier:child; 118, integer:1; 119, subscript; 120, subscript; 121, subscript; 122, subscript; 123, assignment; 124, call; 125, identifier:arr; 126, identifier:current_parent; 127, identifier:arr; 128, identifier:child; 129, identifier:arr; 130, identifier:child; 131, identifier:arr; 132, identifier:current_parent; 133, identifier:iteration; 134, binary_operator:iteration + 1; 135, identifier:print; 136, argument_list; 137, identifier:iteration; 138, integer:1; 139, string:"iteration"; 140, identifier:iteration; 141, string:":"; 142, list_splat; 143, identifier:arr
code: def max_heapify(arr, end, simulation, iteration):
      """ Max heapify helper for max_heap_sort
      """
      last_parent = (end - 1) // 2
  
      # Iterate from last parent to first
      for parent in range(last_parent, -1, -1):
          current_parent = parent
  
          # Iterate from current_parent to last_parent
          while current_parent <= last_parent:
              # Find greatest child of current_parent
              child = 2 * current_parent + 1
              if child + 1 <= end and arr[child] < arr[child + 1]:
                  child = child + 1
  
              # Swap if child is greater than parent
              if arr[child] > arr[current_parent]:
                  arr[current_parent], arr[child] = arr[child], arr[current_parent]
                  current_parent = child
                  if simulation:
                      iteration = iteration + 1
                      print("iteration",iteration,":",*arr)
              # If no swap occured, no need to keep iterating
              else:
                  break
      arr[0], arr[end] = arr[end], arr[0]
      return iteration