• Question: what is algorithm?

    Asked by ellis13adam12 to Yee Whye, Valerie, Nick, Mackenzie, Lin, Jun, Jacob, Brian, Anna on 14 Nov 2019.
    • Photo: Jacob Leygonie

      Jacob Leygonie answered on 14 Nov 2019:


      Good question!

      There are possibly several approaches to talk about algorithms. Let me propose a simple one. An algorithm is a list of instructions. Often, we name the algorithm. The following is an example:

      Title of algorithm: Receipt of a strange cake

      1) Put 1kg of chocolate in microwave.

      2) Mix with eggs and flour.

      3) Add butter.

      4) Eat.

      An algorithm has to be “executed” by someone. The person that executes the algorithm should be able to A) understand the langage of the algorithm; and B) be able to do (execute) each instruction.

      For instance, the algorithm “Receipt of a strange cake” can be interpreted and executed by a human being; but could not even be interpreted by a computer. A computer understands only simple langages (with a very small vocabulary): for instance Java, Python, C. These are really langages like english, french or german, but are much simpler, so that it is easy for us human to learn them. If you write an algorithm in one of these langages, i.e. a series of instruction, the computer will be able to interpret it and then execute it.

      It is common to insist on the requirement that an algorithm should “terminate”, i.e. that the person/algorithm that executes it should be able to do all the instructions in a finite amount of time. For instance, the following algorithm causes trouble, because it never terminates!

      Title of algorithm: Silly algorithm

      1) Say “Hello!”.

      2) Say “Goodbye!” and go back to instruction 1).

      It is also important to ask that the algorithm is “correct”, i.e. that it does what it is expected to do. For instance, if someone asks you to design an algorithm that counts from 1 to 3, then the algorithm “Receipt of a strange cake” will not be correct, but the following one will.

      Title: Counting from 1 to 3

      1) Say “1”
      2) Say “2”
      3) Say “3”

Comments