Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Algorithms (12 points + 3 bonus points) In general we express algorithms in pseudocode, i.e., in a sequence of statements that resemblesomeprogramminglanguage. Pseudocodecomprisesstep-by-stepinstructions that execute

Algorithms (12 points + 3 bonus points) In general we express algorithms in pseudocode, i.e., in a sequence of statements that resemblesomeprogramminglanguage. Pseudocodecomprisesstep-by-stepinstructions that execute a solution. Using your own pseudocode write algorithms for the following problems. Your pseudocode could be any syntactically-relaxed programming language that you like or just plain pseudocode as weve used in class. (a) (3 points) Write an algorithm to compute the sum u(n) = n X i=1 (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) =Pn i=1Pm j=1(i2 + j2) sum 0; for i 1 to n do for j 1 to m do sumsum+ i2 + j2;endend (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? (d) (3 points) Write an algorithm that will convert military-style time to ante meridiem or post meridiem time. For example, 1800 76 : 00 PM.(e) (3 bonus points) Write an algorithm that will take as input the number n such that 1 6 n 6 366 and will return the day and month in a year, assuming that n = 1 7January 1, n = 2 7January 2, ..., n = 31 7January 31, n = 32 7February 1, etc. image text in transcribed

1. Algorithms (12 points 3 bonus 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 cxccute 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 sunm ! (b) (3 points) Consider the following algorithm. Assuming that you are paying S 1 for each numerica operation, what is the cost to run this algorithm in tes of n and m? Why? input : Variables n and m output: u(n)- n-1 ml(i2 + j2) sum for i 1 to n do forj1 to m do sumsum2 end end (c) (3 points) Given the algorithm in the previous problem, is there a way to reduce (d) (3 points) Write an algorithm that will convert military-style time to ante meri (e) (3 bonus points) Write an algorithm that wll take as input the number n such n = 1-January 1, the cost of running it? By how h? Why? diem or post meridiem time. For example, 1800 >6:00 PM that I 366 and will return the day and month in a year, assuming that n = 2-January 2, n-31 n-32 February 1, etc. January 31

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions

Question

Describe the activities involved in completing the audit.

Answered: 1 week ago

Question

2.1 Explain the importance of a brand to an organisation

Answered: 1 week ago

Question

Do you think physicians should have unions? Why or why not?

Answered: 1 week ago