Intro to Algorithms

What Is an Algorithm?

An algorithm is a detailed step-by-step instruction set or formula for solving a problem or completing a task. In computing, programmers write algorithms that instruct the computer how to perform a task.

When you think of an algorithm in the most general way (not just in regards to computing), algorithms are everywhere. A recipe for cooking a cake is an algorithm, the method you use to solve addition, subtraction or a long division problems is an algorithm, and the process of stacking a dishwasher is an algorithm. Even your morning routine could be considered an algorithm!

Algorithms are fascinating and, although some are quite complex, the concept itself is actually quite simple.

The Benefits of Algorithmic Thinking

Algorithmic thinking, or the ability to define clear steps to solve a problem, is crucial in subjects like Math and Science. People use algorithms without realizing it all the time, particularly in Maths but also in everyday life. Algorithmic thinking allows people to break down problems and conceptualize solutions in terms of discrete steps in a procedure.

An algorithm is a way of designing something so it can converting into code that will adhere to the six basic computer operations. So every line in an algorithm must be match one of Six Basic Computer Operations.

The Six Basic Computer Operations are:

A computer can receive information

A computer can out put information

A computer can perform arithmetic

A computer can assign a value to a variable or memory location

A computer can compare two variables and select one of two alternative actions

A computer can repeat a group of actions

Algorithm Rules

Algorithm

A set of step-by-step instructions to accomplish a task.

An algorithm must have start instruction

Each instruction must be precise.

Each instruction must be unambiguous.

Each instruction must be executed in finite time.

An algorithm must have stop instruction.

Examples

Algorithm Example 1

Write an algorithm to add 2 numbers

 Step 1: Start

 Step 2: Let a=10,b=20

 Step 3: c=a+b;

 Step 4: print c

 Step 5: Stop

Algorithm Example 2

Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Pseudocode and Flowcharts

Pseudo code is an artificial and informal language that helps programmers develop algorithms. Pseudo code is very similar to everyday English.

FLOWCHARTS(Dictionary) A schematic representation of a sequence of operations, as in a manufacturing process or computer program.

(Technical) A graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users.

Program flow charts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.

Flowcharts shows logic of an algorithm. They also emphasizes individual steps and their interconnections e.g. control flow from one action to the next