Pseudo code
ag1805x
Pseudo code
• An informal high-level description of the operating principle of
a computer program or other algorithm.
• It uses the structural conventions of a programming language,
but is intended for human reading rather than machine
reading.
• Pseudo code typically omits details that are essential for
machine understanding of the algorithm, such as variable
declarations, system-specific code and some subroutines.
• The programming language is augmented with natural
language description details, where convenient, or with
compact mathematical notation.
Purpose
• The purpose of using pseudo code is that it is easier for people
to understand than conventional programming language code,
and that it is an efficient and environment independent
description of the key principles of an algorithm.
Applications
• Textbooks and scientific publications related to computer
science and numerical computation often use pseudo code in
description of algorithms, so that all programmers can
understand them, even if they do not all know the same
programming languages. In textbooks, there is usually an
accompanying introduction explaining the particular
conventions in use. The level of detail of the pseudo-code may
in some cases approach that of formalized general purpose
languages.
Applications [contd.]
• A programmer who needs to implement a specific algorithm,
especially an unfamiliar one, will often start with a pseudo
code description, and then “translate” that description into
the target programming language and modify it to interact
correctly with the rest of the program. Programmers may also
start a project by sketching out the code in pseudo code on
paper before writing it in its actual language, as a top-down
structuring approach, with a process of steps to be followed as
a refinement.
Syntax
• Pseudo code generally does not actually obey the syntax rules
of any particular language.
• There is no systematic standard form.
• Any particular writer will generally borrow style and syntax for
example, control structures from some conventional
programming language.
• Popular syntax sources include Fortran, Pascal, BASIC, C, C++,
Java, Lisp, and ALGOL.
• Variable declarations are typically omitted.
• Function calls and blocks of code, such as code contained
within a loop, are often replaced by a one-line natural
language sentence.
Pseudo code for sorting
• Sorting: To arrange set of elements into proper order
(ascending/descending).
• To sort an array there are 3 basic algorithms:
• Bubble Sort
• Selection Sort
• Insertion Sort
• Bubble Sort: Suppose A is an array of N values. We want to
sort A in ascending order. Bubble Sort is a simple minded
algorithm based on the idea that we look at the list, and
wherever we find two consecutive elements out of order, we
swap them. We do this as follows: We repeatedly traverse the
unsorted part of the array, comparing consecutive elements,
and we interchange them when they are out of order.
• Pseudocode:
• Selection Sort: Suppose A is an array of N values. We want to
sort A in ascending order. That is, A[1] should be the smallest
and A[N] should be the largest. The idea of Selection Sort is
that we repeatedly find the smallest element in the unsorted
part of the array and swap it with the first element in the
unsorted part of the array.
• Pseudo code:
• Insertion Sort: Suppose A is an array of N values. We want to
sort A in ascending order. Insertion Sort is an algorithm to do
this as follows: We traverse the array and insert each element
into the sorted part of the list where it belongs. This usually
involves pushing down the larger elements in the sorted part.
• Pseudo code:
Pseudo code for finding maximum
• Suppose A is an array of N values. We want to find the
maximum. We set the first value of the array as the maximum
and then traverse through the array and check if there are
values more than the maximum value. If present we change
the value of maximum and continue through the array.
• Pseudo code:
Pseudo code for finding minimum
• Suppose A is an array of N values. We want to find the
minimum. We set the first value of the array as the minimum
and then traverse through the array and check if there are
values less than the minimum value. If present we change the
value of minimum and continue through the array.
• Pseudo code:
Pseudo code

Pseudo code

  • 1.
  • 2.
    Pseudo code • Aninformal high-level description of the operating principle of a computer program or other algorithm. • It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. • Pseudo code typically omits details that are essential for machine understanding of the algorithm, such as variable declarations, system-specific code and some subroutines. • The programming language is augmented with natural language description details, where convenient, or with compact mathematical notation.
  • 3.
    Purpose • The purposeof using pseudo code is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment independent description of the key principles of an algorithm.
  • 4.
    Applications • Textbooks andscientific publications related to computer science and numerical computation often use pseudo code in description of algorithms, so that all programmers can understand them, even if they do not all know the same programming languages. In textbooks, there is usually an accompanying introduction explaining the particular conventions in use. The level of detail of the pseudo-code may in some cases approach that of formalized general purpose languages.
  • 5.
    Applications [contd.] • Aprogrammer who needs to implement a specific algorithm, especially an unfamiliar one, will often start with a pseudo code description, and then “translate” that description into the target programming language and modify it to interact correctly with the rest of the program. Programmers may also start a project by sketching out the code in pseudo code on paper before writing it in its actual language, as a top-down structuring approach, with a process of steps to be followed as a refinement.
  • 6.
    Syntax • Pseudo codegenerally does not actually obey the syntax rules of any particular language. • There is no systematic standard form. • Any particular writer will generally borrow style and syntax for example, control structures from some conventional programming language. • Popular syntax sources include Fortran, Pascal, BASIC, C, C++, Java, Lisp, and ALGOL. • Variable declarations are typically omitted. • Function calls and blocks of code, such as code contained within a loop, are often replaced by a one-line natural language sentence.
  • 7.
    Pseudo code forsorting • Sorting: To arrange set of elements into proper order (ascending/descending). • To sort an array there are 3 basic algorithms: • Bubble Sort • Selection Sort • Insertion Sort
  • 8.
    • Bubble Sort:Suppose A is an array of N values. We want to sort A in ascending order. Bubble Sort is a simple minded algorithm based on the idea that we look at the list, and wherever we find two consecutive elements out of order, we swap them. We do this as follows: We repeatedly traverse the unsorted part of the array, comparing consecutive elements, and we interchange them when they are out of order. • Pseudocode:
  • 10.
    • Selection Sort:Suppose A is an array of N values. We want to sort A in ascending order. That is, A[1] should be the smallest and A[N] should be the largest. The idea of Selection Sort is that we repeatedly find the smallest element in the unsorted part of the array and swap it with the first element in the unsorted part of the array. • Pseudo code:
  • 12.
    • Insertion Sort:Suppose A is an array of N values. We want to sort A in ascending order. Insertion Sort is an algorithm to do this as follows: We traverse the array and insert each element into the sorted part of the list where it belongs. This usually involves pushing down the larger elements in the sorted part. • Pseudo code:
  • 14.
    Pseudo code forfinding maximum • Suppose A is an array of N values. We want to find the maximum. We set the first value of the array as the maximum and then traverse through the array and check if there are values more than the maximum value. If present we change the value of maximum and continue through the array. • Pseudo code:
  • 16.
    Pseudo code forfinding minimum • Suppose A is an array of N values. We want to find the minimum. We set the first value of the array as the minimum and then traverse through the array and check if there are values less than the minimum value. If present we change the value of minimum and continue through the array. • Pseudo code: