Professional Documents
Culture Documents
Lecture 2 DAA
Lecture 2 DAA
Pseudocode Conventions
Psuedo code Purpose
• Flowcharts graphically represent the
algorithm.
• But it can only be used for simple
algorithms or problems.
• So psuedo code is used to represent
algorithm
Psuedocode Conventions
Conventions - Comments
• Begin with //
• Continue until the end of line
Conventions - Blocks
• Indicated with matching braces:{ and }.
• Statement delimiter ;
• Examples
– A compound statement
– The body of a procedure
Conventions - Identifier
• Begins with a letter.
• Implicit data type assignment
• Scope depends on context
Conventions- Data Types
• Simple
– Integer, float, char, Boolean, and so on.
• Compound
– Formed with records
node = record
{ Datatype_1 data_1;
---------------
---------------
Datatype_n data_n;
Node *link; }
Conventions - Assignment
• Assignment of values to variables
• Assignment statement format
<variable> := <expression>
Conventions - Boolean
• Two boolean values
– True , False.
• Produced using operators
– Logical
• and, or , not
– Relational operators
• <, <= , = , # , >= , >
Conventions - Array
• Array indices start at zero.
• Elements represented using [ ]
• Example
– (i,j) th element in A denoted as A[i,j].
Conventions - Loops
• Looping statements
– For
– While
– Repeat-until
Conventions – Loop Contd..
• While Loop
while <condition> do while (variable <=n) do
{ {
<statement 1> <statement 1>
--------------- ………….
<statement n> …………
} <statement n>
variable :=variable + incr;
}
Conventions - Loop Contd..
• For Loop
Repeat
<statement 1>
--------- --
<statement n>
Until <condition>
Conventions - Condition
Conditional statement in two forms:
• Form1
If <condition> then <statement>
• Form2