**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:

Characteristics | Description |

Linear | The data are placed sequentially in a memory in sequential fashion. Ex: Array |

Non-Linear | The data are not placed sequentially. Ex: Tree, graph |

Homogeneous | All the elements are of same type. Ex: Array |

Non-homogeneous | The data can be of different types Ex: Structure and Union |

Static | Static data structures are those whose sizes and structures associated memory locations are fixed, at compile time. Example: Array |

Dynamic | Dynamic structures are those which expands or shrinks depending upon the program need and its execution. Also, their associated memory locations changes. Example: Linked List created using pointers |

**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

## Leave a Reply