SlideShare a Scribd company logo
Assignment On Data Structure
Nowrin Islam Nishat
ID: 193-35-483
Dept. Of Software Engineering
Mr. S A M Matiur Rahman
Associate Professor and Associate Head
Department of Software Engineering
Daffodil International University
[Queue , Linked List , Tree]
Submitted By : Submitted To :
N-!-s-h-a-t
19-08-2020 1
Queue
A Queue is a linear structure which follows a particular order in which the operations are
performed. The order is First In First Out (FIFO). A good example of a queue is any queue of
consumers for a resource where the consumer that came first is served first. The difference
between stacks and queues is in removing. In a stack we remove the item the most recently
added; in a queue, we remove the item the least recently added.
[NOTE] :
The process to add an element into queue is called Enqueue and the
process of removal of an element from queue is called Dequeue.
N-!-s-h-a-t
19-08-2020
2
Basic features of Queue
1. Like stack, queue is also an ordered list of elements of similar data
types.
2. Queue is a FIFO( First in First Out ) structure.
3. Once a new element is inserted into the Queue, all the elements
inserted before the new element in the queue must be removed, to
remove the new element.
4. peek( ) function is oftenly used to return the value of first element
without dequeuing it
N-!-s-h-a-t
19-08-2020
3
Application 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 system uses queues to hold people calling them in
an order until a service representive in free.
3. Handling of interrupts in real time systems.
N-!-s-h-a-t
19-08-2020
4
Queue can be implemented using an Array, Stack or Linked List.
The easiest way of implementing a queue is by using an Array.
Initially the head(FRONT) and the tail(REAR) of the queue points at
the first index of the array (starting the index of array from 0). As we
add elements to the queue, the tail keeps on moving ahead, always
pointing to the position where the next element will be inserted,
while the head remains at the first index.
Implementation of Queue Data Structure
When we remove an element from Queue, we can follow
two possible approaches (mentioned [A] and [B] in above
diagram). In [A] approach, we remove the element
at head position, and then one by one shift all the other
elements in forward position.
In approach [B] we remove the element from head position
and then move head to the next position.
In approach [A] there is an overhead of shifting the
elements one position forward every time we remove the
first element.
In approach [B] there is no such overhead, but whenever we
move head one position ahead, after removal of first
element, the size on Queue is reduced by one space each
time. N-!-s-h-a-t
19-08-2020
5
Algorithm for ENQUEUE operation
1. Check if the queue is full or not.
2. If the queue is full, then print overflow error and exit the program.
3. If the queue is not full, then increment the tail and add the element.
Algorithm for DEQUEUE operation
1. Check if the queue is empty or not.
2. If the queue is empty, then print underflow error and exit the program.
3. If the queue is not empty, then print the element at the head and increment
the head.
Complexity Analysis of Queue Operations
Just like Stack, in case of a Queue too, we know exactly, on which position new element will be
added and from where an element will be removed, hence both these operations requires a single
step.
> Enqueue: O(1)
> Dequeue: O(1)
> Size: O(1)
N-!-s-h-a-t
19-08-2020
6
Linked List
Linked List is a very commonly used linear data structure which consists of group of nodes in a
sequence.
Each node holds its own data and the address of the next node hence forming a chain like
structure.
Linked Lists are used to create trees and graphs.
N-!-s-h-a-t
19-08-2020
7
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.
N-!-s-h-a-t
19-08-2020
8
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 Lists
There are 3 different implementations of Linked List available, they are:
1.Singly Linked List
2.Doubly Linked List
3.Circular Linked List
Let's know more about them and how they are different from each other.
N-!-s-h-a-t
19-08-2020
9
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 the sequence of nodes.
The operations we can perform on singly linked lists
are insertion, deletion and traversal.
Singly Linked List
Doubly Linked List
In a doubly linked list, each node contains a data part and two
addresses, one for the previous node and one for the next node.
Circular Linked List
In circular linked list the last node of the list holds the address of the
first node hence forming a circular chain.
N-!-s-h-a-t
19-08-2020 10
Tree
A binary tree is a hierarchical data structure in which each node has at most two children generally referred as
left child and right child.
Each node contains three components:
1. Pointer to left subtree
2. Pointer to right subtree
3. Data element
The topmost node in the tree is called the root. An empty tree is represented by NULL pointer.
A representation of binary tree is shown:
N-!-s-h-a-t
19-08-2020
11
Common Terminologies
•Root: Topmost node in a tree.
•Parent: Every node (excluding a root) in a tree is connected by a directed edge from
exactly one other node. This node is called a parent.
•Child: A node directly connected to another node when moving away from the root.
•Leaf/External node: Node with no children.
•Internal node: Node with atleast one children.
•Depth of a node: Number of edges from root to the node.
•Height of a node: Number of edges from the node to the deepest leaf. Height of the tree
is the height of the root.
In the above binary tree we see that root node is A.
The tree has 10 nodes with 5 internal nodes,
i.e, A,B,C,E,G and 5 external nodes, i.e, D,F,H,I,J. The
height of the tree is 3. B is the parent
of D and E while D and E are children of B.
N-!-s-h-a-t
19-08-2020
12
Advantages of Trees
Trees are so useful and frequently used, because they have some very serious advantages:
•Trees reflect structural relationships in the data.
•Trees are used to represent hierarchies.
•Trees provide an efficient insertion and searching.
•Trees are very flexible data, allowing to move subtrees around with minumum effort.
Types of Trees (Based on Structure)
Rooted binary tree: It has a root node and every node has atmost two children.
Full binary tree: It is a tree in which every node in the
tree has either 0 or 2 children.
•The number of nodes, n, in a full binary tree is atleast n =
2h – 1, and atmost n = 2h+1 – 1, where h is the height of
the tree.
•The number of leaf nodes l, in a full binary tree is
number, L of internal nodes + 1, i.e, l = L+1.
N-!-s-h-a-t
19-08-2020
13
Perfect binary tree: It is a binary tree in which all interior nodes have two children and all leaves have the
same depth or same level.
•A perfect binary tree with l leaves has n =
2l-1 nodes.
•In perfect full binary tree, l = 2h and n =
2h+1 - 1 where, n is number of nodes, h is
height of tree and l is number of leaf nodes
Complete binary tree: It is a binary tree in which every level, except possibly the last, is completely filled, and
all nodes are as far left as possible.
The number of internal nodes in a
complete binary tree of n nodes
is floor(n/2).
N-!-s-h-a-t
19-08-2020 14
Balanced binary tree: A binary tree is height balanced if it satisfies the following constraints:
1.The left and right subtrees' heights differ by at most one, AND
2.The left subtree is balanced, AND
3.The right subtree is balanced
An empty tree is height balanced.
The height of a balanced binary
tree is O(Log n) where n is
number of nodes.
N-!-s-h-a-t
19-08-2020 15
Degenarate tree: It is a tree is where each parent node has only one child
node. It behaves like a linked list.
N-!-s-h-a-t
19-08-2020
16
N-!-s-h-a-t
19-08-2020
17
Ad

More Related Content

What's hot (20)

data structures and algorithms Unit 1
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1
infanciaj
 
Ii pu cs practical viva voce questions
Ii pu cs  practical viva voce questionsIi pu cs  practical viva voce questions
Ii pu cs practical viva voce questions
Prof. Dr. K. Adisesha
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
Zaid Shabbir
 
Ds important questions
Ds important questionsDs important questions
Ds important questions
LavanyaJ28
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
LavanyaJ28
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
LavanyaJ28
 
Data Structures
Data StructuresData Structures
Data Structures
Nitesh Bichwani
 
Data structure
Data structureData structure
Data structure
Prof. Dr. K. Adisesha
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
adeel hamid
 
Types Of Data Structure
Types Of Data StructureTypes Of Data Structure
Types Of Data Structure
Vaishali Chinchkhede
 
Data structure
 Data structure Data structure
Data structure
Shahariar limon
 
Unit 2 linked list
Unit 2   linked listUnit 2   linked list
Unit 2 linked list
DrkhanchanaR
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data Structure
Mandavi Classes
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
lavparmar007
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
Mahmoud Alfarra
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Hassan Ahmed
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
Aakash deep Singhal
 
Tree
TreeTree
Tree
Timothy Pastoral
 
Data structure
Data structureData structure
Data structure
laraib kafeel
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
NUPOORAWSARMOL
 
data structures and algorithms Unit 1
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1
infanciaj
 
Ii pu cs practical viva voce questions
Ii pu cs  practical viva voce questionsIi pu cs  practical viva voce questions
Ii pu cs practical viva voce questions
Prof. Dr. K. Adisesha
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
Zaid Shabbir
 
Ds important questions
Ds important questionsDs important questions
Ds important questions
LavanyaJ28
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
LavanyaJ28
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
LavanyaJ28
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
adeel hamid
 
Unit 2 linked list
Unit 2   linked listUnit 2   linked list
Unit 2 linked list
DrkhanchanaR
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data Structure
Mandavi Classes
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
lavparmar007
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
Mahmoud Alfarra
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Hassan Ahmed
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
Aakash deep Singhal
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
NUPOORAWSARMOL
 

Similar to [Queue , linked list , tree] (20)

4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
SSE_AndyLi
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
BlueSwede
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
Jabs6
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
SeethaDinesh
 
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
priyanshukumar97908
 
Linked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptxLinked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptx
AAUsH2
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)
Dr. SURBHI SAROHA
 
Data Structure Lecture 3 Linked Lists.pdf
Data Structure Lecture 3 Linked Lists.pdfData Structure Lecture 3 Linked Lists.pdf
Data Structure Lecture 3 Linked Lists.pdf
donotreply20
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
selemonGamo
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Data Structure
Data StructureData Structure
Data Structure
HarshGupta663
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
irshad17
 
Data structures notes
Data structures notesData structures notes
Data structures notes
Upasana Talukdar
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
raji175286
 
CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111
kannanmeenu602
 
Data Structure
Data Structure Data Structure
Data Structure
Ibrahim MH
 
Data Structures Introduction & Linear DS
Data Structures Introduction & Linear DSData Structures Introduction & Linear DS
Data Structures Introduction & Linear DS
sailaja156145
 
Data Structure
Data StructureData Structure
Data Structure
Karthikeyan A K
 
Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02
Getachew Ganfur
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
SSE_AndyLi
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
BlueSwede
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
Jabs6
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
SeethaDinesh
 
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
priyanshukumar97908
 
Linked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptxLinked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptx
AAUsH2
 
Data Structure Lecture 3 Linked Lists.pdf
Data Structure Lecture 3 Linked Lists.pdfData Structure Lecture 3 Linked Lists.pdf
Data Structure Lecture 3 Linked Lists.pdf
donotreply20
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
selemonGamo
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
irshad17
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
raji175286
 
CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111
kannanmeenu602
 
Data Structure
Data Structure Data Structure
Data Structure
Ibrahim MH
 
Data Structures Introduction & Linear DS
Data Structures Introduction & Linear DSData Structures Introduction & Linear DS
Data Structures Introduction & Linear DS
sailaja156145
 
Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02
Getachew Ganfur
 
Ad

Recently uploaded (20)

Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
Reflections on Morality, Philosophy, and History
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Ad

[Queue , linked list , tree]

  • 1. Assignment On Data Structure Nowrin Islam Nishat ID: 193-35-483 Dept. Of Software Engineering Mr. S A M Matiur Rahman Associate Professor and Associate Head Department of Software Engineering Daffodil International University [Queue , Linked List , Tree] Submitted By : Submitted To : N-!-s-h-a-t 19-08-2020 1
  • 2. Queue A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first. The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. [NOTE] : The process to add an element into queue is called Enqueue and the process of removal of an element from queue is called Dequeue. N-!-s-h-a-t 19-08-2020 2
  • 3. Basic features of Queue 1. Like stack, queue is also an ordered list of elements of similar data types. 2. Queue is a FIFO( First in First Out ) structure. 3. Once a new element is inserted into the Queue, all the elements inserted before the new element in the queue must be removed, to remove the new element. 4. peek( ) function is oftenly used to return the value of first element without dequeuing it N-!-s-h-a-t 19-08-2020 3
  • 4. Application 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 system uses queues to hold people calling them in an order until a service representive in free. 3. Handling of interrupts in real time systems. N-!-s-h-a-t 19-08-2020 4
  • 5. Queue can be implemented using an Array, Stack or Linked List. The easiest way of implementing a queue is by using an Array. Initially the head(FRONT) and the tail(REAR) of the queue points at the first index of the array (starting the index of array from 0). As we add elements to the queue, the tail keeps on moving ahead, always pointing to the position where the next element will be inserted, while the head remains at the first index. Implementation of Queue Data Structure When we remove an element from Queue, we can follow two possible approaches (mentioned [A] and [B] in above diagram). In [A] approach, we remove the element at head position, and then one by one shift all the other elements in forward position. In approach [B] we remove the element from head position and then move head to the next position. In approach [A] there is an overhead of shifting the elements one position forward every time we remove the first element. In approach [B] there is no such overhead, but whenever we move head one position ahead, after removal of first element, the size on Queue is reduced by one space each time. N-!-s-h-a-t 19-08-2020 5
  • 6. Algorithm for ENQUEUE operation 1. Check if the queue is full or not. 2. If the queue is full, then print overflow error and exit the program. 3. If the queue is not full, then increment the tail and add the element. Algorithm for DEQUEUE operation 1. Check if the queue is empty or not. 2. If the queue is empty, then print underflow error and exit the program. 3. If the queue is not empty, then print the element at the head and increment the head. Complexity Analysis of Queue Operations Just like Stack, in case of a Queue too, we know exactly, on which position new element will be added and from where an element will be removed, hence both these operations requires a single step. > Enqueue: O(1) > Dequeue: O(1) > Size: O(1) N-!-s-h-a-t 19-08-2020 6
  • 7. Linked List Linked List is a very commonly used linear data structure which consists of group of nodes in a sequence. Each node holds its own data and the address of the next node hence forming a chain like structure. Linked Lists are used to create trees and graphs. N-!-s-h-a-t 19-08-2020 7
  • 8. 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. N-!-s-h-a-t 19-08-2020 8
  • 9. 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 Lists There are 3 different implementations of Linked List available, they are: 1.Singly Linked List 2.Doubly Linked List 3.Circular Linked List Let's know more about them and how they are different from each other. N-!-s-h-a-t 19-08-2020 9
  • 10. 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 the sequence of nodes. The operations we can perform on singly linked lists are insertion, deletion and traversal. Singly Linked List Doubly Linked List In a doubly linked list, each node contains a data part and two addresses, one for the previous node and one for the next node. Circular Linked List In circular linked list the last node of the list holds the address of the first node hence forming a circular chain. N-!-s-h-a-t 19-08-2020 10
  • 11. Tree A binary tree is a hierarchical data structure in which each node has at most two children generally referred as left child and right child. Each node contains three components: 1. Pointer to left subtree 2. Pointer to right subtree 3. Data element The topmost node in the tree is called the root. An empty tree is represented by NULL pointer. A representation of binary tree is shown: N-!-s-h-a-t 19-08-2020 11
  • 12. Common Terminologies •Root: Topmost node in a tree. •Parent: Every node (excluding a root) in a tree is connected by a directed edge from exactly one other node. This node is called a parent. •Child: A node directly connected to another node when moving away from the root. •Leaf/External node: Node with no children. •Internal node: Node with atleast one children. •Depth of a node: Number of edges from root to the node. •Height of a node: Number of edges from the node to the deepest leaf. Height of the tree is the height of the root. In the above binary tree we see that root node is A. The tree has 10 nodes with 5 internal nodes, i.e, A,B,C,E,G and 5 external nodes, i.e, D,F,H,I,J. The height of the tree is 3. B is the parent of D and E while D and E are children of B. N-!-s-h-a-t 19-08-2020 12
  • 13. Advantages of Trees Trees are so useful and frequently used, because they have some very serious advantages: •Trees reflect structural relationships in the data. •Trees are used to represent hierarchies. •Trees provide an efficient insertion and searching. •Trees are very flexible data, allowing to move subtrees around with minumum effort. Types of Trees (Based on Structure) Rooted binary tree: It has a root node and every node has atmost two children. Full binary tree: It is a tree in which every node in the tree has either 0 or 2 children. •The number of nodes, n, in a full binary tree is atleast n = 2h – 1, and atmost n = 2h+1 – 1, where h is the height of the tree. •The number of leaf nodes l, in a full binary tree is number, L of internal nodes + 1, i.e, l = L+1. N-!-s-h-a-t 19-08-2020 13
  • 14. Perfect binary tree: It is a binary tree in which all interior nodes have two children and all leaves have the same depth or same level. •A perfect binary tree with l leaves has n = 2l-1 nodes. •In perfect full binary tree, l = 2h and n = 2h+1 - 1 where, n is number of nodes, h is height of tree and l is number of leaf nodes Complete binary tree: It is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. The number of internal nodes in a complete binary tree of n nodes is floor(n/2). N-!-s-h-a-t 19-08-2020 14
  • 15. Balanced binary tree: A binary tree is height balanced if it satisfies the following constraints: 1.The left and right subtrees' heights differ by at most one, AND 2.The left subtree is balanced, AND 3.The right subtree is balanced An empty tree is height balanced. The height of a balanced binary tree is O(Log n) where n is number of nodes. N-!-s-h-a-t 19-08-2020 15
  • 16. Degenarate tree: It is a tree is where each parent node has only one child node. It behaves like a linked list. N-!-s-h-a-t 19-08-2020 16
  翻译: