Tags

, ,

What is an algorithm?
Algorithm in computer programming is a series of logical steps from a given input to a desired output. It is also used as a problem-solving technique.

Scenario:

  • Let us say you want to program the computer to display the number of times a word occurs in a sentence.
  • It does not matter what programming language you use, because algorithm is not specific to any programming language.
  • Beginning with input from the user to the output generated by the program, you outline the processing required to achieve the result.

Example:
For the scenario outlined above.

Prompt user to enter a sentence.
Accept the sentence as a string of words.
Prompt to enter a word whose frequency of occurrence you need to check.
Accept and store the word.
Loop over each character in the string.
Check character to see if it is empty space.
Hold characters until you hit space and concatenate to form a word.
Check word against the user's input word.
If match occurs, increment a counter. If not, continue till the end of the loop.
Print count.

What youI need?
A computer, a programming language compiler and a text editor.

Note: The word algorithm derived from a Persian mathematician Ja’far Mohammed Ben Musa a.k.a al-Khowarazmi, meaning “the man from Khwarazm.”

Advertisements