SlideShare a Scribd company logo
1 of 12
What is Data Structure?
 Data structure is an arrangement of data in computer's memory. It
makes the data quickly available to the processor for required operations.
 It is a software artifact which allows data to be stored, organized and
accessed.
 It is a structure program used to store ordered data, so that various
operations can be performed on it easily.
For example, if we have an employee's data like name 'ABC' and salary
10000. Here, 'ABC' is of String data type and 10000 is of Float data type.
We can organize this data as a record like Employee record and collect &
store employee's records in a file or database as a data structure like 'ABC'
10000, 'PQR' 15000, 'STU' 5000.
 Data structure is about providing data elements in terms of some
relationship for better organization and storage.
 It is a specialized format for organizing and storing data that can be
accessed within appropriate ways.
Why is Data Structure important?
 Data structure is important because it is used in almost every
program or software system.
 It helps to write efficient code, structures the code and solve
problems.
 Data can be maintained more easily by encouraging a better design or
implementation.
 Data structure is just a container for the data that is used to store,
manipulate and arrange. It can be processed by algorithms.
For example, while using a shopping website like Flipkart or Amazon, the
users know their last orders and can track them. The orders are stored in a
database as records.
However, when the program needs them so that it can pass the data
somewhere else (such as to a warehouse) or display it to the user, it loads
the data in some form of data structure.
Types of Data Structure
A. Primitive Data Type
 Primitive data types are the data types available in most of the programming
languages.
 These data types are used to represent single value.
 It is a basic data type available in most of the programming language.
Data type Description
Integer Used to represent a number without decimal point.
Float Used to represent a number with decimal point.
Character Used to represent single character.
Boolean Used to represent logical values either true or false.
B. Non-Primitive Data Type
 Data type derived from primary data types are known as Non-Primitive data
types.
 Non-Primitive data types are used to store group of values.
 It can be divided into two types:
1. Linear Data Structure
2. Non-Linear Data Structure
1. Linear Data Structure
Linear data structure traverses the data elements sequentially.
 In linear data structure, only one data element can directly be reached.
 It includes array, linked list, stack and queues.

Types Description
Arrays Array is a collection of elements. It is used in mathematical problems like matrix, algebra etc.
each element of an array is referenced by a subscripted variable or value, called subscript or
index enclosed in parenthesis.
Linked
list
Linked list is a collection of data elements. It consists of two parts: Info and Link. Info gives
information and Link is an address of next node. Linked list can be implemented by using
pointers.
Stack Stack is a list of elements. In stack, an element may be inserted or deleted at one end which is
known as Top of the stack. It performs two operations: Push and Pop. Push means adding an
element in stack and Pop means removing an element in stack. It is also called Last-in-First-
out (LIFO).
Queue Queue is a linear list of element. In queue, elements are added at one end called rear and the
existing elements are deleted from other end called front. It is also called as First-in-First-out
(FIFO).
2. Non-Linear Data Structure
 Non-Linear data structure is opposite to linear data structure.
 In non-linear data structure, the data values are not arranged in order and a
data item is connected to several other data items.
 It uses memory efficiently. Free contiguous memory is not required for
allocating data items.
 It includes trees and graphs.
Type Description
Tree Tree is a flexible, versatile and powerful non-linear data structure. It is used to represent data
items processing hierarchical relationship between the grandfather and his children &
grandchildren. It is an ideal data structure for representing hierarchical data.
Graph Graph is a non-linear data structure which consists of a finite set of ordered pairs called edges.
Graph is a set of elements connected by edges. Each elements are called a vertex and node.
Abstract Data type (ADT)
What is ADT?
 ADT stands for Abstract Data Type.
 It is an abstraction of a data structure.
 Abstract data type is a mathematical model of a data structure.
 It describes a container which holds a finite number of objects where the
objects may be associated through a given binary relationship.
 It is a logical description of how we view the data and the operations
allowed without regard to how they will be implemented.
 ADT concerns only with what the data is representing and not with how it
will eventually be constructed.
 It is a set of objects and operations. For example, List, Insert, Delete,
Search, Sort.
It consists offollowing three parts:
1. Data
2. Operation
3. Error
1. Data describes the structure of the data used in the ADT.
2. Operationdescribes valid operations for the ADT. It describes its interface.
3. Error describes how to deal with the errors that can occur.
Advantages of ADT
 ADT is reusable and ensures robust data structure.
 It reduces coding efforts.
 Encapsulation ensures that data cannot be corrupted.
 ADT is based on principles of Object Oriented Programming (OOP) and
Software Engineering (SE).
 It specifies error conditions associated with operations.
What is Stack?
 Stack is an ordered list of the same type of elements.
 It is a linear list where all insertions and deletions are permitted only at one
end of the list.
 Stack is a LIFO (Last In First Out) structure.
 In a stack, when an element is added, it goes to the top of the stack.
Definition
“Stack is a collection of similar data items in which both insertion and deletion
operations are performed based on LIFO principle”.
There are two basic operations performed in a Stack:
1. Push() function is used to add or insert new elements into the stack.
2. Pop() function is used to delete or remove an element from the stack.
 When a stack is completely full, it is said to be Overflow state and if stack
is completely empty, it is said to be Underflow state.
 Stack allows operations at one end only. Stack behaves like a real life stack,
for example, in a real life, we can remove a plate or dish from the top of the
stack only or while playing a deck of cards, we can place or remove a card
from top of the stack only.
Similarly, here also, we can only access the top element of a stack.
 According to its LIFO structure, the element which is inserted last, is
accessed first.
Implementation of Stack
The above diagram represents a stack insertion operation. In a stack, inserting and
deleting of elements are performed at a single position which is known as, Top.
Insertion operation can be performed using Push() function. New element is added
at top of the stack and removed from top of the stack, as shown in the diagram
below:
An element is removed from top of the stack. Delete operation is based on LIFO
principle. This operation is performed using a Pop() function. It means that the
insertion and deletion operations are performed at one end i.e at Top.
Following table shows the Position of Top which indicates the status of stack:
Position of Top Status of Stack
-1 Stack is empty.
0 Only one element in a stack.
N - 1 Stack is full.
N Stack is overflow. (Overflow state)
Applications of Stack
The simplest application of a stack is to reverse a word. You push a given word to
stack - letter by letter - and then pop letters from the stack.
There are other uses also like:
1. Parsing
2. Expression Conversion(Infix to Postfix, Postfix to Prefix etc)
* Below program is written in C++ language */
# include<iostream>
class Stack
{
int top;
public:
int a[10]; //Maximum size of Stack
Stack()
{
top = -1;
}
void push(int x);
int pop();
void isEmpty();
};
void Stack::push(int x)
{
if(top >= 10)
{
cout << "Stack Overflow n";
}
else
{
a[++top] = x;
cout << "Element Inserted n";
}
}
int Stack::pop()
{
if(top < 0)
{
cout << "Stack Underflow n";
return 0;
}
else
{
int d = a[top--];
return d;
}
}
void Stack::isEmpty()
{
if(top < 0) {
cout << "Stack is empty n" }
else {
cout << "Stack is not empty n";
}
}
int main() {
Stack s1;
s1.push(10);
s1.push(100);
}
What is Queue?
 Queue is a linear data structure where the first element is inserted from
one end called REAR and deleted from the other end called as FRONT.
 Front points to the beginning of the queue and Rear points to
the end of the queue.
 Queue follows the FIFO (First - In - First Out) structure.
 According to its FIFO structure, element inserted first will also be
removed first.
 In a queue, one end is always used to insert data (enqueue) and the
other is used to delete data (dequeue), because queue is open at both its ends.
 The enqueue() and dequeue() are two important functions used in a
queue.
Operations on Queue
Following are the basic operations performed on a Queue.
Operations Description
enqueue() This function defines the operation for adding an element into queue.
dequeue() This function defines the operation for removing an element from queue.
init() This function is used for initializing the queue.
Front Front is used to get the front data item from a queue.
Rear Rear is used to get the last item from a queue.
Queue Implementation
 Array is the easiest way to implement a queue. Queue can be also
implemented using Linked List or Stack.
 In the above diagram, Front and Rear of the queue point at the first
index of the array. (Array index starts from 0).
 While adding an element into the queue, the Rear keeps on moving
ahead and always points to the position where the next element will be
inserted. Front remains at the first index.
Applications of Queue
Queue, as the name suggests is used whenever we need to manage any group of
objects in an order in which the first one coming in, also gets out first while the
others wait for their turn, like in the following scenarios:
1. Serving requests on a single shared resource, like a printer, CPU task
scheduling etc.
2. In real life scenario, Call Center phone systems uses Queues to hold people
calling them in an order, until a service representative is free.
3. Handling of interrupts in real-time systems. The interrupts are handled in the
same order as they arrive i.e First come first served.
#include<iostream>
#define SIZE 10
class Queue
{
int a[SIZE];
int rear; //same as tail
int front; //same as head
public:
Queue()
{
rear = front = -1;
}
void enqueue(int x);
int dequeue();
void display();
};
void Queue :: enqueue(int x)
{
if(front == -1) { front++; }
if( rear == SIZE-1)
{
cout << "Queue is full";
}
else {
a[++rear] = x;
} }
int Queue :: dequeue()
{
return a[++front ;
}
void Queue :: display()
{
int i;
for( i = front; i <= rear; i++)
{ cout << a[i] << endl; }
}
void main()
{
Queue q;
q.enqueue(10);
q.enqueue(100);
q.enqueue(1000);
q.enqueue(1001);
q.enqueue(1002);
q.dequeue();
q.enqueue(1003);
q.dequeue();
q.dequeue();
q.enqueue(1004);
q.display();
}
To implement approach, you simply need to change the dequeue method, and
include a for loop which will shift all the remaining elements by one position.
returna[0]; //returningfirst element
for (i = 0; i < tail-1;i++) //shiftingall otherelements
{
a[i] = a[i+1];
tail--;
}
Applications:
Printing a page in printer
1) When a resource is shared among multiple consumers. Examples include CPU
scheduling, Disk Scheduling.
2) When data is transferred asynchronously (data not necessarily received at same
rate as sent) between two processes. Examples include IO Buffers, pipes, file IO,
etc.

More Related Content

What's hot

What's hot (20)

Array in c++
Array in c++Array in c++
Array in c++
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
Red black tree
Red black treeRed black tree
Red black tree
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Array ppt
Array pptArray ppt
Array ppt
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
stack & queue
stack & queuestack & queue
stack & queue
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Hashing
HashingHashing
Hashing
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 

Similar to Data Structure

chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptxselemonGamo
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxSaralaT3
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxsarala9
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxmexiuro901
 
Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Tutort Academy
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data StructureJazz Jinia Bhowmik
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptyarotos643
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.pptSeethaDinesh
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testspriyanshukumar97908
 
Data structures Lecture no. 2
Data structures Lecture no. 2Data structures Lecture no. 2
Data structures Lecture no. 2AzharIqbal710687
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxUsriDevi1
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)SURBHI SAROHA
 

Similar to Data Structure (20)

chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
Intro ds
Intro dsIntro ds
Intro ds
 
UNITIII LDS.pdf
UNITIII LDS.pdfUNITIII LDS.pdf
UNITIII LDS.pdf
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
1597380885789.ppt
1597380885789.ppt1597380885789.ppt
1597380885789.ppt
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
 
Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
Data structures Lecture no. 2
Data structures Lecture no. 2Data structures Lecture no. 2
Data structures Lecture no. 2
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
 
intr_ds.ppt
intr_ds.pptintr_ds.ppt
intr_ds.ppt
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Data Structure

  • 1. What is Data Structure?  Data structure is an arrangement of data in computer's memory. It makes the data quickly available to the processor for required operations.  It is a software artifact which allows data to be stored, organized and accessed.  It is a structure program used to store ordered data, so that various operations can be performed on it easily. For example, if we have an employee's data like name 'ABC' and salary 10000. Here, 'ABC' is of String data type and 10000 is of Float data type. We can organize this data as a record like Employee record and collect & store employee's records in a file or database as a data structure like 'ABC' 10000, 'PQR' 15000, 'STU' 5000.  Data structure is about providing data elements in terms of some relationship for better organization and storage.  It is a specialized format for organizing and storing data that can be accessed within appropriate ways. Why is Data Structure important?  Data structure is important because it is used in almost every program or software system.  It helps to write efficient code, structures the code and solve problems.  Data can be maintained more easily by encouraging a better design or implementation.  Data structure is just a container for the data that is used to store, manipulate and arrange. It can be processed by algorithms. For example, while using a shopping website like Flipkart or Amazon, the users know their last orders and can track them. The orders are stored in a database as records. However, when the program needs them so that it can pass the data
  • 2. somewhere else (such as to a warehouse) or display it to the user, it loads the data in some form of data structure. Types of Data Structure A. Primitive Data Type  Primitive data types are the data types available in most of the programming languages.  These data types are used to represent single value.  It is a basic data type available in most of the programming language. Data type Description Integer Used to represent a number without decimal point. Float Used to represent a number with decimal point. Character Used to represent single character. Boolean Used to represent logical values either true or false.
  • 3. B. Non-Primitive Data Type  Data type derived from primary data types are known as Non-Primitive data types.  Non-Primitive data types are used to store group of values.  It can be divided into two types: 1. Linear Data Structure 2. Non-Linear Data Structure 1. Linear Data Structure Linear data structure traverses the data elements sequentially.  In linear data structure, only one data element can directly be reached.  It includes array, linked list, stack and queues.  Types Description Arrays Array is a collection of elements. It is used in mathematical problems like matrix, algebra etc. each element of an array is referenced by a subscripted variable or value, called subscript or index enclosed in parenthesis. Linked list Linked list is a collection of data elements. It consists of two parts: Info and Link. Info gives information and Link is an address of next node. Linked list can be implemented by using pointers. Stack Stack is a list of elements. In stack, an element may be inserted or deleted at one end which is known as Top of the stack. It performs two operations: Push and Pop. Push means adding an element in stack and Pop means removing an element in stack. It is also called Last-in-First- out (LIFO). Queue Queue is a linear list of element. In queue, elements are added at one end called rear and the existing elements are deleted from other end called front. It is also called as First-in-First-out (FIFO).
  • 4. 2. Non-Linear Data Structure  Non-Linear data structure is opposite to linear data structure.  In non-linear data structure, the data values are not arranged in order and a data item is connected to several other data items.  It uses memory efficiently. Free contiguous memory is not required for allocating data items.  It includes trees and graphs. Type Description Tree Tree is a flexible, versatile and powerful non-linear data structure. It is used to represent data items processing hierarchical relationship between the grandfather and his children & grandchildren. It is an ideal data structure for representing hierarchical data. Graph Graph is a non-linear data structure which consists of a finite set of ordered pairs called edges. Graph is a set of elements connected by edges. Each elements are called a vertex and node. Abstract Data type (ADT) What is ADT?  ADT stands for Abstract Data Type.  It is an abstraction of a data structure.  Abstract data type is a mathematical model of a data structure.  It describes a container which holds a finite number of objects where the objects may be associated through a given binary relationship.  It is a logical description of how we view the data and the operations allowed without regard to how they will be implemented.  ADT concerns only with what the data is representing and not with how it will eventually be constructed.  It is a set of objects and operations. For example, List, Insert, Delete, Search, Sort.
  • 5. It consists offollowing three parts: 1. Data 2. Operation 3. Error 1. Data describes the structure of the data used in the ADT. 2. Operationdescribes valid operations for the ADT. It describes its interface. 3. Error describes how to deal with the errors that can occur. Advantages of ADT  ADT is reusable and ensures robust data structure.  It reduces coding efforts.  Encapsulation ensures that data cannot be corrupted.  ADT is based on principles of Object Oriented Programming (OOP) and Software Engineering (SE).  It specifies error conditions associated with operations. What is Stack?  Stack is an ordered list of the same type of elements.  It is a linear list where all insertions and deletions are permitted only at one end of the list.  Stack is a LIFO (Last In First Out) structure.  In a stack, when an element is added, it goes to the top of the stack. Definition “Stack is a collection of similar data items in which both insertion and deletion operations are performed based on LIFO principle”. There are two basic operations performed in a Stack: 1. Push() function is used to add or insert new elements into the stack.
  • 6. 2. Pop() function is used to delete or remove an element from the stack.  When a stack is completely full, it is said to be Overflow state and if stack is completely empty, it is said to be Underflow state.  Stack allows operations at one end only. Stack behaves like a real life stack, for example, in a real life, we can remove a plate or dish from the top of the stack only or while playing a deck of cards, we can place or remove a card from top of the stack only. Similarly, here also, we can only access the top element of a stack.  According to its LIFO structure, the element which is inserted last, is accessed first. Implementation of Stack The above diagram represents a stack insertion operation. In a stack, inserting and deleting of elements are performed at a single position which is known as, Top. Insertion operation can be performed using Push() function. New element is added at top of the stack and removed from top of the stack, as shown in the diagram below:
  • 7. An element is removed from top of the stack. Delete operation is based on LIFO principle. This operation is performed using a Pop() function. It means that the insertion and deletion operations are performed at one end i.e at Top. Following table shows the Position of Top which indicates the status of stack: Position of Top Status of Stack -1 Stack is empty. 0 Only one element in a stack. N - 1 Stack is full. N Stack is overflow. (Overflow state) Applications of Stack The simplest application of a stack is to reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack. There are other uses also like: 1. Parsing 2. Expression Conversion(Infix to Postfix, Postfix to Prefix etc)
  • 8. * Below program is written in C++ language */ # include<iostream> class Stack { int top; public: int a[10]; //Maximum size of Stack Stack() { top = -1; } void push(int x); int pop(); void isEmpty(); }; void Stack::push(int x) { if(top >= 10) { cout << "Stack Overflow n"; } else { a[++top] = x; cout << "Element Inserted n"; } } int Stack::pop() { if(top < 0) { cout << "Stack Underflow n"; return 0; } else { int d = a[top--]; return d; } } void Stack::isEmpty() { if(top < 0) { cout << "Stack is empty n" } else { cout << "Stack is not empty n"; } } int main() { Stack s1; s1.push(10); s1.push(100); }
  • 9. What is Queue?  Queue is a linear data structure where the first element is inserted from one end called REAR and deleted from the other end called as FRONT.  Front points to the beginning of the queue and Rear points to the end of the queue.  Queue follows the FIFO (First - In - First Out) structure.  According to its FIFO structure, element inserted first will also be removed first.  In a queue, one end is always used to insert data (enqueue) and the other is used to delete data (dequeue), because queue is open at both its ends.  The enqueue() and dequeue() are two important functions used in a queue. Operations on Queue Following are the basic operations performed on a Queue. Operations Description enqueue() This function defines the operation for adding an element into queue. dequeue() This function defines the operation for removing an element from queue. init() This function is used for initializing the queue. Front Front is used to get the front data item from a queue. Rear Rear is used to get the last item from a queue.
  • 10. Queue Implementation  Array is the easiest way to implement a queue. Queue can be also implemented using Linked List or Stack.  In the above diagram, Front and Rear of the queue point at the first index of the array. (Array index starts from 0).  While adding an element into the queue, the Rear keeps on moving ahead and always points to the position where the next element will be inserted. Front remains at the first index. Applications of Queue Queue, as the name suggests is used whenever we need to manage any group of objects in an order in which the first one coming in, also gets out first while the others wait for their turn, like in the following scenarios: 1. Serving requests on a single shared resource, like a printer, CPU task scheduling etc. 2. In real life scenario, Call Center phone systems uses Queues to hold people calling them in an order, until a service representative is free. 3. Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive i.e First come first served.
  • 11. #include<iostream> #define SIZE 10 class Queue { int a[SIZE]; int rear; //same as tail int front; //same as head public: Queue() { rear = front = -1; } void enqueue(int x); int dequeue(); void display(); }; void Queue :: enqueue(int x) { if(front == -1) { front++; } if( rear == SIZE-1) { cout << "Queue is full"; } else { a[++rear] = x; } } int Queue :: dequeue() { return a[++front ; } void Queue :: display() { int i; for( i = front; i <= rear; i++) { cout << a[i] << endl; } } void main() { Queue q; q.enqueue(10); q.enqueue(100); q.enqueue(1000); q.enqueue(1001); q.enqueue(1002); q.dequeue(); q.enqueue(1003); q.dequeue(); q.dequeue(); q.enqueue(1004); q.display(); }
  • 12. To implement approach, you simply need to change the dequeue method, and include a for loop which will shift all the remaining elements by one position. returna[0]; //returningfirst element for (i = 0; i < tail-1;i++) //shiftingall otherelements { a[i] = a[i+1]; tail--; } Applications: Printing a page in printer 1) When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk Scheduling. 2) When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes. Examples include IO Buffers, pipes, file IO, etc.