SlideShare a Scribd company logo
CS1301 Data Structures
Unit I INTRODUCTION
 Introduction
 Data structure
 Linked DS
 Succinct DS
 Implicit DS
 Compressed DS
 Search DS
 Static and Dynamic DS
 Persistent DS
 Concurrent DS
 Arrays
 Recursions
Data structure
• a particular way of storing and organizing
data in a computer so that it can be used
efficiently.
Linked DS
• is a data structure which consists of a set of data
records (nodes) linked together and organized by
references (links or pointers)
• In linked data structures, the links are usually
treated as special data types that can only be
compared for equality
• a structure contains a pointer to another instance
of the same structure or different structure
• Linking can be done in two ways - Using dynamic
allocation and using array index linking
• include linked lists, search trees, expression trees
Linked DS
• Advantages against arrays
– more flexibility
– saving wasted memory (built dynamically)
– the reference to each node gives us the information
where to find out the next one
– Memory can be utilized more efficiently
Linked DS
• General disadvantages
– follow multiple pointers so element access time
varies
– may also use more memory
Linked LIST
• Consists of series of node
• Each node of the list contains
• the data item
• a pointer to the next node
• Flexible space use
• Dynamically allocate space for each element as needed
• Include a pointer to the next item
Object
Data Next
Linked LIST
• Types of Linked List
– Singly Linked List
– Doubly Linked List
– Circular Linked List
SINGLY Linked LIST
• Each node contains only one link field pointing
to the next node in the list
700 1000 800
550 700 1000 800
10 20 30 40
Header
SINGLY Linked LIST
 Collection structure has a pointer to the list head
 Initially NULL
 Add first item
 Allocate space for node
 Set its data pointer to object
 Set Next to NULL
 Set Head to point to new node
Data Next
object
Head
Collection
node
SINGLY Linked LIST
 Add second item
 Allocate space for node
 Set its data pointer to object
 Set Next to current Head
 Set Head to point to new node
Data Next
object
Head
Collection
node
Data Next
object2
node
SINGLY Linked LIST
• Declaration for Linked List
Struct node;
typedef struct Node *List
typedef struct Node *Position
int IsLast (List L);
int IsEmpty(List L);
position Find(int x, List L);
void delete(int x, List L);
Struct node
{
int element;
position next;
};
SINGLY Linked LIST
• Routine to insert an element in the list
void insert(int x, List L, Position P) // insert after position P
{
Position Newnode;
Newnode = malloc(size of(Struct Node));
If(Newnode !=NULL)
{
Newnode Element =X;
Newnode  Next =PNext;
P  Next = Newnode;
}
}
To insert an element in the list
SINGLY Linked LIST
• Routine to check whether list is empty
int IsEmpty(List L) // returns 1 if L is empty
{
if (L Next == NULL)
return(1);
}
SINGLY Linked LIST
• Routine to check whether current
position is last
int IsLast(position p,List L) // returns 1 if P is the last
position in L
{
if (P Next == NULL)
return(1);
}
SINGLY Linked LIST
• Find Routine
position Find(int x,List L)
{
//Returns the position of x in L, null if x is not found
Position P;
P= L Next;
while(P!= NULL && PElement!= X)
P=PNext
return P;
}
SINGLY Linked LIST
• Find Previous Routine
position Findprevious(int x,List L)
{
//Returns the position of the predecessor
Position p;
P=L
while(P Next!= NULL && PNextElement!= X)
P=PNext
return P;
}
SINGLY Linked LIST
• Find Next Routine
position FindNext(int x,List L)
{
//Returns the position of its successor
P=L Next
while(P Next!= NULL && PElement!= X)
P=PNext
return PNext;
}
SINGLY Linked LIST
• Routine to delete an element from the list
Void Delete(int x, List L)
{
// Delete the first occurrence of X from the list
position P, temp;
P= Findprevious(x,L);
If(!IsLast(P,L))
{
Temp=P Next;
PNext = Temp Next
free(temp);
}
}
SINGLY Linked LIST
• Routine to delete the list
Void DeleteList(List L)
{
position P, Temp;
P= LNext ;
LNext = NULL;
while(P!=NULL)
{
Temp=P Next;
free(P);
P=Temp;
}
}
DoUBLY Linked LIST
• Each node has three fields
– Data field
– Forward Link(FLINK)
– Backward link(BLINK)
• FLINK points to the successor node in the list
• BLINK points to the predecessor node
BLINK Data FLINK
Doubly Linked LIST
L
10 20
Header
30
Structure Declaration
Struct Node
{
Int element;
Struct Node *FLINK;
Struct Node *BLINK;
}
DoUBLY Linked LIST
Routine to insert an element in a doubly linked list
Void insert(int x, list l, position p)
{
struct Node *Newnode;
Newnode= malloc(size of(Struct Node));
If (Newnode !=NULL)
{
Newnode  Element =x;
Newnode  Flink = p Flink;
P  flink  blink =Newnode;
P  Flink = Newnode;
Newnode  Blink = p;
}
}
DoUBLY Linked LIST
DoUBLY Linked LIST
DoUBLY Linked LIST
• Advantages
– Deletion operation is easier
– Finding predecessor & successor of a node is
easier
• Disadvantages
– More memory space required since it has two
pointers
CIRCULAR Linked LIST
• Pointer of last node points to the first
node
• Types
–Singly Linked Circular List
–Doubly Linked circular List
CIRCULAR Linked LIST
• Singly Linked Circular List
–Last node of the list points to the first
node
CIRCULAR Linked LIST
• Doubly Linked Circular List
– Doubly linked list
– Forward link of last node points to the first node
– Backward link of the first node points to the last
node of the list
CIRCULAR Linked LIST
• Advantages
–Allows to traverse the list starting at any
point
–Allows quick access to the first and last
records
–Circular doubly linked list allows the list to
traverse in either directions.
POINTERS and arrays
• Special variables which contain the address of
another memory location
int arr[4] = {2,4,6,8};
• arr acts as constant pointer pointing to first
element
• arr= &arr[0]=100
arr[0] arr[1] arr[2] arr[3]
100 102 104 106
• & is the address operator, represents address of
the variable
• %u – obtaining the address
2 4 6 8
POINTERS
main()
{
int a=2;
printf(“value of a=%d”,a);
printf(“addressof a=%u”,&a);
} a – variable name
value of a or value at address 1000
1000 - address
2
• * operator is the value of at the address operator
• Pointer variable declaration - * should preced variable
name
int *b;
b=&a;
• b is the variable which contains the address of variable
a as its value
• Pointer variable that stores the address of a pointer
variable
int a=2;
int *b;
int **c;
b=&a;
c=&b;
• C has been declared as pointer to pointer variable
which contains the address of pointer variable b

More Related Content

PPTX
Javascript ADT - List
PPT
Intro to Lists
PDF
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
PDF
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
PPTX
Lists
PPT
Data structures & algorithms lecture 3
PDF
The List Data Model
PDF
Data structures list
Javascript ADT - List
Intro to Lists
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Lists
Data structures & algorithms lecture 3
The List Data Model
Data structures list

What's hot (20)

PPTX
R DATA STRUCTURES 2
PPTX
R DATA STRUCTURES 1
PPT
Intro ds
PPTX
Data structures and algorithms
PPTX
Data structures - unit 1
PPTX
Data Structures (CS8391)
PPTX
Lists in Python
PPT
702 present
PPTX
Loops and arrays
PPTX
Arrays
PPSX
Algorithm and Programming (Searching)
PPT
List data structure
PPT
Presentation of array
PPTX
Array in c
PPTX
Understanding the components of standard template library
PPTX
Introduction to data structure
PPTX
Report cs3 pillos
R DATA STRUCTURES 2
R DATA STRUCTURES 1
Intro ds
Data structures and algorithms
Data structures - unit 1
Data Structures (CS8391)
Lists in Python
702 present
Loops and arrays
Arrays
Algorithm and Programming (Searching)
List data structure
Presentation of array
Array in c
Understanding the components of standard template library
Introduction to data structure
Report cs3 pillos
Ad

Similar to Data structures2 (20)

PPTX
Data structure
PPTX
Deleting a node from the list(SINGLE LINKED LIST)
PDF
Document on Linked List as a presentation
PDF
Document on Linked List as a presentation
PPT
DS Unit 2.ppt
PDF
DS Module 03.pdf
PPTX
Data Structures Introduction & Linear DS
PPT
ANOITO2341988888888888888888888885555.ppt
PPTX
UNIT -4 Singly Linked List-kiruthika.pptx
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
Linked List in Data Structure
PPTX
linkedlistforslideshare-210123143943.pptx
PPT
Unit ii(dsc++)
PPTX
Linked list
PPTX
VCE Unit 02 (1).pptx
PPTX
Linked lists linked lists vs Arrays.pptx
PPTX
Implemention of Linked list concept in Data Structures
PDF
ds-lecture-4-171012041008 (1).pdf
PPTX
Linked List.pptx
Data structure
Deleting a node from the list(SINGLE LINKED LIST)
Document on Linked List as a presentation
Document on Linked List as a presentation
DS Unit 2.ppt
DS Module 03.pdf
Data Structures Introduction & Linear DS
ANOITO2341988888888888888888888885555.ppt
UNIT -4 Singly Linked List-kiruthika.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
Linked List in Data Structure
linkedlistforslideshare-210123143943.pptx
Unit ii(dsc++)
Linked list
VCE Unit 02 (1).pptx
Linked lists linked lists vs Arrays.pptx
Implemention of Linked list concept in Data Structures
ds-lecture-4-171012041008 (1).pdf
Linked List.pptx
Ad

More from Parthipan Parthi (20)

PPTX
Inheritance
PPTX
Switch statement mcq
PPTX
Oprerator overloading
PPTX
802.11 mac
PPT
Ieee 802.11 wireless lan
PPTX
Computer network
PPT
Ieee 802.11 wireless lan
PPTX
Session 6
PPT
Queuing analysis
PPTX
Alternative metrics
PPT
PPT
Ieee 802.11 wireless lan
PPTX
Data structures1
PPTX
Data structures 4
PPTX
Data structures 3
PPT
Input output streams
PPT
Io stream
DOC
Dbms lab questions
PPTX
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
Inheritance
Switch statement mcq
Oprerator overloading
802.11 mac
Ieee 802.11 wireless lan
Computer network
Ieee 802.11 wireless lan
Session 6
Queuing analysis
Alternative metrics
Ieee 802.11 wireless lan
Data structures1
Data structures 4
Data structures 3
Input output streams
Io stream
Dbms lab questions
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3

Recently uploaded (20)

PPTX
UNIT 4 Total Quality Management .pptx
PDF
PPT on Performance Review to get promotions
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT
Project quality management in manufacturing
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
DOCX
573137875-Attendance-Management-System-original
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
composite construction of structures.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
UNIT 4 Total Quality Management .pptx
PPT on Performance Review to get promotions
Embodied AI: Ushering in the Next Era of Intelligent Systems
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Geodesy 1.pptx...............................................
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
CH1 Production IntroductoryConcepts.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Project quality management in manufacturing
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
573137875-Attendance-Management-System-original
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
composite construction of structures.pdf
bas. eng. economics group 4 presentation 1.pptx

Data structures2

  • 2. Unit I INTRODUCTION  Introduction  Data structure  Linked DS  Succinct DS  Implicit DS  Compressed DS  Search DS  Static and Dynamic DS  Persistent DS  Concurrent DS  Arrays  Recursions
  • 3. Data structure • a particular way of storing and organizing data in a computer so that it can be used efficiently.
  • 4. Linked DS • is a data structure which consists of a set of data records (nodes) linked together and organized by references (links or pointers) • In linked data structures, the links are usually treated as special data types that can only be compared for equality • a structure contains a pointer to another instance of the same structure or different structure • Linking can be done in two ways - Using dynamic allocation and using array index linking • include linked lists, search trees, expression trees
  • 5. Linked DS • Advantages against arrays – more flexibility – saving wasted memory (built dynamically) – the reference to each node gives us the information where to find out the next one – Memory can be utilized more efficiently
  • 6. Linked DS • General disadvantages – follow multiple pointers so element access time varies – may also use more memory
  • 7. Linked LIST • Consists of series of node • Each node of the list contains • the data item • a pointer to the next node • Flexible space use • Dynamically allocate space for each element as needed • Include a pointer to the next item Object Data Next
  • 8. Linked LIST • Types of Linked List – Singly Linked List – Doubly Linked List – Circular Linked List
  • 9. SINGLY Linked LIST • Each node contains only one link field pointing to the next node in the list 700 1000 800 550 700 1000 800 10 20 30 40 Header
  • 10. SINGLY Linked LIST  Collection structure has a pointer to the list head  Initially NULL  Add first item  Allocate space for node  Set its data pointer to object  Set Next to NULL  Set Head to point to new node Data Next object Head Collection node
  • 11. SINGLY Linked LIST  Add second item  Allocate space for node  Set its data pointer to object  Set Next to current Head  Set Head to point to new node Data Next object Head Collection node Data Next object2 node
  • 12. SINGLY Linked LIST • Declaration for Linked List Struct node; typedef struct Node *List typedef struct Node *Position int IsLast (List L); int IsEmpty(List L); position Find(int x, List L); void delete(int x, List L); Struct node { int element; position next; };
  • 13. SINGLY Linked LIST • Routine to insert an element in the list void insert(int x, List L, Position P) // insert after position P { Position Newnode; Newnode = malloc(size of(Struct Node)); If(Newnode !=NULL) { Newnode Element =X; Newnode  Next =PNext; P  Next = Newnode; } }
  • 14. To insert an element in the list
  • 15. SINGLY Linked LIST • Routine to check whether list is empty int IsEmpty(List L) // returns 1 if L is empty { if (L Next == NULL) return(1); }
  • 16. SINGLY Linked LIST • Routine to check whether current position is last int IsLast(position p,List L) // returns 1 if P is the last position in L { if (P Next == NULL) return(1); }
  • 17. SINGLY Linked LIST • Find Routine position Find(int x,List L) { //Returns the position of x in L, null if x is not found Position P; P= L Next; while(P!= NULL && PElement!= X) P=PNext return P; }
  • 18. SINGLY Linked LIST • Find Previous Routine position Findprevious(int x,List L) { //Returns the position of the predecessor Position p; P=L while(P Next!= NULL && PNextElement!= X) P=PNext return P; }
  • 19. SINGLY Linked LIST • Find Next Routine position FindNext(int x,List L) { //Returns the position of its successor P=L Next while(P Next!= NULL && PElement!= X) P=PNext return PNext; }
  • 20. SINGLY Linked LIST • Routine to delete an element from the list Void Delete(int x, List L) { // Delete the first occurrence of X from the list position P, temp; P= Findprevious(x,L); If(!IsLast(P,L)) { Temp=P Next; PNext = Temp Next free(temp); } }
  • 21. SINGLY Linked LIST • Routine to delete the list Void DeleteList(List L) { position P, Temp; P= LNext ; LNext = NULL; while(P!=NULL) { Temp=P Next; free(P); P=Temp; } }
  • 22. DoUBLY Linked LIST • Each node has three fields – Data field – Forward Link(FLINK) – Backward link(BLINK) • FLINK points to the successor node in the list • BLINK points to the predecessor node BLINK Data FLINK
  • 23. Doubly Linked LIST L 10 20 Header 30 Structure Declaration Struct Node { Int element; Struct Node *FLINK; Struct Node *BLINK; }
  • 24. DoUBLY Linked LIST Routine to insert an element in a doubly linked list Void insert(int x, list l, position p) { struct Node *Newnode; Newnode= malloc(size of(Struct Node)); If (Newnode !=NULL) { Newnode  Element =x; Newnode  Flink = p Flink; P  flink  blink =Newnode; P  Flink = Newnode; Newnode  Blink = p; } }
  • 27. DoUBLY Linked LIST • Advantages – Deletion operation is easier – Finding predecessor & successor of a node is easier • Disadvantages – More memory space required since it has two pointers
  • 28. CIRCULAR Linked LIST • Pointer of last node points to the first node • Types –Singly Linked Circular List –Doubly Linked circular List
  • 29. CIRCULAR Linked LIST • Singly Linked Circular List –Last node of the list points to the first node
  • 30. CIRCULAR Linked LIST • Doubly Linked Circular List – Doubly linked list – Forward link of last node points to the first node – Backward link of the first node points to the last node of the list
  • 31. CIRCULAR Linked LIST • Advantages –Allows to traverse the list starting at any point –Allows quick access to the first and last records –Circular doubly linked list allows the list to traverse in either directions.
  • 32. POINTERS and arrays • Special variables which contain the address of another memory location int arr[4] = {2,4,6,8}; • arr acts as constant pointer pointing to first element • arr= &arr[0]=100 arr[0] arr[1] arr[2] arr[3] 100 102 104 106 • & is the address operator, represents address of the variable • %u – obtaining the address 2 4 6 8
  • 33. POINTERS main() { int a=2; printf(“value of a=%d”,a); printf(“addressof a=%u”,&a); } a – variable name value of a or value at address 1000 1000 - address 2
  • 34. • * operator is the value of at the address operator • Pointer variable declaration - * should preced variable name int *b; b=&a; • b is the variable which contains the address of variable a as its value • Pointer variable that stores the address of a pointer variable int a=2; int *b; int **c; b=&a; c=&b; • C has been declared as pointer to pointer variable which contains the address of pointer variable b