Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In each of the following problems, you are given two algorithms that do the same job. You are required to indicate which of the two
In each of the following problems, you are given two algorithms that do the same job. You are required to indicate which of the two algorithms is better and why (30 points) a. The following two algorithms count the number of values that are above the average of a given set of values.
5) In each of the following problems, you are given two algorithms that do the same job. You are required to indicate which of the two algorithms is "better" and why (30 points) a. The following two algorithms count the number of values that are above the average of a given set of values Algorithms: AboveAvg1 & AboveAvg2 Input L: List of integer values, N: size of the List Output -> C: Number of values above the average of all values AboveAvgl (L, N) AboveAvg2 (L, N) 1. Set Avg, count0, 2" For 1 = 0 to N-1 1, Set Avg = 0, C=0 2, For J 0 to N-1 1- set count-count + L [I] 3. Set Avgcount/N 4. ForI 0 to N-1 1- set count = 0 2-For I 0 to N1 1- set count-count + L[I] 1- IF L[I] > Avg ) 3- Set Avg-count/N 4- IF ( L[J] > Avg ) 1-set c = c + 1 5. Return C 1- Set C-C 1 3. Return C b. The following two algorithms take a list L and output another list M such that M contains the even numbers of L first then L's odd numbers Algorithms: EvensFirst1 & EvensFirst2 Input L: List of integer values, n: size of List L Output -M: List of integers such that even numbers are first then odd numbers EvensFirstl (L, n, M) EvensFirst2 (L, n, M) 2, K= Size- 1 3. ForI0 to n1 2. For I 0 to n1 1_ IF ( L[1] % 2-. O ) // b. J-J+1 2-1F (L[1] % 2 != 0 ) // Odd 1_ IF ( L[1] % 2= 0 ) // Even 3. For I 0 to n1 b, J= J+1 2- ELSE /1 odd a. MIK) = L[1] b. K K-1 b, J = J+1 4. Return M 4. Return MStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started