analysis_2 - Computing Complexity of Algorithms Example...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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

This document was uploaded on 06/12/2011.

Page1 / 16

analysis_2 - Computing Complexity of Algorithms Example...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online