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).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.