World's most popular travel blog for travel bloggers.

Ques : Describe Pseudo - Code Conventions

, , No Comments

 The following conventions must be used for pseudo-code.

  1. Give a valid name for the pseudo-code procedure. (See sample code for insertion sort at the end).
  2. Use the line numbers for each line of code.
  3. Use proper Indentation for every statement in a block structure.
  4. For a flow control statements use if-else. Always end an if statement with an end-if. Both if, else and end-if should be aligned vertically in same line.

Ex : If (conditional expression)
statements (see the indentation)
else statements

end - if

5. Use : = or " <--- " operator for assignments.

Ex: i = j or i <--- J

n = 2 to length [A] or n<--- 2 to length [A]

  1. Array elements can be represented by specifying the array name followed by the index in square brackets. For example, A[i] indicates the ith element of the array A.
  1. For looping or iteration use for or while statements. Always end a for loop with end-for and a while with end-while.
  2. The conditional expression of for or while can be written as shown in rule (4). You can separate two or more conditions with “and”
  3. If required, we can also put comments in between the symbol

    /* and */.

A simple pseudo-code for insertion sort using the above conventions:

INSERTION - SORT (A)
1 . for j <--- 2 to length [A]
2. key <---A [j]
3. i <--- j - 1 _ /* insert A[j] into sorted sequence A [1...j - 1] */
4. while i > 0 and A[i] > key
5. A [i+1] <--- A[i]
6. i <--- i - 1
7. end - while
8. A[i+1] <--- key
9. end - for

0 comments:

Post a Comment

Let us know your responses and feedback