Question 1 Consider the following segment of an algorithm: i = 1 Loop while (i < n) print("Hello World!") i - i * 3 Which one of the following options about the runtime R(n) is true? A. R(n) = 0(n³) B. R(n) = 0(log³n) C. R(n)= 0(3") D. R(n)= 0(log3 n) E. R(n) = 0(³√n) Question 2 Which of the following is NOT true? A. n2 € 0(n3) E B. log(n!) € O(n) C. log(n!) E (logn) D. 4¹ € 0(2) E. n² € (nlgn) Question 3 Suppose T is a binary search tree storing n entries. Which one of the following statements is true? A. Inserting into T is 0(1) in the best case and 0(log n) in the worst case. B. Inserting into T is 0(1) in the best case and 0(n) in the worst case. C. Inserting into T is 0(log n) in the best case and 0(log n) in the worst case. D. Inserting into T is 0(log n) in the best case and 0(n) in the worst case. E. Inserting into T is O(n) in the best case and 0(n) in the worst case.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 18PE
icon
Related questions
Question
Question 1
Consider the following segment of an algorithm:
i = 1
Loop while (i <n)
print("Hello World!")
i - i * 3
Which one of the following options about the runtime R(n) is true?
A. R(n) = 0(n³)
B. R(n)=
C. R(n) =
D. R(n) =
E. R(n) = (n)
(log³n)
☺ (3")
0(log3 n)
Question 2
Which of the following is NOT true?
A. n² € 0(³)
B. log(n!) € O(n)
C. log(n!) E (logn)
D. 4¹ € 0(2¹)
E. n² € (nlgn)
Question 3
Suppose T is a binary search tree storing n entries. Which one of the following statements
is true?
A. Inserting into T is 0(1) in the best case and 0(log n) in the worst case.
B. Inserting into T is 0(1) in the best case and 0(n) in the worst case.
C. Inserting into T is O(log n) in the best case and O(log n) in the worst case.
D. Inserting into T is 0(log n) in the best case and 0(n) in the worst case.
E. Inserting into T is O(n) in the best case and 0(n) in the worst case.
Transcribed Image Text:Question 1 Consider the following segment of an algorithm: i = 1 Loop while (i <n) print("Hello World!") i - i * 3 Which one of the following options about the runtime R(n) is true? A. R(n) = 0(n³) B. R(n)= C. R(n) = D. R(n) = E. R(n) = (n) (log³n) ☺ (3") 0(log3 n) Question 2 Which of the following is NOT true? A. n² € 0(³) B. log(n!) € O(n) C. log(n!) E (logn) D. 4¹ € 0(2¹) E. n² € (nlgn) Question 3 Suppose T is a binary search tree storing n entries. Which one of the following statements is true? A. Inserting into T is 0(1) in the best case and 0(log n) in the worst case. B. Inserting into T is 0(1) in the best case and 0(n) in the worst case. C. Inserting into T is O(log n) in the best case and O(log n) in the worst case. D. Inserting into T is 0(log n) in the best case and 0(n) in the worst case. E. Inserting into T is O(n) in the best case and 0(n) in the worst case.
Question 4
Given the recurrence relations T(n) = ₁
complexity in big-theta?
A. 0(√n log10 √n)
B. 0(n² log₂ n)
C. 0(√n log₂n)
D. (n¹og₂n)
E. (n log₂ √n)
Question 5
Consider a Queue ADT with the following standard operations: create Queue () and
enqueue (Queue Q, int x), and a Stack ADT with the similar standard operations: createStack(),
pushStack (Stack s, int n), and popStack (Stack S, int x) have been created. With the following
algorithm and data file:
) = √2T (²) + √ñ and T(1)=1, what is the run-time
Algorithm: DoSomething (String filename)
Q1 = createQueue ()
S1 = createStack()
Open filename
loop (not end of file)
read number
if (number not 0)
else
pushStack (S1, number)
popStack (S1, x)
popStack (S1, x)
loop (not empty S1)
popStack (S1, x)
enqueu (Q1, x)
end loop
end if
end loop
The data are 8, 30, 53, 14, 0, 66, 38, 19, 45, 29, 39, 7, 0, 29, 29, 8, 39, 18, 0
What would be the contents of queue Q1 after the above-describe code is executed
with the associated data file input to the algorithm?
A. 53, 30, 8, 39, 29, 45, 19, 38, 66, 39, 8, 29, 29
B. 30, 8, 29, 45, 19, 38, 66, 8, 29, 29
C. 53, 14, 19, 45, 29, 39, 7, 8, 39, 18
D. 8, 30, 33, 38, 19, 45, 29, 29, 8
E. 8, 30, 66, 38, 19, 45, 29, 29, 29,8
Transcribed Image Text:Question 4 Given the recurrence relations T(n) = ₁ complexity in big-theta? A. 0(√n log10 √n) B. 0(n² log₂ n) C. 0(√n log₂n) D. (n¹og₂n) E. (n log₂ √n) Question 5 Consider a Queue ADT with the following standard operations: create Queue () and enqueue (Queue Q, int x), and a Stack ADT with the similar standard operations: createStack(), pushStack (Stack s, int n), and popStack (Stack S, int x) have been created. With the following algorithm and data file: ) = √2T (²) + √ñ and T(1)=1, what is the run-time Algorithm: DoSomething (String filename) Q1 = createQueue () S1 = createStack() Open filename loop (not end of file) read number if (number not 0) else pushStack (S1, number) popStack (S1, x) popStack (S1, x) loop (not empty S1) popStack (S1, x) enqueu (Q1, x) end loop end if end loop The data are 8, 30, 53, 14, 0, 66, 38, 19, 45, 29, 39, 7, 0, 29, 29, 8, 39, 18, 0 What would be the contents of queue Q1 after the above-describe code is executed with the associated data file input to the algorithm? A. 53, 30, 8, 39, 29, 45, 19, 38, 66, 39, 8, 29, 29 B. 30, 8, 29, 45, 19, 38, 66, 8, 29, 29 C. 53, 14, 19, 45, 29, 39, 7, 8, 39, 18 D. 8, 30, 33, 38, 19, 45, 29, 29, 8 E. 8, 30, 66, 38, 19, 45, 29, 29, 29,8
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Counting Sort
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