Professional Documents
Culture Documents
Welcome To All: Data Structures and Algorithm
Welcome To All: Data Structures and Algorithm
Welcome To All: Data Structures and Algorithm
Algorithm Specification
• Pseudocode Conventions
• Recursive Algorithms
Pseudocode Conventions
It contains some important functions.
i. Comments begin with // and continue until the end of line.
ii. Blocks are indicated with matching braces { and }.
Statements are delimited by ;
iii. An identifier begins with a letter. Variable may be global
(or) local compound data types can be formed with records.
iv. Assignment of values to variables are assign with =
<variable> := <expression>;
v. There are two boolean values true and false.
Logical operators and, or, not and operators <,<,=,=,>, and >
are provided
vi. Arrays are denoted as [ ]
vii. Looping statements for, while & repeat-until.
viii. Condition statements if & if-else
ix. Input and output are done using instructions read and write
Example:
• Towers of Hanoi
• Permutation Generator
Towers of Hanoi
• Towers of Hanoi puzzle, there was a diamond tower with 64
golden disk (A)
• Besides this tower there were two other diamond tower
(B & C)
• Brahman move the disks from A to tower B using tower C for
intermediate storage.
• The number of disks is n. To get the largest disk to the bottom
of tower B,
• we move the remaining n disks to tower C and then move the
largest to tower B.
• Now we are left with the task of moving the disks from tower
C to tower B. To do this, we have towers A and B available.
• Tower B has a disk on it can be ignored as the disk is larger
than the disks being moved from tower C and so any disk can
be placed on top of it.
Permutation Generator:
• Given a set of n > 1 elements.
• Problem: print all possible permutations of this set.
Eg. The set is { a, b, c }
Set of permutations is
{ (a,b,c),(a,c,b),(b,a,c),(b,c,a),(c,a,b),(c,b,a)
}
Sorting
Sorting arranges data in a sequence which makes searching
easier. Every record which is going to be sorted will contain one
key. Based on the key the record will be sorted.
Sorting Techniques:
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
4. Quick Sort
5. Merge Sort
6. Heap Sort
Thank you