Docsity

Written Assignment 2 - Computer Science I - Fall 2007 | COP 3502, Assignments of Computer Science

Toggle sidebar
bg1
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
)12)(1(
1
2++
=
∑
==
nnn
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++;
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++;
pf2

Partial preview of the text

Download Written Assignment 2 - Computer Science I - Fall 2007 | COP 3502 and more Assignments Computer Science in PDF only on Docsity!

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. 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, #

Also do these problems

  1. Show by mathematical induction that 6

1

==

nn n i

n

i

  1. 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++;

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

i > n , the algorithm terminates. What is the running timer of this algorithm?