This blog is under construction

Saturday, 16 February 2013

Algorithm, Program, Data Structure and Pseudocode

What is an algorithm?

An algorithm is a set of instructions that can be used for solving a problem.  An efficient algorithm is the one that takes less running time and memory.

Algorithm to swap two numbers:
Step 1: Start
Step 2: Input two numbers(val1 and val2)
Step 3: Assign "val1" to a temporary variable (temp)
Step 4: Assign "val2" to  "val1"
Step 5: Assign "temp" to "val2"
Step 6: Display values in val1 & val2

What is a program?

Program is nothing but implementation of an algorthim using any programming language(Eg: C, C++, Java etc)

C program to swap two numbers:
int main() {
int val1, val2, temp;
printf("Enter two numbers:");
scanf("%d%d", &val1, &val2);
temp = val1;
val1= val2;
val2 = temp;
printf("After swapped: %d  %d\n", val1, va2);
return 0;

What is a pseudocode?
It is a combination of both natural and programming language which can be used to explain the generic implementation of an algorithm.

Pseudocode to swap two numbers:
swap(a, b)
t  <- a
a <- b
b <- t
return a, b

What is a data structure?

Organizing, storing and retrieving needed data to solve a problem.
Eg: Arrays, Lists, Stack etc.
char str[5][10] = {"English", "Math", "Physics", "Computer", "Biology"};

See Also:
Data Structure Programs In C

1 comment:

  1. perfect explanation about java programming .its very useful.thanks for your valuable training in chennai | best java training in velachery