Question: Find the largest among root and children largest = i l = 2 * i + 1 r = 2 * i

Find the largest among root and children
   largest = i
   l = 2 * i + 1
   r = 2 * i + 2
 
if l < n and arr[i] < arr[l]:
   largest = 1
 
if r < n and arr[largest] < arr[r]:
   largest = r

 

I am getting an error message that says below:

Traceback (most recent call last):
 File "", line 10, in
NameError: name 'l' is not defined

This is my code:

def heapify(arr, n, i):

Step by Step Solution

3.41 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It appears that youre experiencing a NameError because the variable l is not defined ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!