assign6-problem3

assign6-problem3 - Name Mihai Feraru a let n = length of...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 Name: Mihai Feraru a) let n = length of array let i = the number of iterations left for the outer loop to execute The outer loop iterates n-1 times For each iteration of the outer loop, the inner loop executes i times Inside the inner loop, there is a condition that can either execute once or not at all, and inside that there is a permutation that a The condition can be considered a constant, O(1) the program is a sum of constant actions that is linearly decreasing 1 +. .(n-1 times). .+ 1 . .. (1 + 1 + 1 + 1) + (1 + 1 + 1) + (1 + 1) + 1 1 + 2 * 1 + 3 * 1 + 4 * 1 + 5 * 1 + . .. n-1 * 1 1 + 2 + 3 + . .. + n-1 = (n - 1)(n - 2) / 2 1/2 (n^2 - 2n - n + 2) O(n^2 - 2n - n) = O(n^2) best case: O(1) if the array length is 1 b) the first condition only runs once and is thus O(1) the slectionsort method call is executed twice. The algorythm inside selection sort is formed of two nested for loops. The outer loop executes as many times as the array's length - 1. The inner loop runs as many times as the array's length beginning at the position in the outer loop
Background image of page 1

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

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

This note was uploaded on 11/03/2009 for the course CS 01-119-10 taught by Professor D'arville during the Fall '09 term at Rutgers.

Page1 / 2

assign6-problem3 - Name Mihai Feraru a let n = length of...

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