Learn a basic process for occurring a equipment to a problem. Nothing in this thing is unique to utilizing a computer to resolve a problem. This process can be provided to settle a wide variety of problems, consisting of ones that have nothing to perform with computers.

You are watching: An algorithmic solution to a problem is one in which


I have a problem! I should thank Aunt Kay because that the birthday existing she sent me. I can send a thank you keep in mind through the mail. Ns could call her on the telephone. I can send her an email message. I could drive to her house and thank she in person. In fact, over there are numerous ways I might thank her, yet that"s no the point. The point is that I must decide exactly how I want to resolve the problem, and use the ideal tool to implement (carry out) my plan. The postal service, the telephone, the internet, and my vehicle are devices that I have the right to use, however none that these in reality solves mine problem. In a similar way, a computer does not settle problems, it"s simply a tool that I can use to implement my plan for fixing the problem.

Knowing the Aunt Kay appreciates an innovative and unexplained things, i have decided to hire a singing messenger to supply my thanks. In this context, the messenger is a tool, but one that needs instructions indigenous me. I have to tell the messenger wherein Aunt Kay lives, what time i would like the article to it is in delivered, and what lyrikeolistravelservices.com I desire sung. A computer program is comparable to my instructions to the messenger.

The story that Aunt Kay supplies a familiar context to collection the phase for a useful allude of view worrying computers and also computer programs. The adhering to list summarizes the an essential aspects the this point of view.


A computer is a tool that have the right to be supplied to carry out a arrangement for solving a problem.

A computer system program is a collection of instructions because that a computer. These instructions describe the actions that the computer must follow to perform a plan.

An algorithm is a setup for solving a problem.

A person must design an algorithm.

A human being must interpret an algorithm right into a computer program.


This suggest of watch sets the stage for a procedure that we will use to build solutions come Jeroo problems. The basic procedure is important since it have the right to be used to resolve a wide selection of problems, including ones where the systems will be composed in some other programming language.


An Algorithm advance Process


Every problem solution starts v a plan. That arrangement is dubbed an algorithm.


an algorithm is a setup for fixing a problem.

There are many ways to write an algorithm. Part are really informal, part are rather formal and also mathematical in nature, and some are fairly graphical. The instructions for connecting a DVD player come a television space an algorithm. A mathematical formula such together πR2 is a special situation of an algorithm. The type is not an especially important as long as it gives a good way to describe and also check the reasonable of the plan.

The development of one algorithm (a plan) is a key step in resolving a problem. As soon as we have actually an algorithm, we deserve to translate it into a computer program in some programming language. Ours algorithm development procedure consists that five major steps.


Step 1: achieve a summary of the problem.

Step 2: analyze the problem.

Step 3: construct a high-level algorithm.

Step 4: refine the algorithm through adding more detail.

Step 5: evaluation the algorithm.


Step 1: attain a description of the problem.

This action is much more daunting than the appears. In the adhering to discussion, words client describes someone who desires to uncover a systems to a problem, and the native developer refers to someone that finds a means to settle the problem. The developer must develop an algorithm the will solve the client"s problem.

The customer is responsible for producing a summary of the problem, yet this is often the weakest part of the process. It"s quite typical for a problem description to endure from one or an ext of the following types of defects: (1) the summary relies ~ above unstated assumptions, (2) the summary is ambiguous, (3) the description is incomplete, or (4) the summary has internal contradictions. This defects are seldom due to carelessness by the client. Instead, castle are as result of the fact that organic languages (English, French, Korean, etc.) are rather imprecise. Component of the developer"s responsibility is to recognize defects in the summary of a problem, and also to occupational with the customer to remedy those defects.

Step 2: analysis the problem.

The purpose of this action is to recognize both the beginning and finishing points for resolving the problem. This process is analogous to a mathematician identify what is given and also what have to be proven. A great problem description makes it less complicated to execute this step.

When identify the beginning point, we have to start by search answers come the adhering to questions:

What data space available?

Where is the data?

What formulas pertain come the problem?

What rules exist because that working v the data?

What relationships exist among the data values?

When determining the ending point, we need to define the characteristikeolistravelservices.com the a solution. In various other words, exactly how will we recognize when we"re done? asking the adhering to questions regularly helps to determine the ending point.

What new facts will we have?

What item will have changed?

What transforms will have been made to those items?

What points will no longer exist?

Step 3: construct a high-level algorithm.

An algorithm is a arrangement for addressing a problem, however plans come in numerous levels of detail. It"s usually better to begin with a high-level algorithm that has the major part of a solution, but leaves the details until later. We can use an daily example to demonstrate a high-level algorithm.

Problem: I require a send a birthday map to my brother, Mark.

Analysis: ns don"t have actually a card. I choose to purchase a card fairly than make one myself.

High-level algorithm:

go to a save that sells greeting cards pick a card purchase a card Mail the card

This algorithm is satisfactory for daily use, yet it lacks details the would need to be included were a computer system to lug out the solution. These details encompass answers to inquiries such together the following.

"Which keep will i visit?"

"How will certainly I obtain there: walk, drive, ride mine bicycle, take it the bus?"

"What sort of card does mark like: humorous, sentimental, risqué?"

These type of details are taken into consideration in the next step of our process.

Step 4: refine the algorithm by adding much more detail.

A high-level algorithm shows the major steps that must be adhered to to fix a problem. Currently we need to include details to these steps, yet how much information should we add? Unfortunately, the answer to this concern depends top top the situation. We have to take into consideration who (or what) is going to implement the algorithm and how lot that human (or thing) currently knows just how to do. If someone is walking to acquisition Mark"s birthday card on mine behalf, my instructions need to be adapted to whether or no that human being is acquainted with the stores in the community and also how fine the purchaser recognized my brother"s taste in greeting cards.

When our score is to build algorithms that will certainly lead to computer system programs, we require to take into consideration the capabilities of the computer and provide enough detail so that someone else can use ours algorithm to write a computer program that adheres to the steps in ours algorithm. As with the birthday card problem, we require to readjust the level of information to enhance the capacity of the programmer. As soon as in doubt, or as soon as you space learning, it is much better to have too much detail than to have actually too little.

Most that our instances will relocate from a high-level to a in-depth algorithm in a solitary step, however this is not always reasonable. For larger, more facility problems, that is usual to go v this procedure several times, emerging intermediate level algorithms as we go. Every time, we add much more detail come the ahead algorithm, stopping when we view no benefit to more refinement. This an approach of slowly working indigenous a high-level to a in-depth algorithm is often dubbed stepwise refinement.


Stepwise refinement is a procedure for arising a thorough algorithm by gradually adding detail to a high-level algorithm.

Step 5: testimonial the algorithm.

The final step is to review the algorithm. What space we feather for? First, we need to work through the algorithm step by action to identify whether or not it will solve the initial problem. Once we space satisfied the the algorithm does carry out a equipment to the problem, we begin to watch for other things. The adhering to questions are typical of people that need to be inquiry whenever we review an algorithm. Asking these questions and seeking your answers is a great way come develop an abilities that can be used to the following problem.

Does this algorithm solve a very particular problem or walk it solve a more basic problem? If that solves a very particular problem, have to it be generalized?

For example, one algorithm that computes the area that a circle having actually radius 5.2 meter (formula π*5.22) solves a very certain problem, however an algorithm that computes the area of any type of circle (formula π*R2) solves a more general problem.

Can this algorithm it is in simplified?

One formula for computing the perimeter that a rectangle is:

length + broad + size + width

A simpler formula would be:

2.0 * (length + width)

Is this systems similar come the solution to one more problem? how are lock alike? exactly how are they different?

For example, take into consideration the adhering to two formulae:

Rectangle area = length * width Triangle area = 0.5 * basic * height

Similarities: every computes an area. Each multiplies 2 measurements.

Differences: different measurements are used. The triangle formula includes 0.5.

Hypothesis: possibly every area formula requires multiplying two measurements.


This section contains prolonged example that demonstrates the algorithm development process. To complete the algorithm, we need to understand that every Jeroo have the right to hop forward, turn left and right, pick a flower native its current location, and plant a flower at its existing location.

Problem explain (Step 1)

A Jeroo starts in ~ (0, 0) facing east with no flower in that is pouch. There is a flower at place (3, 0). Compose a regime that directs the Jeroo to choose the flower and plant it at ar (3, 2). After planting the flower, the Jeroo need to hop one room East and also stop. There are no various other nets, flowers, or Jeroos ~ above the island.

StartFinish
*
*

Analysis that the difficulty (Step 2)

The flower is exactly three spaces front of the jeroo.

The flower is to it is in planted precisely two spaces south of its present location.

The Jeroo is to finish facing eastern one an are East that the planted flower.

There space no nets to worry about.

High-level Algorithm (Step 3)

Let"s name the Jeroo Bobby. Bobby need to do the following:

get the flower placed the flower Hop east

Detailed Algorithm (Step 4)

Let"s name the Jeroo Bobby. Bobby have to do the following:

gain the flower

Review the Algorithm (Step 5)

The high-level algorithm partitioned the problem into three fairly easy subproblems. This seems favor a an excellent technique.

This algorithm solves a very certain problem since the Jeroo and the flower are in very details locations.

This algorithm is actually a systems to a slightly an ext general problem in i beg your pardon the Jeroo beginning anywhere, and also the flower is 3 spaces straight ahead the the Jeroo.

Java password for "Pick and Plant"

A an excellent programmer doesn"t write a routine all in ~ once. Instead, the programmer will write and test the regimen in a collection of builds. Each construct adds to the ahead one. The high-level algorithm will guide us in this process.


A an excellent programmer functions incrementally, add tiny pieces one in ~ a time and constantly re-checking the job-related so far.
very first BUILD

To check out this equipment in action, produce a new Greenfoot4keolistravelservices.com scenario and use the Edit Palettes Jeroo menu command to make the Jeroo class visible. Right-click top top the Island class and also create a new subclass v the name of her choice. This subclass will organize your brand-new code.

The recommended first build includes three things:

The main technique (here myProgram() in her island subclass).

Declaration and also instantiation the every Jeroo that will be used.

The high-level algorithm in the type of comments.

public void myProgram() Jeroo bobby = new Jeroo(); this.add(bobby); // --- gain the flower --- // --- put the flower --- // --- Hop eastern --- // ===== end of method myProgram() ===== The instantiation in ~ the beginning of myProgram() areas bobby in ~ (0, 0), dealing with East, v no flowers.

Once the very first build is working correctly, we deserve to proceed come the others. In this case, each construct will correspond to one step in the high-level algorithm. It might seem favor a the majority of work to use four builds because that such a straightforward program, but doing so help establish behavior that will come to be invaluable as the program become an ext complex.

2nd BUILD

This construct adds the reasonable to "get the flower", i m sorry in the in-depth algorithm (step 4 above) consists of to dance 3 times and then picking the flower. The brand-new code is suggested by comments that wouldn"t appear in the original (they space just right here to speak to attention come the additions). The blank lines aid show the company of the logic.

public void myProgram(){ Jeroo bobby = brand-new Jeroo(); this.add(bobby); // --- obtain the flower --- bobby.hop(3); // By acquisition a moment to run the occupational so far, you deserve to confirm even if it is or no this step in the planned algorithm functions as expected.

3rd BUILD

This develop adds the logic to "put the flower". New code is shown by the comments the are noted here to mark the additions.

public void myProgram(){ Jeroo bobby = brand-new Jeroo(); this.add(bobby); // --- acquire the flower --- bobby.hop(3); bobby.pick(); // --- put the flower --- bobby.turn(RIGHT); // FOURTH build (final) This build adds the reasonable to "hop East".public void myProgram(){ Jeroo bobby = brand-new Jeroo(); this.add(bobby); // --- gain the flower --- bobby.hop(3); bobby.pick(); // --- placed the flower --- bobby.turn(RIGHT); bobby.hop(2); bobby.plant(); // --- Hop eastern --- bobby.turn(LEFT); //
This section includes a 2nd example the demonstrates the algorithm breakthrough process.

Problem explain (Step 1)

There space two Jeroos. One Jeroo starts in ~ (0, 0) encountering North v one flower in its pouch. The second starts at (0, 2) facing eastern with one flower in the pouch. Over there is a net at location (3, 2). Compose a regime that directs the an initial Jeroo to give its flower to the 2nd one. ~ receiving the flower, the 2nd Jeroo have to disable the net, and plant a flower in its place. After planting the flower, the Jeroo should turn and face South. There space no other nets, flowers, or Jeroos ~ above the island.

StartFinish
*
*

Analysis the the problem (Step 2)

Jeroo_2 is precisely two spaces behind Jeroo_1.

The just net is exactly three spaces front of Jeroo_2.

Each Jeroo has specifically one flower.

Jeroo_2 will have actually two flower after receiving one indigenous Jeroo_1. One flower have to be supplied to disable the net. The various other flower must be planted in ~ the location of the net, i.e. (3, 2).

Jeroo_1 will end up at (0, 1) facing South.

Jeroo_2 is to end up at (3, 2) encountering South.

Each Jeroo will end up with 0 flowers in its pouch. One flower was used to disable the net, and the other was planted.

High-level Algorithm (Step 3)

Let"s name the very first Jeroo Ann and also the second one Andy.

Ann need to do the following:
discover the network (but don"t hop top top it) Disable the net Plant a flower at the location of the net confront South

Detailed Algorithm (Step 4)

Let"s name the very first Jeroo Ann and the 2nd one Andy.

Ann need to do the following:

Review the Algorithm (Step 5)

The high-level algorithm helps regulate the details.

This algorithm solves a very details problem, yet the details locations are not important. The just thing the is essential is the starting location the the Jeroos loved one to one another and the place of the net relative to the second Jeroo"s location and also direction.

Java code for "Replace Net v Flower"

As before, the code have to be composed incrementally as a series of builds. 4 builds will be perfect for this problem. Together usual, the first build will certainly contain the main method, the declaration and instantiation that the Jeroo objects, and also the high-level algorithm in the kind of comments. The 2nd build will have Ann offer her flower to Andy. The third build will have Andy locate and also disable the net. In the final build, Andy will ar the flower and turn East.

very first BUILD

This build creates the main method, instantiates the Jeroos, and also outlines the high-level algorithm. In this example, the main method would be myProgram() contained within a subclass that Island.

public void myProgram() Jeroo ann = new Jeroo(0, 0, NORTH, 1); this.add(ann); Jeroo andy = new Jeroo(0, 2 , 1); // default eastern this.add(andy); // --- Ann, find Andy --- // --- Ann, give Andy a flower --- // --- Andy, find and also disable the net --- // --- Andy, ar a flower in ~ (3, 2) --- // --- Andy, face South --- // ===== end of technique myProgram() ===== 2nd BUILD This construct adds the logic for Ann to locate Andy and give that a flower.

public void myProgram() Jeroo ann = new Jeroo(0, 0, NORTH, 1); this.add(ann); Jeroo andy = brand-new Jeroo(0, 2 , 1); // default eastern this.add(andy); // --- Ann, find Andy --- ann.turn(LEFT); ann.turn(LEFT); ann.hop(); // Now, Ann is at (0, 1) encountering South, and also Andy is directly ahead // --- Ann, provide Andy a flower --- ann.give(AHEAD); // Ann now has 0 flowers, Andy has 2 // --- Andy, find and also disable the network --- // --- Andy, location a flower in ~ (3, 2) --- // --- Andy, confront South --- // ===== end of technique myProgram() ===== third BUILD This build adds the logic for Andy come locate and also disable the net.

See more: What Happens If You Swallow Too Much Blood, Eli5: Why Is It Harmful To Swallow Blood

public void myProgram() Jeroo ann = new Jeroo(0, 0, NORTH, 1); this.add(ann); Jeroo andy = new Jeroo(0, 2 , 1); // default east this.add(andy); // --- Ann, discover Andy --- ann.turn(LEFT); ann.turn(LEFT); ann.hop(); // Now, Ann is in ~ (0, 1) facing South, and Andy is straight ahead // --- Ann, offer Andy a flower --- ann.give(AHEAD); // Ann now has actually 0 flowers, Andy has 2 // --- Andy, find and also disable the network --- andy.hop(2); // Andy is in ~ (2, 2) encountering the net andy.toss(); // --- Andy, location a flower at (3, 2) --- // --- Andy, face South --- // ===== finish of an approach myProgram() ===== FOURTH construct (final) This develop adds the logic because that Andy to location a flower in ~ (3, 2) and also turn South.

public void myProgram() Jeroo ann = brand-new Jeroo(0, 0, NORTH, 1); this.add(ann); Jeroo andy = brand-new Jeroo(0, 2 , 1); // default eastern this.add(andy); // --- Ann, find Andy --- ann.turn(LEFT); ann.turn(LEFT); ann.hop(); // Now, Ann is in ~ (0, 1) encountering South, and also Andy is directly ahead // --- Ann, give Andy a flower --- ann.give(AHEAD); // Ann now has actually 0 flowers, Andy has actually 2 // --- Andy, find and disable the net --- andy.hop(2); // Andy is in ~ (2, 2) facing the net andy.toss(); // --- Andy, ar a flower at (3, 2) --- andy.hop(); andy.plant(); // --- Andy, face South --- andy.turn(RIGHT); // ===== finish of technique myProgram() ===== © 2012 Stephen Edwards, Brian Dorn, and also Dean Sanders