SlideShare une entreprise Scribd logo
1  sur  19
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);
}

Contenu connexe

Tendances

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-8sumitbardhan
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)swajahatr
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked ListsJ.T.A.JONES
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
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-15sumitbardhan
 

Tendances (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
 

Similaire à Data structure

هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات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 queuessuser7319f8
 
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 SCIENCEDev Chauhan
 
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 EngineeringRAJASEKHARV8
 
–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.pdfpasqualealvarez467
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory MappingQundeel
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptxchin463670
 

Similaire à 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
 

Plus de Arvind Kumar

3 d transformation reflection
3 d transformation   reflection3 d transformation   reflection
3 d transformation reflectionArvind Kumar
 
3 d transformation Rotation
3 d transformation   Rotation3 d transformation   Rotation
3 d transformation RotationArvind Kumar
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curveArvind Kumar
 
3 D transformation translation, scaling
3 D transformation   translation, scaling3 D transformation   translation, scaling
3 D transformation translation, scalingArvind Kumar
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clippingArvind Kumar
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmArvind Kumar
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 

Plus de 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
 

Dernier

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 

Dernier (20)

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 

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); }