SlideShare a Scribd company logo
Data Structure
Dr. Tauheed Ahmed
Lecture 2: Introduction
2
Contents
Overview of Non-Primitive
Data Structure
Linked Lists: Introduction
A lists (Linear linked list) can be defined as a collection of variable number of data items
Ex. 2.1: Brokerage Firm Data
Suppose a brokerage firm maintains a
file where each record contains a
customer’s name and his or her
salesman
S. No. Customer Salesperson
1 Adams Smith
2 Brown Ray
3 Clark Jones
4 Drew Ray
5 Evans Smith
6 Farmer Jones
7 Geller Ray
8 Hill Smith
9 Infeld Ray
Is it the most effective way to represent the data?
No
Linked Lists: Introduction
Let us try to solve this, so as to have following representation
Ex. 2.1: Brokerage Firm Data
Suppose the firm wants to list the
customers for the given salesperson
S. No. Customer Salesperson
Pointer
1 Adams 3
2 Brown 2
3 Clark 1
4 Drew 2
5 Evans 3
6 Farmer 1
7 Geller 2
8 Hill 3
9 Infeld 2
Is it the most effective way to
represent the data?
No
Salespers
on Pointer
Salesperson
1 Jones
2 Ray
3 Smith
Linked Lists: Introduction
Following representation will solve the problem
S. No. Customer Link
1 Adams 5
2 Brown 4
3 Clark 6
4 Drew 7
5 Evans 8
6 Farmer 0
7 Geller 9
8 Hill 0
9 Infeld 0
Is it the most effective way to represent the data?
Yes
Salesperson
Pointer
Salesperso
n
Start
Pointer
1 Jones 3
2 Ray 2
3 Smith 1
Jones Brow
n
Drew Geller Infeld
Linked List
A linked list is a way to store a collection of elements. Like an array these can be character or integers.
Each element in a linked list is stored in the form of a node.
Definition
• Pointer
• Structure
Node
Pointers
If you have a variable in your program, will give you its address in the memory
Pointers (pointer variables)
are special variables that are
used to store addresses
rather than values.
Pointer Syntax
int* p;
(declared a pointer
p of int type.)
int *p1;
int * p2;
(declared two
pointers p1 and
p2)
int* p1, p2;
(declared a
pointer p1 and a
normal variable p2)
Accessing Pointers
Assigning addresses to Pointers
int* pc, c;
c = 5;
pc = &c;
Output: 5 Output: 1
1
What is the output ?
int* pc, c;
c = 5;
pc = &c;
printf("%d", *pc);
What is the output
int* pc, c;
c = 5;
pc = &c;
c = 1;
printf("%d", c);
printf("%d", *pc);
Structure
In C programming, a struct (or structure) is a collection of variables (can be of different
types) under a single name.
struct Person {
char name[50];
int IDNo;
float salary;
};
struct Person {
// code
};
int main() {
struct Person person1,
person2, p[20];
return 0;
}
struct Person {
// code
} person1, person2, p[20];
Create Struct Variables
• person1 and person2 are struct Person variables
• p[] is a struct Person array of size 20.
Node of a Linked List
Each node of a linked list consists of following component
struct node
{
int data;
struct node *next;
};
Node Representation
• A data item
• An address of another node
We wrap both the data item and the next
node reference in a struct as:
Arrays Vs Linked List
Data Structure:
• Contiguous
Memory
Allocation:
• Typically
allocated to the
whole array
Insertion/
Deletion:
• Inefficient
Access:
• Random
Data Structure:
• Non-Contiguous
Memory
Allocation:
• Typically
allocated one by
one to individual
elements
Insertion/
Deletion:
• Efficient
Access:
• Sequential
Linked
List
Arrays
Stack
A stack is also an ordered collection of elements like arrays, but it has a special feature that
deletion and insertion of elements can be done only from one end called the top of the stack
(TOP)
Definition
Due to this property, it is also
called as last in first out type of
data structure (LIFO).
Stack
When an element is inserted into a stack or removed from the stack, its base remains fixed
where the top of stack changes
Insertion of element into
stack is called PUSH and
deletion of element from
stack is called POP.
Stack: Implementation
The stack can
be
implemented
into two ways:
Using arrays (Static implementation)
Using Linked List (Dynamic implementation)
Queue
A Queue is also an ordered collection of elements that follows the principle of "First in, First out"
(FIFO), where the first element added to the queue is the first one to be removed.
Definition
Due to this property, it is also
called as First in first out type of
data structure (FIFO).
Queue
In a queue new elements are added to the queue from one end called REAR end and the
element are always removed from the other end called the FRONT end.
Insertion of element into
queue is called Enqueue
and deletion of element
from queue is called
Dequeue.
Queue: Implementation
The Queue can
be
implemented
into two ways:
Using arrays (Static implementation)
Using Linked List (Dynamic implementation)
Tree
Tree data structure is a hierarchical structure that is used to represent and organize data in the
form of parent child relationship.
Definition
• There is a special data item at the top of hierarchy
called the Root of the tree.
• The remaining data items are partitioned into
number of mutually exclusive subset, each of which
is itself, a tree which is called the sub tree.
• The tree always grows in length towards bottom
in data structures, unlike natural trees which grows
upwards.
Graph
A graph G(V,E) is a set of vertices V and a set of edges E.
Definition
A graph data structure is a collection of nodes that have
data and are connected to other nodes.
Graph
An edge connects a pair of vertices and many have weight such as length, cost and another
measuring instrument for according the graph.
Vertices on the graph are shown as point or circles and edges are drawn as arcs or line
segment.
Example of graph:
Question
1. What is the correct syntax for declaring an integer array in C?
2. What is the major limitation of arrays?
A. They can only store integers.
B. They require predefined size.
C. They can only store characters.
D. They are immutable.
C
B
Question
3. What does each node in a linked list consist of?
A. Only data
B. Only a pointer to the next node
C. Data and a pointer to another node
D. None of the above
4. In a graph, what does an edge represent?
A. single node
B. A connection between two vertices
C. The weight of the graph
D. A hierarchical structure
C
B

More Related Content

PPTX
1.Introduction to Data Structures and Algorithms.pptx
BlueSwede
 
PPT
data structure algorithm example and example
lionelmessi593584
 
PPT
Unit 1.ppt
Minakshee Patil
 
PPT
DS.ppt Datatastructures notes presentation
SakkaravarthiShanmug
 
PPT
Fundamentals of data structure syallabus
kashvigoyal020106
 
PDF
Data structure
Gaurav Handge
 
PPTX
Data structure chapter 1.pptx
Kami503928
 
PPT
DS_PPT.ppt
MeghaKulkarni27
 
1.Introduction to Data Structures and Algorithms.pptx
BlueSwede
 
data structure algorithm example and example
lionelmessi593584
 
Unit 1.ppt
Minakshee Patil
 
DS.ppt Datatastructures notes presentation
SakkaravarthiShanmug
 
Fundamentals of data structure syallabus
kashvigoyal020106
 
Data structure
Gaurav Handge
 
Data structure chapter 1.pptx
Kami503928
 
DS_PPT.ppt
MeghaKulkarni27
 

Similar to Lecture 2 ppt ffffffffffffffffffffffffff (20)

PPT
Lecture 1 - Overview of Data Structure .ppt
neelam108thapa
 
PPTX
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
PPTX
Data Structures and Algorithms Fundamentals
Ashwin Kumar Ramasamy
 
PPT
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
PDF
Introduction to Data Structure
Jazz Jinia Bhowmik
 
PPT
1597380885789.ppt
PraveenKumar977108
 
PPTX
data structures module I & II.pptx
rani marri
 
PPTX
sourabhpptsasdfghjkcdfxcvhbycfxv hgvihjubgveminar.pptx
gagaco5776
 
PDF
INTRODUCTION TO DATA STRUCTURES AND ALGORITHM
workspaceabhishekmah
 
PDF
INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
workspaceabhishekmah
 
PPTX
ds classificationtypeswithexampleimages.pptx
SriRanjani60
 
PPTX
Data Structure , Classification of Data structure
vdeepa7
 
PPT
PMDATA STRUICVIUDGHfjufguigfuigkguidfui.ppt
srahul53094
 
PPT
data structure details of types and .ppt
poonamsngr
 
PDF
CSE_D:11:_Somnath Mallick_3rd semister.pdf
Somnathmallick8
 
PPTX
Data Structure & Algorithm.pptx
Mumtaz
 
PPT
data structure programing language in c.ppt
LavkushGupta12
 
PPTX
Introduction to data structure presentations
jayajadhav7
 
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
SKUP1
 
Lecture 1 - Overview of Data Structure .ppt
neelam108thapa
 
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
Data Structures and Algorithms Fundamentals
Ashwin Kumar Ramasamy
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
Introduction to Data Structure
Jazz Jinia Bhowmik
 
1597380885789.ppt
PraveenKumar977108
 
data structures module I & II.pptx
rani marri
 
sourabhpptsasdfghjkcdfxcvhbycfxv hgvihjubgveminar.pptx
gagaco5776
 
INTRODUCTION TO DATA STRUCTURES AND ALGORITHM
workspaceabhishekmah
 
INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
workspaceabhishekmah
 
ds classificationtypeswithexampleimages.pptx
SriRanjani60
 
Data Structure , Classification of Data structure
vdeepa7
 
PMDATA STRUICVIUDGHfjufguigfuigkguidfui.ppt
srahul53094
 
data structure details of types and .ppt
poonamsngr
 
CSE_D:11:_Somnath Mallick_3rd semister.pdf
Somnathmallick8
 
Data Structure & Algorithm.pptx
Mumtaz
 
data structure programing language in c.ppt
LavkushGupta12
 
Introduction to data structure presentations
jayajadhav7
 
DATA STRUCTURES AND LINKED LISTS IN C.pptx
SKUP1
 
Ad

Recently uploaded (20)

PPTX
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
PDF
WISE main accomplishments for ISQOLS award July 2025.pdf
StatsCommunications
 
PPTX
Blue and Dark Blue Modern Technology Presentation.pptx
ap177979
 
PPTX
short term project on AI Driven Data Analytics
JMJCollegeComputerde
 
PDF
Technical Writing Module-I Complete Notes.pdf
VedprakashArya13
 
PDF
An Uncut Conversation With Grok | PDF Document
Mike Hydes
 
PDF
Practical Measurement Systems Analysis (Gage R&R) for design
Rob Schubert
 
PPTX
The whitetiger novel review for collegeassignment.pptx
DhruvPatel754154
 
PDF
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
PPTX
Fuzzy_Membership_Functions_Presentation.pptx
pythoncrazy2024
 
PPTX
Databricks-DE-Associate Certification Questions-june-2024.pptx
pedelli41
 
PPTX
INFO8116 - Week 10 - Slides.pptx data analutics
guddipatel10
 
PDF
Key_Statistical_Techniques_in_Analytics_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
MR and reffffffvvvvvvvfversal_083605.pptx
manjeshjain
 
PPTX
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
PDF
Blue Futuristic Cyber Security Presentation.pdf
tanvikhunt1003
 
PDF
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
PPTX
Multiscale Segmentation of Survey Respondents: Seeing the Trees and the Fores...
Sione Palu
 
PPT
Real Life Application of Set theory, Relations and Functions
manavparmar205
 
PDF
SUMMER INTERNSHIP REPORT[1] (AutoRecovered) (6) (1).pdf
pandeydiksha814
 
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
WISE main accomplishments for ISQOLS award July 2025.pdf
StatsCommunications
 
Blue and Dark Blue Modern Technology Presentation.pptx
ap177979
 
short term project on AI Driven Data Analytics
JMJCollegeComputerde
 
Technical Writing Module-I Complete Notes.pdf
VedprakashArya13
 
An Uncut Conversation With Grok | PDF Document
Mike Hydes
 
Practical Measurement Systems Analysis (Gage R&R) for design
Rob Schubert
 
The whitetiger novel review for collegeassignment.pptx
DhruvPatel754154
 
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
Fuzzy_Membership_Functions_Presentation.pptx
pythoncrazy2024
 
Databricks-DE-Associate Certification Questions-june-2024.pptx
pedelli41
 
INFO8116 - Week 10 - Slides.pptx data analutics
guddipatel10
 
Key_Statistical_Techniques_in_Analytics_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
MR and reffffffvvvvvvvfversal_083605.pptx
manjeshjain
 
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
Blue Futuristic Cyber Security Presentation.pdf
tanvikhunt1003
 
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
Multiscale Segmentation of Survey Respondents: Seeing the Trees and the Fores...
Sione Palu
 
Real Life Application of Set theory, Relations and Functions
manavparmar205
 
SUMMER INTERNSHIP REPORT[1] (AutoRecovered) (6) (1).pdf
pandeydiksha814
 
Ad

Lecture 2 ppt ffffffffffffffffffffffffff

  • 1. Data Structure Dr. Tauheed Ahmed Lecture 2: Introduction
  • 3. Linked Lists: Introduction A lists (Linear linked list) can be defined as a collection of variable number of data items Ex. 2.1: Brokerage Firm Data Suppose a brokerage firm maintains a file where each record contains a customer’s name and his or her salesman S. No. Customer Salesperson 1 Adams Smith 2 Brown Ray 3 Clark Jones 4 Drew Ray 5 Evans Smith 6 Farmer Jones 7 Geller Ray 8 Hill Smith 9 Infeld Ray Is it the most effective way to represent the data? No
  • 4. Linked Lists: Introduction Let us try to solve this, so as to have following representation Ex. 2.1: Brokerage Firm Data Suppose the firm wants to list the customers for the given salesperson S. No. Customer Salesperson Pointer 1 Adams 3 2 Brown 2 3 Clark 1 4 Drew 2 5 Evans 3 6 Farmer 1 7 Geller 2 8 Hill 3 9 Infeld 2 Is it the most effective way to represent the data? No Salespers on Pointer Salesperson 1 Jones 2 Ray 3 Smith
  • 5. Linked Lists: Introduction Following representation will solve the problem S. No. Customer Link 1 Adams 5 2 Brown 4 3 Clark 6 4 Drew 7 5 Evans 8 6 Farmer 0 7 Geller 9 8 Hill 0 9 Infeld 0 Is it the most effective way to represent the data? Yes Salesperson Pointer Salesperso n Start Pointer 1 Jones 3 2 Ray 2 3 Smith 1 Jones Brow n Drew Geller Infeld
  • 6. Linked List A linked list is a way to store a collection of elements. Like an array these can be character or integers. Each element in a linked list is stored in the form of a node. Definition • Pointer • Structure Node
  • 7. Pointers If you have a variable in your program, will give you its address in the memory Pointers (pointer variables) are special variables that are used to store addresses rather than values. Pointer Syntax int* p; (declared a pointer p of int type.) int *p1; int * p2; (declared two pointers p1 and p2) int* p1, p2; (declared a pointer p1 and a normal variable p2)
  • 8. Accessing Pointers Assigning addresses to Pointers int* pc, c; c = 5; pc = &c; Output: 5 Output: 1 1 What is the output ? int* pc, c; c = 5; pc = &c; printf("%d", *pc); What is the output int* pc, c; c = 5; pc = &c; c = 1; printf("%d", c); printf("%d", *pc);
  • 9. Structure In C programming, a struct (or structure) is a collection of variables (can be of different types) under a single name. struct Person { char name[50]; int IDNo; float salary; }; struct Person { // code }; int main() { struct Person person1, person2, p[20]; return 0; } struct Person { // code } person1, person2, p[20]; Create Struct Variables • person1 and person2 are struct Person variables • p[] is a struct Person array of size 20.
  • 10. Node of a Linked List Each node of a linked list consists of following component struct node { int data; struct node *next; }; Node Representation • A data item • An address of another node We wrap both the data item and the next node reference in a struct as:
  • 11. Arrays Vs Linked List Data Structure: • Contiguous Memory Allocation: • Typically allocated to the whole array Insertion/ Deletion: • Inefficient Access: • Random Data Structure: • Non-Contiguous Memory Allocation: • Typically allocated one by one to individual elements Insertion/ Deletion: • Efficient Access: • Sequential Linked List Arrays
  • 12. Stack A stack is also an ordered collection of elements like arrays, but it has a special feature that deletion and insertion of elements can be done only from one end called the top of the stack (TOP) Definition Due to this property, it is also called as last in first out type of data structure (LIFO).
  • 13. Stack When an element is inserted into a stack or removed from the stack, its base remains fixed where the top of stack changes Insertion of element into stack is called PUSH and deletion of element from stack is called POP.
  • 14. Stack: Implementation The stack can be implemented into two ways: Using arrays (Static implementation) Using Linked List (Dynamic implementation)
  • 15. Queue A Queue is also an ordered collection of elements that follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. Definition Due to this property, it is also called as First in first out type of data structure (FIFO).
  • 16. Queue In a queue new elements are added to the queue from one end called REAR end and the element are always removed from the other end called the FRONT end. Insertion of element into queue is called Enqueue and deletion of element from queue is called Dequeue.
  • 17. Queue: Implementation The Queue can be implemented into two ways: Using arrays (Static implementation) Using Linked List (Dynamic implementation)
  • 18. Tree Tree data structure is a hierarchical structure that is used to represent and organize data in the form of parent child relationship. Definition • There is a special data item at the top of hierarchy called the Root of the tree. • The remaining data items are partitioned into number of mutually exclusive subset, each of which is itself, a tree which is called the sub tree. • The tree always grows in length towards bottom in data structures, unlike natural trees which grows upwards.
  • 19. Graph A graph G(V,E) is a set of vertices V and a set of edges E. Definition A graph data structure is a collection of nodes that have data and are connected to other nodes.
  • 20. Graph An edge connects a pair of vertices and many have weight such as length, cost and another measuring instrument for according the graph. Vertices on the graph are shown as point or circles and edges are drawn as arcs or line segment. Example of graph:
  • 21. Question 1. What is the correct syntax for declaring an integer array in C? 2. What is the major limitation of arrays? A. They can only store integers. B. They require predefined size. C. They can only store characters. D. They are immutable. C B
  • 22. Question 3. What does each node in a linked list consist of? A. Only data B. Only a pointer to the next node C. Data and a pointer to another node D. None of the above 4. In a graph, what does an edge represent? A. single node B. A connection between two vertices C. The weight of the graph D. A hierarchical structure C B