algorithm - the two largest numbers in array of 4 elements -
i'm trying find way find largest 2 numbers in array of 4 elements, approach i'm using right this: start with
x = array[1] y = array[2] compare x,y if y > x switch values "because want x have greatest value" read array[3] if greater x create new x , give x value y else if check if greater y if yes create new y
but there many comparison, , want cut down it. guys have improve algorithm ?
yeah create lot of comparisons each index. why not find maximum, remove array find maximum ?
your algorithm o(2n) o(n)
arrays algorithm assembly
No comments:
Post a Comment