The procedure given below is used to maintain min-order in the min heap. Find out the missing statements, represented as X. [code] procedure

The procedure given below is used to maintain min-order in the min heap. Find out the missing statements, represented as X.
Code:
procedure TrickleDownMin(i)
	 if A[i] has children then 
		m := index of smallest of the children 
		        or grandchildren (if any) of A[i] 
		if A[m] is a grandchild of A[i] then
			 if A[m] < A[i] then 
				swap A[i] and A[m]
				X: _______________________
					____________________
			 endif 	
			TrickleDownMin(m)
		 endif 
		else //{A[m] is a child of A[i]} 
			if A[m] < A[i] then 
				swap A[i] and A[m] 
		endif
	 endif
A. if A[m] > A[parent(m)] then
swap A[m] and A[parent(m)]
B. if A[m] > A[parent(m)] then
swap A and A[parent(m)]
C. if A[m] < A[parent(m)] then
swap A[m] and A[parent(m)]
D. if A[m] > A[parent(m)] then
swap A and A[parent(m)]
 
Answer: a
Explanation: In TrickleDownMin() procedure, we maintain the min-ordering of the min heap. In this procedure, we locate the lowest child or grandchild of the element at positions i. If the lowest element is grandchild then we check that it is smaller than both, its parent and A.
 

Tìm kiếm

Back
Top