Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please analyze my algorithm(which finds the secondLargest number out of an array

ID: 3870087 • Letter: P

Question

Please analyze my algorithm(which finds the secondLargest number out of an array, and state the complexity of it. I believe or would like to claim that the algorithm is 1+n-1.

I would like more elaboration on the algorithm, and my justification as to why I claim this(I'm not entirely sure I'm right or not), because it begins with an if else statement, so that is 1 comparison, then it enters the for loop, so that is 1+(n-2). Also, I am very confused as to why there are subtractions when you enter a for loop combined with the if & else if statement.

Explanation / Answer

Upper if condition have complexity 1 because of if or else part exicuted. By this

So the complexity is n-2 +1= n-1.

Then we, use big Oh notation , for this- O (n).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote