Question

Suppose you implemented a quadratic time (that is an O(n^2) algorithm for a problem P. On...

Suppose you implemented a quadratic time (that is an O(n^2) algorithm for a problem P. On a test run, your algorithm takes 50 seconds on inputs of size 1000. Your friend found a clever algorithm which solves the same problem with a running time O(n^(3/2)). However, the faster algorithm takes 150 seconds on inputs of size 1000. How could this be? If you need to solve a problem of size 4000, which algorithm you should use? What about inputs of size 10,000? Explain your answers (assume low-order terms are negligible).

Homework Answers

Answer #1

Say the quadratic algorithm takes time

and the other one takes

the constants can vary so the time may be more for the lower-order algorithm.

So we can see that

which gives b = 0.0047

and c = 0.00005‬

Hence for the size of 4000 we have

Quadratic algo taking the time of 800 sec

other one takes time of 0.0047*(4000^(1.5)) = 1,189.016

For the size of 4000 quadratic algo is preferred as it takes lesser time

Now for the size of 10000

Solving the same equations, we get the time for quadratic algo is 0.00005‬ * (10000^2) = 5000 sec

and for the other algo is 0.0047*(10000^(1.5)) = 4700 sec

So for the size of 10000, it takes lesser time than quadratic algo hence it is preferred.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
a) Suppose that a particular algorithm has time complexity T(n) = 3 x 2^n, and that...
a) Suppose that a particular algorithm has time complexity T(n) = 3 x 2^n, and that executing an implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are presented with a machine that is 64 times as fast. How many inputs could we process on the new machine in t seconds? b) Suppose that another algorithm has time complexity T(n) = n^2, and that executing an implementation of it on a particular...
discrete structures problems 1. A program P takes time proportional to logn where n is the...
discrete structures problems 1. A program P takes time proportional to logn where n is the input size. If the program takes 1 minute to process input of size 1,000,000, how many seconds does it take to process input of size 100? 2. When the best possible algorithm to solve a problem is exponential-time, or in general in nonpolynomial (not in O(np) for any p) we call such a problem ___________________. 3. f(x) is O(x 2) and g(x) is O(x...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
An exponential algorithm requires 4^n (four to the power n) steps to solve a problem with...
An exponential algorithm requires 4^n (four to the power n) steps to solve a problem with an input of size n. Suppose it has been found that using today's computer, a direct implementation of that algorithm would be able to handle an input size of 30 in 10 years. If the computer is speeded up by a factor of 100 (with no other changes), what input size can be processed in the same time? Explain your answer. (Hint: speeding up...
1. Suppose you are given 3 algorithms A1, A2 and A3 solving the same problem. You...
1. Suppose you are given 3 algorithms A1, A2 and A3 solving the same problem. You know that in the worst case the running times are T1(n) = (10^4)n, T2(n) = 10n , T3(n) = (10^3)(n^3) log10 n (a) Which algorithm is the fastest for very large inputs? Which algorithm is the slowest for very large inputs? (Justify your answer.) (b) For which problem sizes is A1 the best algorithm to use (out of the three)? Answer the same question...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...
Design a recursive divide-and-conquer algorithm A(n) that takes an integer input n ≥ 0, and returns...
Design a recursive divide-and-conquer algorithm A(n) that takes an integer input n ≥ 0, and returns the total number of 1’s in n’s binary representation. Note that the input is n, not its binary representation. For example, A(9) should return 2 as 9’s binary representation is 1001, while A(7) should return 3 since 7 is 111 in binary. Note that your algorithm should have a running time of O(log n). Justify your answer. You need to do the following: (1)...
You are an algorithm designer and you came up with four different divide-and-conquer algorithms for some...
You are an algorithm designer and you came up with four different divide-and-conquer algorithms for some problem Q. Those four algorithms are described below in parts (1), (2), (3), and (4). You wrote those descriptions a long time ago so now you want to remind yourself, for each one of them, what was the corresponding recurrence relation and provide an upper bound on the running time. So first give the recurrence then solve it using any method of your choice...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward solutions. One of those problems is the “Maximum Subarray Sum” or “Maximum Value Contiguous Subsequence": Given a sequence of n numbers A[0 ... n-1], give an algorithm for finding a contiguous subsequence A[i ... j], for which the sum of elements in this subsequence is the maximum we can get by choosing different i or j.   For example: the maximum subarray sum for the...
In this problem your task is to find a missing number. The input will always consist...
In this problem your task is to find a missing number. The input will always consist of an array of n positive integers such that the difference between every two consecutive numbers is a fixed constant but one integer is missing. See below for two example inputs/outputs: Input sequence: [0, 2, 4, 6, 10] Output: missing number is 8 Input sequence: [1, 4, 7, 13, 16] Output: missing number is 10 Note that in the first example the constant c...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT