SlideShare a Scribd company logo
Segment Tree 
1
Presented BY: 
 Shohanur Rahman 
 ID# 1321368042 
 CSE 225 (Data Structure) 
 North South University 
 Email: shohan.nsu.cse@gmail.com 
2
Segment Tree 
Definition: 
In computer science, a segment tree is 
a tree data structure for storing intervals, 
or segments. It allows querying which of 
the stored segments contain a given point. 
It can be implemented as a 
dynamic structure. 
3
Segment Trees 
4
Sample Problem: 
 You are given n (1<=n<=100000) integers 
& 100000 query. Each query you have to 
change a value of an element Or you 
have to given the minimum value of a 
range. 
5
Function Of segment Tree 
6
Initial Functions: 
We start with a segment arr[1 . . . n]. 
and every time we divide the current 
segment into two halves(if it has not yet 
become a segment of length 1), and then 
call the same procedure on both halves, 
and for each such segment we store the 
sum in corresponding node. 
7
Initial Functions:
Initial Functions( in tree look): 
9
Initial Functions(Algorithm): 
#define mx 100001 
int arr[mx]; 
int tree[mx*3]; 
void init(int node,int b,int e) 
{ 
if(b==e) 
{ 
tree[node]=arr[b]; 
return; 
} 
int Left=node*2; 
int Right=node*2+1; 
int mid=(b+e)/2; 
init(Left,b,mid); 
init(Right,mid+1,e); 
tree[node]=tree[Left]+tree[Right]; 
} 10
Query Functions: 
11
Query Functions: 
 Once the tree is initialized, how to get 
the sum using the initialized segment 
tree.Now,we use Query function.Here 3 
types of cases can be happening. 
12
Query Functions: 
13
Query Functions: 
case A: 
if(b>=i&&e<=j);then the segment is :Releavent 
segment. 
case B: 
if (i > e || j < b);means current segment is 
outside of i-j,then its valuless. 
case C: 
if case A and case B are not true and some of 
the parts is included in i-j , then we need to 
break the segment and take some of the parts. 
14
Query Functions(Algorithm): 
int query(int node,int b,int e,int i,int j) 
{ 
if (i > e || j < b) return 0; 
if (b >= i && e <= j) return tree[node]; 
int Left=node*2; 
int Right=node*2+1; 
int mid=(b+e)/2; 
int p1=query(Left,b,mid,i,j); 
int p2=query(Right,mid+1,e,i,j); 
return p1+p2; 
} 
15
Update Function: 
 Like tree initialization and query operations, 
update can also be done recursively. We are 
given an index which needs to update. 
Let new value be the value to be added. We 
start from root of the segment tree, and 
add new value to all nodes which have given 
index in their range. If a node doesn’t have 
given index in its range, we don’t make any 
changes to that node. 
16
Update Function: 
17
Update Function(Algorithm): 
void update(int node,int b,int e,int i,int newvalue) { 
if (i > e || i < b) return; 
if (b >= i && e <= i) { 
tree[node]=newvalue; 
return; 
} 
int Left=node*2; 
int Right=node*2+1; 
int mid=(b+e)/2; 
update(Left,b,mid,i,newvalue); 
update(Right,mid+1,e,i,newvalue); 
tree[node]=tree[Left]+tree[Right]; 
} 18
Time Complexity: 
Function Name: Time: 
1.Initial Function O(n log n) 
2.Query Function O(log n) 
3.Update Function O(log n) 
19
Applications: 
 Using segment trees we get an <O(N), 
O(log N)> algorithm. Segment trees are 
very powerful, not only because they can be 
used for RMQ(Range Minimum Query). They 
are a very flexible data structure, can 
solve even the dynamic version of RMQ 
problem, and have numerous applications in 
range searching problems. 
20
21
Time to run code…….. 
22
Thank You ! 
23

More Related Content

What's hot

Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
V.V.Vanniapermal College for Women
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
Adbms 38 algorithms for select and join operations
Adbms 38 algorithms for select and join operationsAdbms 38 algorithms for select and join operations
Adbms 38 algorithms for select and join operations
Vaibhav Khanna
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
Afaq Mansoor Khan
 
Queue
QueueQueue
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
Vrushali Dhanokar
 
Stack and Queue
Stack and QueueStack and Queue
Stack and Queue
Selvaraj Seerangan
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Essential NumPy
Essential NumPyEssential NumPy
Essential NumPy
zekeLabs Technologies
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
Digvijay Singh Karakoti
 
Data structure tries
Data structure triesData structure tries
Data structure tries
Md. Naim khan
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back tracking
Abinaya B
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
Core Condor
 
Heap
HeapHeap
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
Vardhil Patel
 

What's hot (20)

Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
Binary tree
Binary treeBinary tree
Binary tree
 
Adbms 38 algorithms for select and join operations
Adbms 38 algorithms for select and join operationsAdbms 38 algorithms for select and join operations
Adbms 38 algorithms for select and join operations
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Queue
QueueQueue
Queue
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
 
Stack and Queue
Stack and QueueStack and Queue
Stack and Queue
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Essential NumPy
Essential NumPyEssential NumPy
Essential NumPy
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Data structure tries
Data structure triesData structure tries
Data structure tries
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back tracking
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Heap
HeapHeap
Heap
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 

Viewers also liked

Segment tree
Segment treeSegment tree
Segment tree
Shakil Ahmed
 
Introduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt ControllerIntroduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt Controller
The Linux Foundation
 
Dynamic DFS in Undirected Graph using Segment Tree
Dynamic DFS in Undirected Graph using Segment TreeDynamic DFS in Undirected Graph using Segment Tree
Dynamic DFS in Undirected Graph using Segment Tree
Siraj Memon
 
TripleTree eDiscovery
TripleTree  eDiscoveryTripleTree  eDiscovery
TripleTree eDiscovery
Chris Hoffmann
 
K d tree_cpp
K d tree_cppK d tree_cpp
K d tree_cpp
Russell Childs
 
Priority Lands September 25 2008
Priority Lands September 25 2008Priority Lands September 25 2008
Priority Lands September 25 2008
ecopatriot80
 
Ch15 Heap
Ch15 HeapCh15 Heap
Ch15 Heap
leminhvuong
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
ashish bansal
 
A Parallel Data Distribution Management Algorithm
A Parallel Data Distribution Management AlgorithmA Parallel Data Distribution Management Algorithm
A Parallel Data Distribution Management Algorithm
Gabriele D'Angelo
 
Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )
Alp Çoker
 
STP
STPSTP
STP
wyousif
 
数据结构回顾
数据结构回顾数据结构回顾
数据结构回顾
Zehua HONG
 
TRIES_data_structure
TRIES_data_structureTRIES_data_structure
TRIES_data_structure
ddewithaman10
 
23 priority queue
23 priority queue23 priority queue
23 priority queue
Godo Dodo
 
Spanning Tree Bridge Root Priority value & Extended System ID
Spanning Tree Bridge Root Priority value & Extended System IDSpanning Tree Bridge Root Priority value & Extended System ID
Spanning Tree Bridge Root Priority value & Extended System ID
NetProtocol Xpert
 
Splay Tree
Splay TreeSplay Tree
Industry segments
Industry segmentsIndustry segments
Industry segments
meenakshi sv
 
brand building and service marketing at banyan tree hotels and resorts
brand building and service marketing at banyan tree hotels and resortsbrand building and service marketing at banyan tree hotels and resorts
brand building and service marketing at banyan tree hotels and resorts
saurabh
 
B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
Shakil Ahmed
 
ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...
ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...
ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...Myagaa_1987
 

Viewers also liked (20)

Segment tree
Segment treeSegment tree
Segment tree
 
Introduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt ControllerIntroduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt Controller
 
Dynamic DFS in Undirected Graph using Segment Tree
Dynamic DFS in Undirected Graph using Segment TreeDynamic DFS in Undirected Graph using Segment Tree
Dynamic DFS in Undirected Graph using Segment Tree
 
TripleTree eDiscovery
TripleTree  eDiscoveryTripleTree  eDiscovery
TripleTree eDiscovery
 
K d tree_cpp
K d tree_cppK d tree_cpp
K d tree_cpp
 
Priority Lands September 25 2008
Priority Lands September 25 2008Priority Lands September 25 2008
Priority Lands September 25 2008
 
Ch15 Heap
Ch15 HeapCh15 Heap
Ch15 Heap
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
A Parallel Data Distribution Management Algorithm
A Parallel Data Distribution Management AlgorithmA Parallel Data Distribution Management Algorithm
A Parallel Data Distribution Management Algorithm
 
Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )
 
STP
STPSTP
STP
 
数据结构回顾
数据结构回顾数据结构回顾
数据结构回顾
 
TRIES_data_structure
TRIES_data_structureTRIES_data_structure
TRIES_data_structure
 
23 priority queue
23 priority queue23 priority queue
23 priority queue
 
Spanning Tree Bridge Root Priority value & Extended System ID
Spanning Tree Bridge Root Priority value & Extended System IDSpanning Tree Bridge Root Priority value & Extended System ID
Spanning Tree Bridge Root Priority value & Extended System ID
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Industry segments
Industry segmentsIndustry segments
Industry segments
 
brand building and service marketing at banyan tree hotels and resorts
brand building and service marketing at banyan tree hotels and resortsbrand building and service marketing at banyan tree hotels and resorts
brand building and service marketing at banyan tree hotels and resorts
 
B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
 
ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...
ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...
ерөнхий боловсролын сургуулийн багшийн ажлыг төлөвлөх,үнэлэх,дүгнэхэд баримтл...
 

Similar to Segment tree

Segment Tree
Segment TreeSegment Tree
Segment Tree
Shohanur Rahman
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
K Hari Shankar
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
GOKULKANNANMMECLECTC
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Priyanka Rana
 
E2
E2E2
E2
lksoo
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
UmarMustafa13
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
Intro C# Book
 
Virtusa questions placement preparation guide
Virtusa questions placement preparation guideVirtusa questions placement preparation guide
Virtusa questions placement preparation guide
ThalaAjith33
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy
 
Lo27
Lo27Lo27
Lo27
lksoo
 
05
0505
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
Emertxe Information Technologies Pvt Ltd
 
ARRAY in python and c with examples .pptx
ARRAY  in python and c with examples .pptxARRAY  in python and c with examples .pptx
ARRAY in python and c with examples .pptx
abhishekmaurya102515
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
Mohamed Ahmed
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
BG Java EE Course
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 

Similar to Segment tree (20)

Segment Tree
Segment TreeSegment Tree
Segment Tree
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
E2
E2E2
E2
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
Virtusa questions placement preparation guide
Virtusa questions placement preparation guideVirtusa questions placement preparation guide
Virtusa questions placement preparation guide
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Lo27
Lo27Lo27
Lo27
 
05
0505
05
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
ARRAY in python and c with examples .pptx
ARRAY  in python and c with examples .pptxARRAY  in python and c with examples .pptx
ARRAY in python and c with examples .pptx
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 

Recently uploaded

ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 

Recently uploaded (20)

ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 

Segment tree

  • 2. Presented BY:  Shohanur Rahman  ID# 1321368042  CSE 225 (Data Structure)  North South University  Email: shohan.nsu.cse@gmail.com 2
  • 3. Segment Tree Definition: In computer science, a segment tree is a tree data structure for storing intervals, or segments. It allows querying which of the stored segments contain a given point. It can be implemented as a dynamic structure. 3
  • 5. Sample Problem:  You are given n (1<=n<=100000) integers & 100000 query. Each query you have to change a value of an element Or you have to given the minimum value of a range. 5
  • 7. Initial Functions: We start with a segment arr[1 . . . n]. and every time we divide the current segment into two halves(if it has not yet become a segment of length 1), and then call the same procedure on both halves, and for each such segment we store the sum in corresponding node. 7
  • 9. Initial Functions( in tree look): 9
  • 10. Initial Functions(Algorithm): #define mx 100001 int arr[mx]; int tree[mx*3]; void init(int node,int b,int e) { if(b==e) { tree[node]=arr[b]; return; } int Left=node*2; int Right=node*2+1; int mid=(b+e)/2; init(Left,b,mid); init(Right,mid+1,e); tree[node]=tree[Left]+tree[Right]; } 10
  • 12. Query Functions:  Once the tree is initialized, how to get the sum using the initialized segment tree.Now,we use Query function.Here 3 types of cases can be happening. 12
  • 14. Query Functions: case A: if(b>=i&&e<=j);then the segment is :Releavent segment. case B: if (i > e || j < b);means current segment is outside of i-j,then its valuless. case C: if case A and case B are not true and some of the parts is included in i-j , then we need to break the segment and take some of the parts. 14
  • 15. Query Functions(Algorithm): int query(int node,int b,int e,int i,int j) { if (i > e || j < b) return 0; if (b >= i && e <= j) return tree[node]; int Left=node*2; int Right=node*2+1; int mid=(b+e)/2; int p1=query(Left,b,mid,i,j); int p2=query(Right,mid+1,e,i,j); return p1+p2; } 15
  • 16. Update Function:  Like tree initialization and query operations, update can also be done recursively. We are given an index which needs to update. Let new value be the value to be added. We start from root of the segment tree, and add new value to all nodes which have given index in their range. If a node doesn’t have given index in its range, we don’t make any changes to that node. 16
  • 18. Update Function(Algorithm): void update(int node,int b,int e,int i,int newvalue) { if (i > e || i < b) return; if (b >= i && e <= i) { tree[node]=newvalue; return; } int Left=node*2; int Right=node*2+1; int mid=(b+e)/2; update(Left,b,mid,i,newvalue); update(Right,mid+1,e,i,newvalue); tree[node]=tree[Left]+tree[Right]; } 18
  • 19. Time Complexity: Function Name: Time: 1.Initial Function O(n log n) 2.Query Function O(log n) 3.Update Function O(log n) 19
  • 20. Applications:  Using segment trees we get an <O(N), O(log N)> algorithm. Segment trees are very powerful, not only because they can be used for RMQ(Range Minimum Query). They are a very flexible data structure, can solve even the dynamic version of RMQ problem, and have numerous applications in range searching problems. 20
  • 21. 21
  • 22. Time to run code…….. 22