hw7-soln - ECE 209 Homework 7 Fall 2007 Homework 7 Due:...

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

View Full Document Right Arrow Icon
ECE 209 Fall 2007 Homework 7 Homework 7 Due: November 6, 2007 NAME: __________________________________________________________ UNITY ID: ___________________ @ncsu.edu SECTION: _______________ (001/002) Print this file and answer in the space provided. Staple in the top left corner. Do not fold. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
ECE 209 Fall 2007 Homework 7 1. (35 points) Using big-O notation, give the running time of each of the following functions as a function of N. Function Running Time void fOne(int array[], int N) { int i; for (i=1; i<N; i++) array[i] += array[i-1]; } O(N) Basic Rule #3 void fTwo(int array[], int N) { int i; for (i=1; i<N/2; i++) array[i] += array[i+N/2]; } O(N) Basic Rule #3 void fThree(int array[], int N) { int i, j; for (i=1; i<N; i++) { for (j=N-1; j>=0; j--) { array[j] = array[j] + array[i-1] + i*N; } } } O(N 2 ) Basic Rule #4 int fFour(int array[], int N) { if (N == 0) return 1; else return array[N/2] + fFour(array,N/2); } O(log N) Pattern #2 void fFive(int array[], int N) { int i, j; for (i=1; i<N-5; i++) { for (j=i; j<i+5; j++) { array[i] += array[j]; } array[i] = array[i]/5; } } O(N) Basic Rule #4 (Inner loop is O(1).) int fSix(int array[], int N) {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/24/2008 for the course ECE 209 taught by Professor Tuck during the Spring '08 term at N.C. State.

Page1 / 5

hw7-soln - ECE 209 Homework 7 Fall 2007 Homework 7 Due:...

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

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