A. The running time of the for loop of Line 5 -- 6 is O(n). B. The running time of the for loop of Line 9 -- 11 is Theta of n. C. The running time of ALGO is O(n).

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
2. For each statement below regarding the running time of ALGO, insert a T or F in
the box depending on whether it is true or false, respectively.
A. The running time of the for loop of Line 5 -- 6 is O(n).
B. The running time of the for loop of Line 9 -- 11 is Theta of n.
C. The running time of ALGO is O(n).
D. The running time of ALGO is Theta of n.
E. The runnin time of ALGO is Omega of n.
F. The running time of ALGO is O(n^2).
Transcribed Image Text:2. For each statement below regarding the running time of ALGO, insert a T or F in the box depending on whether it is true or false, respectively. A. The running time of the for loop of Line 5 -- 6 is O(n). B. The running time of the for loop of Line 9 -- 11 is Theta of n. C. The running time of ALGO is O(n). D. The running time of ALGO is Theta of n. E. The runnin time of ALGO is Omega of n. F. The running time of ALGO is O(n^2).
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:
C[i] = 0
5: for j 0 to n-1
6:
C[A[j]] = C[A[j]] + 1
7: for i=1 to 9
C[i] = C[i] + C[i-1]
8:
9: for j = n-1 down to 0
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: C[i] = 0 5: for j 0 to n-1 6: C[A[j]] = C[A[j]] + 1 7: for i=1 to 9 C[i] = C[i] + C[i-1] 8: 9: for j = n-1 down to 0 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
Types of Loop
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