The basic concept of data structure using in c
By: Pehu Verma
Tags: Basic Knowledge, Arrays, Data Structures

l Array

l Linked-list

l Stacks & Queues

l -Tree & graph

The Data structure is are divided into two methods :1. linear & 2. non-linear

Basically, it is a collection of values and no conclusion can be drawn from it.After processing it becomes information that can help in making decisions.

The logical or mathematical model is used to organize the data in main memory is called data structure.

A linear data structure is one in which the elements are store in a sequence. It means each each element in a structure has a unique predecessor. An array is the simplest linear data structure and the others are linked-list, stacks etc.

Array : it is a finite collection of elements, array is a contiguous memory location irrespective of the array size.The elements of an array can be referred to by using one or more indices or subscripts. An index or subscript is a positive integer value which indicates the position of a particular element in the array.

Different notation in single-dimensional array……

1.

ARR(1),ARR(2)

Basic & Fortan

2.

ARR[ 1]..,ARR[n]

Pascal

3.

ARR[0] — -ARR[n-1]

C, C++, Java

In two-dimensional arrays, the elements can be viewed as arranged in the form of rows and columns (matrix form). To access an element of two-dimension array, two subscripts are used — first one represents the row number and second one

represents the column number.

Different notation in two-dimensional array……

1.

ARR(i,j)with 0<I=m&0<j<=n

Basic & Fortan

2.

ARR[ i,j]with 0<=i<m&0<=j<n

Pascal

3.

ARR[i][j]with0<=i<m&0<=j<n

C, C++, Java

A linked list is a linear collection of similar data elements, called nodes, with each node containing some data and pointer(s) pointing to other node(s) in the list.If each node of a linked list contains only one pointer and it points to the next node, then it is called linear linked list or singly-linked list. In such type of lists, the pointer field in the last node contains NULL.

Stack & queues

A stack is a linear list of data elements in which addition of a new element or

deletion of an element occurs only at one end. This end is called Top of the stack.

The operation of adding new element in the stack and deleting an element from the

stack is called push and pop respectively.

Algorithm…..push stack

2.1 Push Operation on Stack

push(s, element) //s is a pointer to stack

1. If s->Top = MAX-1 //checking for stack overflow

Print “Overflow: Stack is full!” and go to step 5

End If

2. Set s->Top = s->Top + 1 //incrementing Top by 1

3. Set s->item[s->Top] = element //inserting element in the stack

4. Print “Value is pushed onto the stack…”

5. End

Pop Operation on Stack

pop(s)

1. If s->Top = -1 //checking for stack underflow

Print “Underflow: Stack is empty!”

Return 0 and go to step 5

End If

2. Set popped = s->item[s->Top] //taking off the top element from

the stack

3. Set s->Top = s->Top — 1 //decrementing Top by 1

4. Return popped

5. End

A queue is a linear data structure in which addition or insertion of a new element

occurs at one end, called Rear, and deletion of an element occurs at other end,

called Front

A non-linear data structure is one in which its elements do not form a sequence. It

means, unlike linear data structure, each element is not constrained to have a unique predecessor and a unique successor.

Trees

Usually, we observe a hierarchical relationship between various data elements.

This hierarchical relationship between data elements can easily be represented

using a non-linear data structure called trees.

graph:

Formally, a graph G(V,E) consists of a pair of two non-empty sets V and E, where

V is a set vertices or nodes and E is a set of edges. The graph is used to represent the

non-hierarchical relationship among pairs of data elements.