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

l T-Mobile LTE 5:31 PM a abdul-quader.com Homework 4 Due Monday, 4/16 Section 31

ID: 3699703 • Letter: L

Question

l T-Mobile LTE 5:31 PM a abdul-quader.com Homework 4 Due Monday, 4/16 Section 31 (page 202) #6 and 9 Describe an algorithm in pseudocode that finds the second largest element of a list of integers. Show how this algorithm works on the following inputs: . 1,3,5,6,7,9 9,8,7,6,5,4,3,2, 10 Describe an algorithm in pseudocode that finds that mean of a list of integers (the mean of a set of numbers is the average of the numbers). Show how this algorithm works on the following inputs: -1,3 -1,2,3,4 Suggested exercises (not to be turned in) Pages 202-203 #3, 7, 8, 11, 13, 23, 24 .

Explanation / Answer

Solution:

The first question is done as per Chegg guidelines, please repost others.

An algorithm in Pseudocode:

Correctness:

The above algorithm will give us the correct result after completing the loop, since we are finding the max element first and after that when the max is getting replaced we are taking the previous value of max and storing it in max2.

Running time:

T(n)= O(n)

1 3 5 6 7 9

at i= 0 for loop max1= 0, max2= 0

after comparison max1= 1, max2= 0

at i= 1 for loop max1= 1, max2= 0

after comparison max1= 3, max2= 1

at i= 2 for loop max1= 3, max2= 2

after comparison max1= 5, max2= 3

at i= 3 for loop max1= 5, max2= 3

after comparison max1= 6, max2= 5

at i= 4 for loop max1= 6, max2= 5

after comparison max1= 7, max2= 6

at i= 5 for loop max1= 7, max2= 6

after comparison max1= 9, max2= 7

max2= 7.

similarly the second example can be done.

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)