MCS-201 · Unit 1

Programming Fundamentals

Section 2 of 9

Block 1 · Unit 1Programming Fundamentals15 min · Section 2 of 9

1.2Algorithms: Definition and Properties

Covers IGNOU MCS-201 §1.3, 1.3.1, 1.3.2, 1.3.3

An algorithm is the plan behind every program. If the algorithm is wrong, no amount of careful coding will fix the program. This section defines what an algorithm is, lists the five properties it must have, and shows how tracing an algorithm by hand reveals errors, including one in the study material itself.

What an algorithm is

An algorithm is a method. A program is that method written in a particular programming language. The same algorithm can be written as numbered English steps, as pseudocode, as a flowchart, or as C or Python code.

Reading assignment: the arrow ←

Algorithms use the arrow ← for assignment: storing a value in a variable.

  • x ← 5 means “store 5 in x”.
  • i ← i + 1 means “calculate i + 1 using the current value of i, then store the result back in i”.

The right-hand side is always calculated first. The arrow is used instead of = because in mathematics i = i + 1 is a false statement, while in programming it is a normal instruction. In C, the same instruction is written i = i + 1;.

The five properties of an algorithm

PropertyMeaningExample of a violation
InputZero or more values are supplied(rarely violated)
OutputAt least one result is producedSteps that calculate a value but never show it
DefinitenessEach step is clear and has only one meaning“Multiply the price by a suitable tax rate”
FinitenessIt always stops after a finite number of steps“k ← 10; while k > 0, k ← k + 1”
EffectivenessEach step is basic enough to be done with pen and paper“Find the largest prime number” (none exists)

The study material also lists “features” of an algorithm: proper understanding of the problem, use of functions for modularity, meaningful variable names and documentation. These are good programming practices. If an exam asks for features, give this list; if it asks for criteria or characteristics, give the five properties above.

Tracing an algorithm

Tracing means executing an algorithm by hand, step by step, writing down the value of every variable after each step. It is the most reliable way to find errors in an algorithm before it becomes a program.

The factorial of a whole number n is

n!=1×2×3×⋯×nn! = 1 \times 2 \times 3 \times \cdots \times n

so 4!=244! = 24. The study material’s factorial algorithm (Example 1.3) repeats its loop “until i = n”. Tracing it with n = 4 shows the problem.

Key takeaways

  • An algorithm is a method; a program is that method in a specific language.
  • x ← value means store the value in x; the right-hand side is calculated first.
  • Every algorithm must satisfy Input, Output, Definiteness, Finiteness and Effectiveness.
  • Tracing with a small example catches off-by-one errors and wrong loop conditions.

Practice questions

Answer on paper first, then check. The explanation matters more than the letter you chose.

Question 1 · multiple choice

Which of these is NOT one of the five properties of an algorithm?

Show answer

Answer: C. Modularity

The five properties are Input, Output, Definiteness, Finiteness and Effectiveness. Modularity is a good programming practice listed among the “features”, not one of the formal properties.

Question 2 · multiple choice

A step says: “Multiply the price by a suitable tax rate.” Which property does it violate?

Show answer

Answer: A. Definiteness

“Suitable” can be understood in more than one way, so the step is not definite. It is tempting to say Input, but the problem is the vague wording; stating the rate (or reading it as an input) makes the step definite.

Question 3 · multiple choice

The steps are: k ← 10; while k > 0, k ← k + 1. Which property is violated?

Show answer

Answer: D. Finiteness

k only increases, so k > 0 stays true and the loop never stops. Each step is perfectly clear, so Definiteness is not the problem.

Question 4 · multiple choice

An algorithm sets i ← 1, fact ← 1 and repeats {fact ← fact × i; i ← i + 1} until i = n, testing before each round. What does it print for n = 4?

Show answer

Answer: C. 6

The loop stops as soon as i becomes 4, before multiplying by 4, so fact = 1 × 1 × 2 × 3 = 6. The expected 24 needs the condition “while i ≤ n”.

Question 5 · multiple choice

If x currently holds 7, what does x hold after the step x ← x × 2 − 4?

Show answer

Answer: B. 10

The right-hand side is calculated first with the current value: 7 × 2 − 4 = 10, and the result replaces the old value. The arrow does not mean “x equals”, so the old value 7 is not kept.

Question 6 · multiple choice

Using the corrected prime algorithm, what is printed for num = 1?

Show answer

Answer: B. not prime

Step 3 checks num < 2 first, so 1 is reported as “not prime”, matching the definition that primes are greater than 1. Without that check, the loop would not run and flag = 1 would wrongly report “prime”.

Question 7 · short answer

Trace the corrected factorial algorithm (i ← 1, fact ← 1; while i ≤ n, fact ← fact × i and i ← i + 1) for n = 3. Show the values after each round and the output.

Show worked answer

Start: i = 1, fact = 1. Round 1: 1 ≤ 3 is true, fact = 1 × 1 = 1, i = 2. Round 2: 2 ≤ 3 is true, fact = 1 × 2 = 2, i = 3. Round 3: 3 ≤ 3 is true, fact = 2 × 3 = 6, i = 4. Test: 4 ≤ 3 is false, so the loop stops. Output: 6, which equals 3! = 1 × 2 × 3.

↑ ↓ move↵ openTab switch type