Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An algorithm is a step-by-step procedure to solve a problem. It is an important step in planning a program. You will find that as programs

An algorithm is a step-by-step procedure to solve a problem. It is an important step in planning a program. You will find that as programs become more complicated, proper planning is invaluable in creating a good program. Algorithms are expressed in natural language. There are no set rules for formatting. An algorithm should be written clearly and unambiguously.

program is the implementation of an algorithm using a specific programming language. When you write a program, you must adhere to the rules of the language you are using. Before we start to write computer programs, we will practice writing some algorithms.

For both an algorithm and a program, you generally need to know:

  1. What input do you need? This what you need to know up-front — you are either given this information or you need to ask for it, specifically and in detail.
  2. What needs to be done? This is the computation part. Given the input, what do you do with it?
    This may be a series of steps, but sometimes involves one or more loops with repeating steps.

The order of the steps is generally important.

  1. What outputs (results) do you expect to get?

Write algorithms (in English) to solve the following problems:

A. Cook scrambled eggs

B. Find the largest of three numbers. Now generalize this: how would you find the largest of a series of numbers (the number of numbers not being known in advance).

C. Find the cost of landscaping a rectangular backyard with sod that is sold by the square foot and fencing that is sold by the foot.

D. Find the cost of gas for a trip from NY to Washington. What is more economical – to drive your car from NY to Washington or to rent a car that charges a per-day fee and an additional charge by the mile? Hint: the most important attribute of cost is the efficiency of your car (it will get so-many miles-per-gallon [mpg]. Is the capacity of your fuel-tank relevant to your calculation? Remember, you can always stop when your tank is running low, and any fuel remaining in the tank is useful for other trips. You can make the assumption (not true in reality) that the price of gasoline is the same everywhere — that is an assumption and generally you want to list all your assumptions when you develop an algorithm. What other factors might go into the cost for this trip? (you only need to list them) — which of these would perhaps be different for a personal car and for a rental car?

E. Find the sum of 100 numbers, then find their average. Would your algorithm be different if you did not know the number of numbers in advance (what if it were not 100 numbers and you were only told how many by the fact there are no more when you ask for the next number?)?

Step by Step Solution

3.48 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

A Cook Scrambled Eggs Gather ingredients eggs butter salt pepper and milk if desired Crack eggs into a mixing bowl Add milk if desired and a pinch of salt and pepper to the eggs and whisk until well c... 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

Probability and Stochastic Processes A Friendly Introduction for Electrical and Computer Engineers

Authors: Roy D. Yates, David J. Goodman

3rd edition

1118324560, 978-1118324561

More Books

Students also viewed these Computer Engineering questions