Category Archives: programming

Problem solving Strategies for Software Programmers

Programming is a problem solving activity. When you write a program, you are actually writing an instruction for a computer to solve some problem. Overtime,  there are several strategies that have been developed and applied to solve problems. Problem solving is the processing of transforming problem from initial state to a desired  state. Some techniques are more effective while others are less. Here I outline some of the common strategies

Trial and Error – This is also known as solving problems using guess and check or generate and test. While it is certainly true that we don’t want to simply guess random answers as a means of solving problems, there are instances when educated guesses are important, valid and useful. For instance estimating the time an activity will end is an example of an informed guess. This techniques works like this:

  • Form an educated guess
  • Check your solution to see if it works and solves the problem
  • If not, revise your guess based on whether it is too high or too low
  •  

Root Cause analysis – a sequence of cause and effect is investigated until the origin of the problem is identified. Root Cause Analysis (RCA) is a systematic concept that involves a set of problem-solving approaches used to determine the underlying cause of an issue. In most cases, when a problem occurs, it creates other problems and resulting problems create others. For instance, in one of the software systems we discovered that some parts of the system were becoming very slow. On further analysis, the page was loading too much data. On further analysis the users where not closing the visiting, leaving many data points to be queried. So a possible solution was to close the visits programmatically after some time. The alternative solution could have been to add more RAM and processing power to the computers. Tools that can help in carrying out effective root cause analysis include the 5 WHY and the Fish Bone Diagram.

Algorithms – in this approach one defines set of step-by-step procedures that provides the correct answer to a particular problem. By following the instructions correctly, you are guaranteed to arrive at the right answer. An algorithm provides specific rules that guarantee a solution.

Brain Storming – Here the methods works by collecting a large number of ideas until one works. Some of these ideas can be crafted into original, creative solutions to a problem, while others can spark even more ideas.

Analogies – Here we compare parallels and make analogies to some other fields where the problem can easily be understood. An analogy is an abstract parallel between two quite different things. For example, you might analogize driving to project management. In both cases it helps to have a map (i.e., a plan) for where you’re going. An analog is a comparison between two objects, or systems of objects that highlights aspects in which they are thought to be similar. Analogical reasoning is any type of thinking that relies upon an analogy. Note that analogy is a cognitive process in which the problem solvers reason through the relationship between the prior experience and the current problem. There are three steps to

  • Mapping step
  • Application Step (Inference Step)
  • Learning Step

Challenges with this approach include ability to find relevant analogies and ability to resist false counter-suggestions that would destroy the analogy.

Working backwards – Working backwards is to start with the final solution and work back one step at a time to get to the beginning. This process will include the following

  • Work back through the logic of what is causing the problem, using the 5WHY’s process or any information that may be relevant, to the ‘resources’ that are driving it.
  • Look at the history of the events that have brought the situation to its current level.
  • Sketch out how you think a solution for the future might work, by changing the input flows and working through what could happen to input and output levels.

This technique works well when

  • The final result is clear and the initial portion of a problem is obscure.
  • A problem proceeds from being complex initially to being simple at the end.
  • A direct approach involves a complicated equation.
  • A problem involves a sequence of reversible actions.

Means End analysis – In this technique aims to apply sequence of transformations that directly target the end state. As described, a problem exists in a current state (initial state) that must be transformed to arrive at given final state. So one might look at the current state, identify the differences between the current state and final state and then keep on providing solutions to the differences. For instance, start at initial state and then create every possible permutation from my initial state. The next step is to calculate the difference in the states just made and end state. In summary:-

  • Identify your current state,
  • Identify where you want to be (your goal state),
  • Identify the means that will get you there.

Brute force – Here we systematically try all possible solutions until one of them works. For instance if I know that pin number to unlock a phone is 4 digits, then I can try all the possible 4 digit combinations because the pin is one of them. This approach works where the solution space is well known and can be traversed in reasonable amount of time. The approach also requires checking each of the possible solution whether it is correct or not.

Hill Climbing – This technique involving choosing any available option that moves you closer to the solution. One challenge with this approach is that the chosen move may appear to move closer to the solution but is incapable of progressing to final solution. We call this getting stuck at local maxima. Local maxima are states that are closer to a goal than any neighboring state but they are not a goal state.

In conclusion, the different strategies outlined above, fall under two broad categories of Algorithmic approaches and Heuristic approaches. Hill climbing, brute force, trial and error, means ends analysis, working backwards all belong to the heuristic strategies because they lack systematic step by step procedures that guarantee a solution all the time. Algorithmic problem solving is more common in computer programming and several algorithms such as bubble sort and binary search among others that solve specific problems.

Loading

Problem solving for computer programmers – Well and Ill-defined problems

In practice, a problem occurs when a problem solver has a goal but initially does not know how to reach the goal. So, the problem begins in a given state (current state) and the problem solver wants the problem in another state (goal state). Problem solving is required to transform the current state to the goal state. Therefore problem solving is application of ideas, skills, or actual information to achieve the solution to a problem or reach a desired outcome.

In light of the above, a well-defined problem provides clear description of the initial state, allowed operations and the goal. Well-defined problems  have clear goals or solution and its problem solving strategies are easily developed. On the other hand, ill-defined problems do provide specific guidance in terms of what is expected.

As an example, most of you might be familiar with the wolf, goat and cabbage farmer river-crossing problem. It is usually told that once upon a time, a farmer went to a market and purchased a wolf, goat and cabbage. On his way home, the farmer came to the bank of a river and rented a boat. But crossing the river by boat, the farmer could carry only himself and a single one of his purchases: the wolf, the goat, or the cabbage. If left unattended together, the wolf would eat the goat, or the goat would eat the cabbage. The farmer’s challenge was to carry himself and his purchases to the far bank of the river, leaving each purchase intact. How can this be achieved?

The above, is a well-stated problem with a clear initial state, allowed operations and final state. In dealing, with programming, which is largely a problem-solving job, because the role of the programmer is to give solutions to the computer for it to execute. Remember that computers just follow the programmed solutions.

“Write a computer program for music” is an example of an ill-defined problem. It neither states the initial state nor the final goal. Generally, ill-defined problems come out as ambiguous, provoke several interpretations and it is not obvious when a solution has been reached.  In addition, ill-defined problems are are unclear, abstract, or confusing and do not have clear problem solving strategies. One strategy to solved ill-defined problems is to add constraints for which the solution will be valid. Such constraints are called operational constraints. In the music playing example, one may add that the program should play, pause, and stop play songs format mp3.

In conclusion, as a way of understanding a problem, problem solvers and particularly programmers should identify the three aspects of the problem for any meaningful and acceptable solution to be accepted.

Loading

Problem Solving – Analyse/Understand the Problem

The goal of problem analysis is to gain better understanding of the problem being solved before development begins. It is import to know why the problem is occurring, when and how often. Try to understand the first cause of the problem. Root cause analysis is a systematic way of uncovering the root, or underlying first cause of an identified problem or a symptom to the problem. Tools such as fishbone diagram or pareto chart can help visualize the problem.

Identify stakeholders – understand needs of users or other stakeholders. A stakeholder is anybody affected by the implementation of a new system or application. Probing questions include

    • who are the users of the system?
    •  who is the customer?
    • who else will be affected by the system?

Define a solution boundary- the solution boundary divides the world into two parts, your system and the rest of the things that interact with your system. The system boundary defines the border between the solution and the real world that surrounds the solution. A boundary is an interface between the system and the environment or other system. All interactions with the system occur via interfaces between the system and the external world.

Understand what is involved in solving the problem. This is involves a identifying what is information is needed and what information is available.

Identify constraints to be imposed on the system – a constraint is a restriction to the degrees of freedom we have in providing a solution. Constraints may be political, economical, environmental, technological, materials and resources as described below
Economical

  • What financial or budgetary constraints apply?
  • Are there costs of goods sold or any product pricing considerations?
  • Are there any licensing issues?

Politics

  • Do internal or external political issues affect potential solutions?
  • Are there any interdepartmental problems or issues?

Technology

  • Are we restricted in our choice of technologies?
  • Are we constrained to work within existing platforms or technologies?
  • Are we prohibited from using any new technologies?
  • Are we expected to use any purchased software packages?

Systems

  • Is the solution to be built on our existing systems?
  • Must we maintain compatibility with existing solutions?
  • What operating systems and environments must be supported?

Environment

  • Are there environmental or regulatory constraints?
  • Are there legal constraints?
  • What are the security requirements?
  • What other standards might restrict us?

Schedule and Resources

  • Is the schedule defined?
  • Are we restricted to existing resources?
  • Can we use outside labor?
  • Can we expand resources? Temporarily? Permanently?

Loading

Problem solving -Define the problem

“Until the problem is well defined and articulated it is impossible to arrive at a solution”

The first step to solving any software engineering problem is to define the problem. Articulate the problem and eliminate all unnecessary terminologies and jargons. Start by reading the problem completely at least twice. Read and establish the context of each key word. If time allows, research about the problem.

Ensure that there is agreement on the problem to be solved. Try to restate the problem in you own understanding.  Find out from the person who posed the problem whether the restated problem is the same as the original problem. Identify instances of the problem and see it is possible to solve an instance or example problem A solution to the example problem may lead to insights about how to solve the general problem or bring about any remaining misunderstanding.

Look at the problem from multiple perspectives. Each perspective may reveal additional information about the problem. The problem should be distinguished from its symptoms such that the root cause properly identified and stated.

The output of this step is a well-defined and articulated problem that focuses on what is required for its solution.

Loading

Software programming and problem solving

Programming is the process of planning a sequence of steps called instructions for the computer to follow. The fact that you are reading this post you already know that computers lack common sense and cannot make any judgment. So the computer will do as instructed by the programmer through the computer program. Programming is more about problem solving than coding.

A problem is the difference between things as perceived and things as desired. A solution will move the situation from the things as perceived to the things as desired.

Programmers are problem solvers and need to improve the art and science of problem solving. On one hand problem solving involves an element of art in that experience, judgment and common sense can help deliver smart solutions. On the other hand problems solving is a science involving scientific means of arriving at solutions. Overall, there are several steps to be taken to solve problems

  • Define the problem
  • Analyse the problem
  • List/Identify  alternative solutions
  • Select the best solution
  • List instructions that lead to the solution using the selected solution
  • Evaluate the solution

in the next post, more details on each step shall be discussed

Loading