SlideShare a Scribd company logo
Data Structure
(KCS-301)
Arvind Kumar
Assistant Professor
CSE/IT Dept.
Data Structure
(KCS-301)
Unit-1
Data Structure
Data structure is simply an arrangement of data or organization of data in
different ways.
Classification of data structures:
Arrays
Linked list
Stacks
Queues
Trees
Graphs
Definition of Algorithm
An algorithm is a set of instructions, sometimes called a procedure or a
function, that is used to perform a certain task.
An algorithm is a description of a procedure which terminates with a
result. Simple algorithms can be implemented within a function for
instance, the factorial of a number x is x multipled by x-1 multipled by
x-2 and so on until it is multiplied by 1.
Arrays
Arrays An array is a series of elements of the same type placed in
contiguous memory locations that can be individually referenced by
adding an index to a unique identifier.
The elements of global and static arrays, on the other hand, are
automatically initialized with their default values, which for all
fundamental types this means they are filled with zeros.
In both cases, local and global, when we declare an array, we have
the possibility to assign initial values to each one of its elements by
enclosing the values in braces { }.
Arrays
Inserting an element in array
It means adding a new element in an existing array
Algorithm
Insertion (A , N, n= no of elements, new= new element,
Index)
Set I= n
Repeat steps 3 while I>index
Set A[I]=A[I+1]
Set A[Index]=new
Exit
Arrays
Algorithm for traversing the array
Set I=Lowerbound
Repeat step 3 and 4 while I<=Upeer bound
Print A[I]
Set I=I+1
Exit
Inserting an element in array
It means adding a new element in an existing array
Algorithm
Insertion (A , N, n= no of elements, new= new element, Index)
Set I= n
Repeat steps 3 while I>index
Set A[I]=A[I+1]
Set A[Index]=new
Exit
Arrays
Searching in Array
It works on unsorted list Called sequential search
The best case is when element is found at first position in array
The worst case is when element is found at last position or not found
Algorithm( I, found,num= val to be found,n=no of elements)
Set I=0, found=0
Enter the number to be searched
Repeat steps 4 while I<n
If (A[I]==num)
Set found=1
Print position I
(End of if)
(End of loop)
If found=0, then value is not searched
Exit
Address calculation of an element
Address calculation of an element:
Row-Major : addr (i,j) = B + W * ( Nc * (i - Lr) + (j-Lc) )
Col-Major : addr (i,j) = B + W * ( (i - Lr) + Nr * (j-Lc) )
i,j = subscript number. B = Base address W = width (size) of
each element Nc = Number of Columns Nr = Number of Rows
Lc = Lower-bound of Column Lr = Lower-bound of Row
In above example, for element (6), i.e., a(1,2) in row-major or
a(2,1) in col-major, B = 200 (say) W = 2 Lr=Lc=0 Nc=Nr=3
addr (1,2) = 210; addr (2,1) = 214
Linked list
Linked list is the collection of nodes connected together with the help of addresses
Advantages of Linked Lists
They are a dynamic in nature which allocates the memory when required.
Insertion and deletion operations can be easily implemented.
Stacks and queues can be easily executed.
Linked List reduces the access time.
Disadvantages of Linked Lists
The memory is wasted as pointers require extra memory for storage.
No element can be accessed randomly; it has to access each node sequentially.
Reverse Traversing is difficult in linked list.
Applications of Linked Lists
Linked lists are used to implement stacks, queues, graphs, etc.
Linked lists let you insert elements at the beginning and end of the list.
In Linked Lists we don’t need to know the size in advance.
Types of Linked List
Types of Linked List:
• Singly Linked list or 1- way linked list
• Doubly or 2-way linked list
• Circular Linked list
Singly Linked List : Singly linked lists contain nodes which have a
data part as well as an address part i.e. next, which points to the next
node in sequence of nodes. The operations we can perform on singly
linked lists are insertion, deletion and traversal.
Types of Linked List
Doubly Linked List : In a doubly linked list, each node contains two
links the first link points to the previous node and the next link points
to the next node in the sequence.
Circular Linked List : In the circular linked list the last node of the
list contains the address of the first node and forms a circular chain.
Implement a Singly Linked list in Stack
#include<stdio.h>
#include<conio.h>
struct stu *new(int)
void addnode( );
void traverse( );
struct stu
{
Int info;
Struct stu * next;
}
*head=NULL, *temp,*p;
Void main( )
{
int a, ch;
while( ch!=0)
{
Scanf(“%d”,&a);
P=new(a);
addnode(p);
printf(“press 1 for vontinue and 0 for end”);
scanf(“%d”, &ch);
}
Traverse (head);
getch( );
}
Struct stu *new ( int a)
{
p=((struct stu *) malloc (sizeof(struct stu)));
p – info=a;
p – next=NULL;
return p;
}
Void addnode( )
{
Temp=head;
If (head==NULL)
{
Head=p;
}
Else
{
P – next=temp;
Head=p;
}
Void traverse
{
Temp=head;
While(temp!=NULL)
{
Printf(“%d”, temp- info);
Temp=temp – next;
}
}
Deletion
Deleting the first node of Singly Linked List:
main( )
{
Int a,ch;
.
. Same as above programs
.
traverse();
delfirst()
Getch();
}
Void delfirst ( )
{
Temp=head;
Head=temp->next;
Free (temp);
}
Deleting the last node of Singly Linked List:
main( )
{
Int a,ch;
.
. Same as above programs
.
traverse();
dellast()
getch();
}
Void dellast( )
{
Temp=head;
While (temp->next!=NULL)
{
r= temp;
temp=temp->next;
}
r-> next=NULL;
free(temp);
}
Deleting the particular node of Singly Linked List:
Void delpart( )
{
Temp=head;
While (temp!=NULL)
{
r=temp;
temp=temp->next;
if(temp->info==item)
{
r->next=temp->next;
free(temp);
}
}
}
Implement Doubly Linked list using Stack
#include<stdio.h>
#include<conio.h>
struct stu *new(int)
void addnode( );
void traverse( );
struct stu
{
Int info;
Struct stu * next;
Struct stu *pre;
}
*head=NULL, *temp,*p;
Void main( )
{
int a, ch;
while( ch!=0)
{
Scanf(“%d”,&a);
P=new(a);
addnode(p);
printf(“press 1 for Continue and 0 for end”);
scanf(“%d”, &ch);
}
Traverse ( );
getch( );
}
Struct stu *new ( int a)
{
p=((struct stu *) malloc (sizeof(struct stu)));
p – >info=a;
p – >next=NULL;
p->pre=NULL;
return p;
}
Void addnode( struct stu *p)
{
Temp=head;
If (head==NULL)
{
Head=p;
}
Else
{
P – next=temp;
Temp->pre=p;
Head=p;
}
Void traverse
{
Temp=head;
While(temp!=NULL)
{
Printf(“%d”, temp- info);
Temp=temp – next;
}
}
Delete the first node in Doubly Linked list
#include<stdio.h>
#include<conio.h>
struct stu *new(int)
void addnode( );
void traverse( );
void delfirst( );
struct stu
{
Int info;
Struct stu * next;
Struct stu *pre;
}
*head=NULL, *temp,*p;
Void main( )
{
int a, ch;
while( ch!=0)
{
Scanf(“%d”,&a);
P=new(a);
addnode(p);
printf(“press 1 for Continue and 0 for
end”);
scanf(“%d”, &ch);
}
Traverse ( );
delfirst ( );
getch( );
}
Struct stu *new ( int a)
{
p=((struct stu *) malloc (sizeof(struct
stu)));
p – >info=a;
p – >next=NULL;
p->pre=NULL;
return p;
}
Void addnode (struct stu*p)
{
Temp=head;
If(head==NULL)
{
Head=p;
{
Else
{
while(temp->next!=NULL)
{
Temp=temp->next;
}
Temp->next=p;
p->pre=temp;
}
}
Void traverse( )
{
Temp=head;
While(temp!=NULL)
Printf(“%d”, temp-> info);
Temp=temp – >next;
}
}
Void delfirst( )
{
Temp=head;
head=temp->next;
head->pre=NULL;
free(temp);
}
Program to add the before a given node in
Doubly Linked list:
#include<stdio.h>
#include<conio.h>
struct stu *new(int)
void addnode( );
void traverse( );
void addbefore( );
struct stu
{
Int info;
Struct stu * next;
Struct stu *pre;
}
*head=NULL, *temp,*p;
Void main( )
{
int a, ch,item;
while( ch!=0)
{
Scanf(“%d”,&a);
P=new(a);
addnode(p);
printf(“press 1 for Continue and 0 for end”);
scanf(“%d”, &ch);
}
Traverse ( );
Printf(“enter the new node value”);
Scanf(“%d”,&a);
P=new(a);
Printf(“Enter the node value before which
the value to be added”);
Scanf( “%d”, &item);
Addbefore( item);
getch( );
}
Struct stu *new ( int a)
{
p=((struct stu *) malloc (sizeof(struct stu)));
p – >info=a;
p – >next=NULL;
p->pre=NULL:
return p;
}
Void addnode (struct stu*p)
{
Temp=head;
If(head==NULL)
{
Head=p;
{
Else
{
while(temp->next!=NULL)
{
Temp=temp->next;
}
Temp->next=p;
p->pre=temp;
}
}
Void traverse( )
{
Temp=head;
While(temp!=NULL)
Printf(“%d”, temp-> info);
Temp=temp – >next;
}
}
Void addbefore( int item)
{
Temp=head;
While(temp!=NULL)
{
If(temp->info==item)
{
p->next=temp;
temp->pre->next=p;
p->pre=temp->pre;
}
Temp=temp->next;}}
Sparse matrix
Sparse matrix is a matrix with majority of its elements equal to
zeros.
Linked list representation of Sparse Matrix
The above given matrix is represented as:
Program to sparse matrix
void main ()
{
static int array[10][10];
int i, j, m, n;
int counter = 0;
printf("Enter the order of the matix
n");
scanf("%d %d", &m, &n);
printf("Enter the co-efficients of
the matix n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d", &array[i][j]);
if (array[i][j] == 0)
{
++counter;
}
}
}
if (counter > ((m * n) / 2))
{
printf("The given matrix is
sparse matrix n");
}
else
printf("The given matrix is not a
sparse matrix n");
printf("There are %d number of
zeros", counter);
}

More Related Content

What's hot

Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
Linked lists
Linked listsLinked lists
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
sumitbardhan
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
swajahatr
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
Dabbal Singh Mahara
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
J.T.A.JONES
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
Dabbal Singh Mahara
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
Dr.Umadevi V
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
Dr.Umadevi V
 
Linked list
Linked listLinked list
Linked list
Harry Potter
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
Aakash deep Singhal
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
kalyanineve
 
358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15
sumitbardhan
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
Dr.Umadevi V
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
arnold 7490
 

What's hot (19)

Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Linked lists
Linked listsLinked lists
Linked lists
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
Linked list
Linked listLinked list
Linked list
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
 
358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 

Similar to Data structure

data structure
data structuredata structure
data structure
Arvind Kumar
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
AravindAnand21
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
Nivegeetha
 
Data structure
 Data structure Data structure
Data structure
Shahariar limon
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
JITTAYASHWANTHREDDY
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
KasthuriKAssistantPr
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
MeghaKulkarni27
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
pasqualealvarez467
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
Hanif Durad
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
chin463670
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
chin463670
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
ssuser0be977
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 

Similar to Data structure (20)

data structure
data structuredata structure
data structure
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Data structure
 Data structure Data structure
Data structure
 
Linked list
Linked list Linked list
Linked list
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 

More from Arvind Kumar

3 d transformation reflection
3 d transformation   reflection3 d transformation   reflection
3 d transformation reflection
Arvind Kumar
 
3 d transformation Rotation
3 d transformation   Rotation3 d transformation   Rotation
3 d transformation Rotation
Arvind Kumar
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curve
Arvind Kumar
 
3d Projection
3d Projection3d Projection
3d Projection
Arvind Kumar
 
3 D transformation translation, scaling
3 D transformation   translation, scaling3 D transformation   translation, scaling
3 D transformation translation, scaling
Arvind Kumar
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clipping
Arvind Kumar
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
Arvind Kumar
 
Weiler atherton
Weiler athertonWeiler atherton
Weiler atherton
Arvind Kumar
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
Arvind Kumar
 

More from Arvind Kumar (9)

3 d transformation reflection
3 d transformation   reflection3 d transformation   reflection
3 d transformation reflection
 
3 d transformation Rotation
3 d transformation   Rotation3 d transformation   Rotation
3 d transformation Rotation
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curve
 
3d Projection
3d Projection3d Projection
3d Projection
 
3 D transformation translation, scaling
3 D transformation   translation, scaling3 D transformation   translation, scaling
3 D transformation translation, scaling
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clipping
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
 
Weiler atherton
Weiler athertonWeiler atherton
Weiler atherton
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 

Recently uploaded

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 

Recently uploaded (20)

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 

Data structure

  • 3. Data Structure Data structure is simply an arrangement of data or organization of data in different ways. Classification of data structures: Arrays Linked list Stacks Queues Trees Graphs
  • 4. Definition of Algorithm An algorithm is a set of instructions, sometimes called a procedure or a function, that is used to perform a certain task. An algorithm is a description of a procedure which terminates with a result. Simple algorithms can be implemented within a function for instance, the factorial of a number x is x multipled by x-1 multipled by x-2 and so on until it is multiplied by 1.
  • 5. Arrays Arrays An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. The elements of global and static arrays, on the other hand, are automatically initialized with their default values, which for all fundamental types this means they are filled with zeros. In both cases, local and global, when we declare an array, we have the possibility to assign initial values to each one of its elements by enclosing the values in braces { }.
  • 6. Arrays Inserting an element in array It means adding a new element in an existing array Algorithm Insertion (A , N, n= no of elements, new= new element, Index) Set I= n Repeat steps 3 while I>index Set A[I]=A[I+1] Set A[Index]=new Exit
  • 7. Arrays Algorithm for traversing the array Set I=Lowerbound Repeat step 3 and 4 while I<=Upeer bound Print A[I] Set I=I+1 Exit Inserting an element in array It means adding a new element in an existing array Algorithm Insertion (A , N, n= no of elements, new= new element, Index) Set I= n Repeat steps 3 while I>index Set A[I]=A[I+1] Set A[Index]=new Exit
  • 8. Arrays Searching in Array It works on unsorted list Called sequential search The best case is when element is found at first position in array The worst case is when element is found at last position or not found Algorithm( I, found,num= val to be found,n=no of elements) Set I=0, found=0 Enter the number to be searched Repeat steps 4 while I<n If (A[I]==num) Set found=1 Print position I (End of if) (End of loop) If found=0, then value is not searched Exit
  • 9. Address calculation of an element Address calculation of an element: Row-Major : addr (i,j) = B + W * ( Nc * (i - Lr) + (j-Lc) ) Col-Major : addr (i,j) = B + W * ( (i - Lr) + Nr * (j-Lc) ) i,j = subscript number. B = Base address W = width (size) of each element Nc = Number of Columns Nr = Number of Rows Lc = Lower-bound of Column Lr = Lower-bound of Row In above example, for element (6), i.e., a(1,2) in row-major or a(2,1) in col-major, B = 200 (say) W = 2 Lr=Lc=0 Nc=Nr=3 addr (1,2) = 210; addr (2,1) = 214
  • 10. Linked list Linked list is the collection of nodes connected together with the help of addresses Advantages of Linked Lists They are a dynamic in nature which allocates the memory when required. Insertion and deletion operations can be easily implemented. Stacks and queues can be easily executed. Linked List reduces the access time. Disadvantages of Linked Lists The memory is wasted as pointers require extra memory for storage. No element can be accessed randomly; it has to access each node sequentially. Reverse Traversing is difficult in linked list. Applications of Linked Lists Linked lists are used to implement stacks, queues, graphs, etc. Linked lists let you insert elements at the beginning and end of the list. In Linked Lists we don’t need to know the size in advance.
  • 11. Types of Linked List Types of Linked List: • Singly Linked list or 1- way linked list • Doubly or 2-way linked list • Circular Linked list Singly Linked List : Singly linked lists contain nodes which have a data part as well as an address part i.e. next, which points to the next node in sequence of nodes. The operations we can perform on singly linked lists are insertion, deletion and traversal.
  • 12. Types of Linked List Doubly Linked List : In a doubly linked list, each node contains two links the first link points to the previous node and the next link points to the next node in the sequence. Circular Linked List : In the circular linked list the last node of the list contains the address of the first node and forms a circular chain.
  • 13. Implement a Singly Linked list in Stack #include<stdio.h> #include<conio.h> struct stu *new(int) void addnode( ); void traverse( ); struct stu { Int info; Struct stu * next; } *head=NULL, *temp,*p; Void main( ) { int a, ch; while( ch!=0) { Scanf(“%d”,&a); P=new(a); addnode(p); printf(“press 1 for vontinue and 0 for end”); scanf(“%d”, &ch); } Traverse (head); getch( ); } Struct stu *new ( int a) { p=((struct stu *) malloc (sizeof(struct stu))); p – info=a; p – next=NULL; return p; } Void addnode( ) { Temp=head; If (head==NULL) { Head=p; } Else { P – next=temp; Head=p; } Void traverse { Temp=head; While(temp!=NULL) { Printf(“%d”, temp- info); Temp=temp – next; } }
  • 14. Deletion Deleting the first node of Singly Linked List: main( ) { Int a,ch; . . Same as above programs . traverse(); delfirst() Getch(); } Void delfirst ( ) { Temp=head; Head=temp->next; Free (temp); } Deleting the last node of Singly Linked List: main( ) { Int a,ch; . . Same as above programs . traverse(); dellast() getch(); } Void dellast( ) { Temp=head; While (temp->next!=NULL) { r= temp; temp=temp->next; } r-> next=NULL; free(temp); } Deleting the particular node of Singly Linked List: Void delpart( ) { Temp=head; While (temp!=NULL) { r=temp; temp=temp->next; if(temp->info==item) { r->next=temp->next; free(temp); } } }
  • 15. Implement Doubly Linked list using Stack #include<stdio.h> #include<conio.h> struct stu *new(int) void addnode( ); void traverse( ); struct stu { Int info; Struct stu * next; Struct stu *pre; } *head=NULL, *temp,*p; Void main( ) { int a, ch; while( ch!=0) { Scanf(“%d”,&a); P=new(a); addnode(p); printf(“press 1 for Continue and 0 for end”); scanf(“%d”, &ch); } Traverse ( ); getch( ); } Struct stu *new ( int a) { p=((struct stu *) malloc (sizeof(struct stu))); p – >info=a; p – >next=NULL; p->pre=NULL; return p; } Void addnode( struct stu *p) { Temp=head; If (head==NULL) { Head=p; } Else { P – next=temp; Temp->pre=p; Head=p; } Void traverse { Temp=head; While(temp!=NULL) { Printf(“%d”, temp- info); Temp=temp – next; } }
  • 16. Delete the first node in Doubly Linked list #include<stdio.h> #include<conio.h> struct stu *new(int) void addnode( ); void traverse( ); void delfirst( ); struct stu { Int info; Struct stu * next; Struct stu *pre; } *head=NULL, *temp,*p; Void main( ) { int a, ch; while( ch!=0) { Scanf(“%d”,&a); P=new(a); addnode(p); printf(“press 1 for Continue and 0 for end”); scanf(“%d”, &ch); } Traverse ( ); delfirst ( ); getch( ); } Struct stu *new ( int a) { p=((struct stu *) malloc (sizeof(struct stu))); p – >info=a; p – >next=NULL; p->pre=NULL; return p; } Void addnode (struct stu*p) { Temp=head; If(head==NULL) { Head=p; { Else { while(temp->next!=NULL) { Temp=temp->next; } Temp->next=p; p->pre=temp; } } Void traverse( ) { Temp=head; While(temp!=NULL) Printf(“%d”, temp-> info); Temp=temp – >next; } } Void delfirst( ) { Temp=head; head=temp->next; head->pre=NULL; free(temp); }
  • 17. Program to add the before a given node in Doubly Linked list: #include<stdio.h> #include<conio.h> struct stu *new(int) void addnode( ); void traverse( ); void addbefore( ); struct stu { Int info; Struct stu * next; Struct stu *pre; } *head=NULL, *temp,*p; Void main( ) { int a, ch,item; while( ch!=0) { Scanf(“%d”,&a); P=new(a); addnode(p); printf(“press 1 for Continue and 0 for end”); scanf(“%d”, &ch); } Traverse ( ); Printf(“enter the new node value”); Scanf(“%d”,&a); P=new(a); Printf(“Enter the node value before which the value to be added”); Scanf( “%d”, &item); Addbefore( item); getch( ); } Struct stu *new ( int a) { p=((struct stu *) malloc (sizeof(struct stu))); p – >info=a; p – >next=NULL; p->pre=NULL: return p; } Void addnode (struct stu*p) { Temp=head; If(head==NULL) { Head=p; { Else { while(temp->next!=NULL) { Temp=temp->next; } Temp->next=p; p->pre=temp; } } Void traverse( ) { Temp=head; While(temp!=NULL) Printf(“%d”, temp-> info); Temp=temp – >next; } } Void addbefore( int item) { Temp=head; While(temp!=NULL) { If(temp->info==item) { p->next=temp; temp->pre->next=p; p->pre=temp->pre; } Temp=temp->next;}}
  • 18. Sparse matrix Sparse matrix is a matrix with majority of its elements equal to zeros. Linked list representation of Sparse Matrix The above given matrix is represented as:
  • 19. Program to sparse matrix void main () { static int array[10][10]; int i, j, m, n; int counter = 0; printf("Enter the order of the matix n"); scanf("%d %d", &m, &n); printf("Enter the co-efficients of the matix n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) { scanf("%d", &array[i][j]); if (array[i][j] == 0) { ++counter; } } } if (counter > ((m * n) / 2)) { printf("The given matrix is sparse matrix n"); } else printf("The given matrix is not a sparse matrix n"); printf("There are %d number of zeros", counter); }