What is pseudocode and how is it different from a programming language?

Answer:

Answer by student

Pseudocode is a way of writing an algorithm in a human-readable form that resembles a programming language but does not follow any specific syntax or rules. It is different from a programming language because it is not meant to be executed by a computer, but only to convey the logic and steps of an algorithm.

Detailed answer by teachoo

-lock-

To understand what pseudocode is and how it differs from a programming language, let’s look at some examples.

Suppose we want to write an algorithm to find the maximum of three numbers. Here is one possible way of writing it in pseudocode:

Input: A, B, C

Output: Max

If A > B and A > C then

  Max = A

Else if B > A and B > C then

  Max = B

Else

  Max = C

End if

Print Max

As you can see, the pseudocode is easy to read and understand , and it uses some keywords and symbols that are common in programming languages, such as if , else , and , = , > , etc . However, the pseudocode does not follow any specific syntax or rules, and it can be written in different ways depending on the preference of the writer. Pseudocode is not meant to be executed by a computer , but only to help the human reader understand an algorithm.

A programming language , on the other hand, is a formal language that follows a specific syntax and rules that can be understood and executed by a computer . A programming language has a predefined set of keywords, symbols, operators, data types, structures, etc. that must be used correctly and consistently. A programming language also has a compiler or an interpreter that translates the code into machine instructions that can be executed by the computer.

For example, here is one possible way of writing the same algorithm in Python, which is a popular programming language:

# Input: A, B, C

# Output: Max

A = int(input("Enter A: "))

B = int(input("Enter B: "))

C = int(input("Enter C: "))

if A > B and A > C:

  Max = A

elif B > A and B > C:

  Max = B

else:

  Max = C

print("Max =", Max)

As you can see, the Python code follows a specific syntax and rules that must be followed exactly. For example, we have to use indentation to indicate blocks of code, we have to use parentheses to enclose the arguments of functions, we have to use colons to end conditional statements, we have to use double quotes to enclose strings, etc. The Python code can be executed by a Python interpreter that will run the code and produce the output.

So, pseudocode and programming languages are different ways of writing algorithms. Pseudocode is a human-readable form that resembles a programming language but does not follow any specific syntax or rules. Programming languages are formal languages that follow specific syntax and rules that can be understood and executed by computers.

-endlock-

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.