# Introduction: Data Structure and Algorithm

Data structure:

• A computer program is a sequence of instructions to perform any specific task. For this, a computer program may need to store data, retrieve data and perform some manipulation on data.
• A data structure is a way of storing and organizing data in such a way that we can perform operations on these data an effective way.
• The most commonly used data structures in C are array, linked list, queues, stack, trees, etc.
• The criteria for choosing a particular type of data structure depends upon the type of problem and how efficient we could store and retrieve data using it.

Basic types of Data structure

As stated above anything that can store data can be termed as data structure, hence Integer, float, Boolean, Char etc. These are known as data structure. These are known as Primitive Data structure..

Few of them are complex data structure which are kind of derived from these and are used to store large and complex data. Those are Linked list, Array, Tree, Queues, Stack etc. These are called Abstract Data structure.

The Data structure can also be classified on the basic of following characteristics:

Algorithm:

An algorithm is a step by step instruction to solve a particular problem. It is defined as a sequence of statements which are used to perform some task. These statements can be converted into programming instructions which form a program.

Diag-1: Algorithm:

Specification of Algorithm:
Each algorithm must specify the following specifications

• Input: Every algorithm must take zero or more input values from the external.
• Output: Every algorithm must produce the result as output.
• Definiteness: Every instruction in the algorithm must be clear and unambigious(only one interpretation).
• Finiteness: For different cases, the algorithm must produce results within a finite amount of time and steps.
• Effectiveness: Every instruction must be basic enough to be carried out and must be feasible.

Example:
Let’s consider the problem of adding two numbers

Algorithm:

• Define a variable ‘result’ and initialize it with a value of 0.
• Take the two numbers ‘num1’ and ‘num2’ and initialize both with a value of say 5 and 10.
• Add the two numbers and store the sum in ‘result’
• Display the value of ‘result’ as output.

C program to compute the sum:

``````#include <stdio.h>

int main ()
{
int result = 0;
int num1 = 5;
int num2 = 10;
result = num1 + num2;
printf("\n The sum is %d\n", result);
return 0;
}``````

Categories: Data Structure and Algorithm