Question: def majority ( A ) : ' ' , Pre: A is a list with more than half its entries equal to x Post: Returns
def majorityA:
Pre: A is a list with more than half its entries equal to x
Post: Returns the majority element x
c
m A
i
while i lenA:
if c :
m Ai
c
else if Ai m:
c
else:
c
i
return m
Can anyone please help me with determining the loop invariant? I literally have no idea.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
