Question: 4. Algorithms (9 points) In general we express algorithms in pseudocode, i.e., in a sequence of statements that resemble some programming language. Pseudocode comprises step-by-step

4. Algorithms (9 points) In general we express algorithms in pseudocode, i.e., in a sequence of statements that resemble some programming language. Pseudocode comprises step-by-step instructions that execute a solution. Using your own pseudocode write algorithms for the following problems. Your pseu- docode could be any syntactically-relaxed programming language that you like or just plain pseudocode as we've used in class. (a) (3 points) Write an algorithm to compute the sum u(n) (-1)2i = (-1)2+(-1)4 +(-1)6... (b) (3 points) Consider the following algorithm. Assuming that you are paying $ 1 for each numerical operation, what is the cost to run this algorithm in terms of n and m? Why? input : Variables n and m output: u(n) = {1-(i2 + j) sum - 0; for i 1 to n do for j 1 to m do | sum sum +12 + j?; end end (c) (3 points) Given the algorithm in the previous problem, is there a way to reduce the cost of running it? By how much? Why? 4. Algorithms (9 points) In general we express algorithms in pseudocode, i.e., in a sequence of statements that resemble some programming language. Pseudocode comprises step-by-step instructions that execute a solution. Using your own pseudocode write algorithms for the following problems. Your pseu- docode could be any syntactically-relaxed programming language that you like or just plain pseudocode as we've used in class. (a) (3 points) Write an algorithm to compute the sum u(n) (-1)2i = (-1)2+(-1)4 +(-1)6... (b) (3 points) Consider the following algorithm. Assuming that you are paying $ 1 for each numerical operation, what is the cost to run this algorithm in terms of n and m? Why? input : Variables n and m output: u(n) = {1-(i2 + j) sum - 0; for i 1 to n do for j 1 to m do | sum sum +12 + j?; end end (c) (3 points) Given the algorithm in the previous problem, is there a way to reduce the cost of running it? By how much? Why
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
