written_asgn2 - c sum=0 for(i=0 i<n i for(j=0 j<n*n j...

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

View Full Document Right Arrow Icon
Written Assignment II COP3502H Due: Monday, 2/19/07 in class Make sure you show all you work and start early. From “Data Structures, Algorithms, and Software Principles in C” 1. page 225, #4 (Hint: read over pages 221-222) 2. page 247, #3 3. page 247, #4 (Hint: unrolling and summation is just the substitution method we discussed in class, also see the appendix for help) 4. page 247, #5 Also do these problems 1. Show by mathematical induction that 6 ) 1 2 )( 1 ( 1 2 + + = == n n n i n i 2. For each of the 6 program fragments, give an analysis of the running time using Big-O notation a. sum=0; for (i=0; i<n; i++) sum++; b. sum=0; for (i=0; i<n; i++) for (j=0; j<n; j++) sum++;
Background image of page 1

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

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

Unformatted text preview: c. sum=0; for (i=0; i<n; ++i) for (j=0; j <n*n; ++j) sum++ d. sum=0; for (i=0; i<n; ++i) for (j=0; j<i; ++j) sum++; e. sum=0; for (i=0; i<n; ++i) for (j=0; j<i*i; ++j) for (k=0; k <j; ++k) sum++; f. sum=0; for (i=1; i<n; ++i) for (j=1; j<i*i; ++j) if (j%i == 0) for (k=0; k<j; ++j) sum++; Extra Credit Problem The Sieve of Erastothenes is a method used to compute all primes less than . We begin by making a table of integers from 2 to n . We find the smallest integer, i that is not crossed out, print i , and cross out i , 2i, 3i ,…. When n n i > , the algorithm terminates. What is the running timer of this algorithm?...
View Full Document

This document was uploaded on 06/12/2011.

Page1 / 2

written_asgn2 - c sum=0 for(i=0 i<n i for(j=0 j<n*n j...

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

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