hw2 - Homework 2 CSE 450/598 Spring 2010 Arizona State...

Info iconThis preview shows pages 1–2. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Homework 2 CSE 450/598 Spring 2010 Arizona State University Due: Tuesday 2/2 before 10:30 1. (2.6) Youre given an integer array A = ( A [ 1 ] , A [ 2 ] ,..., A [ n ]) . Your goal is to output an n by n array B = [ B [ i , j ]] , where B [ i , j ] = A [ i ] + A [ i + 1 ] + + A [ j ] for i < j (for i > j the value of B [ i , j ] is not specified, so it doesnt matter what is output for these values). Heres an algorithm to solve this problem: for i = 1, 2, ..., n: for j = i+1, i+2, ..., n: add up array entries A[i] through A[j] store the result in B[i,j] (a) Pick a function f and show that the running time of the algorithm is O ( f ( n )) for an input of size n . (b) For the same function f show that the running time of the algorithm is also ( f ( n )) . (Here you may have to go back to the previous part and correct your answer if this is not true for the function you had picked. (c) The algorithm youve just analyzed is, in fact, not very efficient. Give a different algorithm to solve the same problem, with an asymptotically better running time: if your algorithm has running time O ( g ( n )) , then it should be the case that g o ( f ) . 2. (2.8) Youre doing stress-testing of glass jars to determine the maximum safe height from which they can be dropped without breaking. The experiment (for a particular fixed typewhich they can be dropped without breaking....
View Full Document

Page1 / 2

hw2 - Homework 2 CSE 450/598 Spring 2010 Arizona State...

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