Question
Q1. a. Given an n-element array X, Algorithm B chooses log n elements in X at random and executes O(n)-time calculation for each. What is
Q1.
a. Given an n-element array X, Algorithm B chooses log n elements in X at random and executes O(n)-time calculation for each. What is the worst-case running time of Algorithm B?
b. Given an n-element array X of integers, Algorithm C executes O(n)-time computation for each even number in X, and an O(log n)-time computation for each odd number in X. What are the best-case and worst-case running times of Algorithm C?
c. Sepp and Ueli are arguing about their algorithms. Sepp claims his O(n log n)-time method is always faster than Uelis O(n 2 )-time method. To settle the issue, they perform a set of experiments. To Sepps dismay, they find that if n < 100, the O(n 2 )-time algorithm runs faster, and only when n 100 is the O(n log n)-time one better. Explain how this is possible.
d. Give a big-Oh characterization, in terms of n, of the running time of the method in the following code fragment.
Initialize real number s 0.
for i 0 to n 1 do
for j 0 to n n 1 do
for k 0 to j 1 do
s s + 1
return s
Step 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