For the two statements about the running time of ALGO, I need an explanation if it is True and F if it is false  1) The increment operation in Line 6 is executed a total of n/2 times in the worst case  2) The decrement operation in Line 10 is executed O(n) times. For Reference the Answer for 1 is False and 2 is True

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 24PE
icon
Related questions
Question

For the two statements about the running time of ALGO, I need an explanation if it is True and F if it is false 

1) The increment operation in Line 6 is executed a total of n/2 times in the worst case 
2) The decrement operation in Line 10 is executed O(n) times.

For Reference the Answer for 1 is False and 2 is True

Consider the following algorithm, which takes in a length-n array A
containing integers in the range 0 to 9.
Assume that array indexing begins at 0.
ALGO (A)
1: Let B be an array of length n
2: Let C be an array of length 10
3: for i=0 to 9
4:
5: for
6:
C[i] = 0
j = 0 to n-1
C[A[j]] C[A[j]] + 1
=
7: for i=1 to 9
8:
C[i] = C[i] + C[i-1]
9: for j = n-1 down to
10:
11:
B[C[A[j]]-1] = A[j]
C[A[J]]= C[A[j]] - 1
Transcribed Image Text:Consider the following algorithm, which takes in a length-n array A containing integers in the range 0 to 9. Assume that array indexing begins at 0. ALGO (A) 1: Let B be an array of length n 2: Let C be an array of length 10 3: for i=0 to 9 4: 5: for 6: C[i] = 0 j = 0 to n-1 C[A[j]] C[A[j]] + 1 = 7: for i=1 to 9 8: C[i] = C[i] + C[i-1] 9: for j = n-1 down to 10: 11: B[C[A[j]]-1] = A[j] C[A[J]]= C[A[j]] - 1
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Single source shortest path
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage