*This preview shows
pages
1–7. Sign up
to
view the full content.*

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Computing Complexity of Algorithms Example Problems 1. Algorithm A runs in O(N 2 ) time, and for an input size of 4, the algorithm runs in 10 milliseconds, how long can you expect it to take to run on an input size of 16? 4 2 16 2----- = ------- 10 x => x = 100ms 2. Algorithm A runs in O(log 2 N) time, and for an input size of 16, the algorithm runs in 28 milliseconds, how long can you expect it to take to run on an input size of 64? log 16 log64 ------------ = ------------=> x =42 ms 28 ms x 3. Algorithm A runs in O(N 3 ) time. For an input size of 10, the algorithm runs in 7 milliseconds. For another input size, the algorithm takes 189 milliseconds. What was that input size? 10 3 N 3----- = ------- => N = 30 7 ms 189 4. An algorithm takes 6 ms for input size N = 10, 24.9 ms for N = 20, and 149 ms for N = 50. Find whether the complexity of the algorithm is O(N 2 ) or O(N 3 ). 5. What is the computational complexity of the following algorithm? (Assume N is a positive integer) int N,j,k,sum = 0; scanf(%d,&N); j = N; while (j > 1) { k = 0; while (k > N){ sum = sum + j * k; k ++; } j = j / 2; }...

View
Full
Document