»  ABAP Development
 Picture

From the Problem to the Algorithm

By: Andrew Kunizitz
Date Added : December 15, 2009 Views : 173
Rate Author : Current : 2.37 /5
Rate this Article : Current : 1.93 /5



Problem
A problem (an unsatisfactory situation) that needs to be solved is also referred to as a task. The path to devising a solution to this task often requires overcoming some obstacles. A way of transforming an initial situation (current state) into a goal (target state) needs to be found. Finding a solution to a task often requires using existing knowledge or breaking the task down into subtasks that can later be divided into more detailed units.

Problem Solving
Problem solving is an activity carried out to find a solution to a task. The approach taken to find a solution can be heuristic (learning by trial and error) or can involve applying a solution strategy. In computer science, a solution strategy is referred to as an algorithm. Provided an intelligent being can gather information (that can potentially help solve a problem), it can develop a solution strategy. If no information is available, the intelligent being carries out various activities (depending on the problem) until a solution is found or efforts are abandoned. If a solution is found, powers of recollection allow it to be reapplied again later if the situation reoccurs. This means that all activities do not have to be repeated. The time available and resources required to find a solution also play a crucial role in the process.

Steps to Solving a Problem
When a problem needs to be solved, it must first be understood before solutions are sought. If the steps required to reach a solution are defined explicitly, this is referred to as an algorithm.
Solving problems involves three main steps:
1. Identifying the problem (current state)
2. Devising and implementing a solution or algorithm
3. Checking the results (target state)

Solving Problems in Substeps
These steps can be broken down into the following substeps:
1. Identifying the problem and recording the current state
2. Gathering information that may help solve the problem (aids, solution approaches, and so on)
3. Selecting, grouping, and consolidating this information
4. Reducing the information to the information required
5. Evaluating the information
6. Applying solution strategies to devise solutions
7. Considering opportunities and risks
8. Solving the problem
9. Checking the results (target state)

The following example is intended to explain the procedure:
Substep 1: The CD "No Problemo" needs to be located from a CD stand within 30 seconds.
Substep 2 to 4: The location of the "No Problemo" CD in the CD stand is unknown.
There are a total of 100 CDs in the stand. They are arranged in alphabetical order. To locate the required CD, you could use one of the following approaches:
• Perform a linear search through all CDs (one after another) from top to bottom.
• Perform a linear search through all CDs from bottom to top.
• At a particular location in the CD stand, take out a CD. Based on the name of the CD, perform a linear search up or down the stand.
• Perform a linear search through the CDs and assign a number to each CD. Record the numbers in a list, allowing you to find CDs faster in future based on the numbers assigned. This approach could also be used even if the CDs are not sorted in the stand.
• Take out the CD located exactly half way down the stand. Depending on whether the title of the CD comes earlier or later in the alphabet, divide the relevant half of the stand and repeat the same check. These steps are repeated until the correct CD is found or it is evident that the CD is not on the stand. This type of search is known as a binary search.
• The following solution is similar to the previous approach. Assuming the CDs are sorted alphabetically, it can be presumed that CD titles (where they are used) beginning with "A" are at the top, and CD titles beginning with "Z" are at the bottom. This approach aims to start the search at a location closer to the required CD than the center of the stand, based on the title of the CD. The alphabet has 26 letters. If you divide the number of CDs by the number of letters in the alphabet, and multiply the result with the ordinal location of the letter (with which the CD title begins) in the alphabet, the result is generally a more favorable starting point for the search. The algorithm for the binary search is then used. The search applied here is known as an interpolation search.

Substep 5: All these solutions identified are viable. However, the first four approaches are particularly time-intensive. Once the CDs are assigned numbers, (approach 4) it is possible to locate the CD directly, which guarantees the fastest search. Approach 5 always yields a particularly fast result. The interpolation search (approach 6) generally always provides the fastest result.

Substep 6: The approach based on the list of titles and the reference to a number, or locating the CD using the search algorithm (approach 5), are favored:
• Write a list of the titles of all CDs and assign a number to each CD. Attach a label indicating the CD number to the outside of each CD. Any new CDs added are to be entered in the list and assigned the next available number.
• Divide the total number of CDs by two and save the value in a storage medium (in a variable named DISTANCE). This value is assigned to a second storage medium (variable POSITION). The CD located at POSITION is taken from the stand. If the title of this CD comes before the title of the required CD in the alphabet, the DISTANCE variable is divided by two and the value calculated is subtracted from the value of the POSITION variable. The CD at this new position is taken from the stand and the title is checked again. If the title of this CD comes after the required title in the alphabet, the DISTANCE variable is divided by two and the value calculated is added to the value of the POSITION variable. This process is repeated. To achieve an accurate result, it must also be taken into account that the distance values calculated have to be rounded up or down.

Substep 7: Approach 4 to the solution (creating a list) demands that the list be updated each time a CD is added to or removed from the collection. You need to decide whether the CDs are to be added to the bottom and assigned a new number. Perhaps the owner of the CDs would prefer to arrange all CDs from a particular band beside one another rather than adding them to the bottom. Approach 5 (binary search) or approach 6 (interpolation search) would not require any maintenance effort. New CDs are inserted at the correct location based on alphabetical sorting.

Substep 8: The preferred approach is implemented in pseudo code:
1. Alphabetically sort the 100 CDs in the CD stand according to band and title.
2. Specify the band and title of the required CD.
3. Calculate at which position in the alphabet the initial letter of the band occurs.
4. Calculate the initial search position: number of CDs divided by 26 (number of letters in the alphabet) * the ordinal location of the letter in the alphabet.
5. Execute and repeat the following steps until the required CD is found or it can be deduced that the CD being searched for is not on the stand:
• Take the CD located at the position calculated from the stand.
• Do the band name and title of this CD come after those of the required CD in the alphabet? If so, a value that is calculated (distance) is subtracted from the current value (current position). If the title found occurs before the title being searched for in the alphabet, a specific value (distance) is added to the current position.
• If the distance calculated is less than or equal to zero, the CD cannot be found and the search can be aborted.

Substep 9: Check whether the solution (algorithm) works and whether it can be applied in practice.

Exercise 1: Developing an Algorithm
Exercise Objectives
After completing this exercise, you will be able to:
• Develop an algorithm
Business Example
You work for the company "Calculate & Smile" and are to become a programmer in the ABAP environment. Before attending the course BC400 (ABAP Workbench Foundations), you need to acquire basic programming knowledge. You need to identify a problem and devise a suitable system-independent solution (an algorithm). This is an integral part of the development process and must be completed before programming begins.
Task 1:
Make various calculations.
1. You want to use a calculator to add, subtract, multiply, and divide two numbers.
Describe the steps you follow to reach your solution. (The calculator is already switched on and ready for use.)
Task 2:
Engage in a telephone conversation.
1. You want to make a call. Engage in a complete telephone conversation from start to finish. Remember that you may also receive a call. Also bear in mind that the call may take place on a landline phone (with a handset) or a cell phone.

Solution 1: Developing an Algorithm
Task 1:
Make various calculations.
1. You want to use a calculator to add, subtract, multiply, and divide two numbers.
Describe the steps you follow to reach your solution. (The calculator is already switched on and ready for use.)
a) Sample solution for the addition
1. Enter the first number.
2. Press the "+" button.
3. Enter the second number.
4. Press the "=" button.
5. The result is displayed.

Task 2:
Engage in a telephone conversation.
1. You want to make a call. Engage in a complete telephone conversation from start to finish. Remember that you may also receive a call. Also bear in mind that the call may take place on a landline phone (with a handset) or a cell phone.
a) The following example outlines a possible series of events for the call. There are of course other alternative solutions.

Post Article Comments

Name : 
EmailAddress : 
URL : 
Comments :