Prerequisite: Segment Tree Implementation
A Segment Tree is a data structure that allows programmers to solve range queries over the given array effectively and to modifying the array values. Basically, Segment Tree is a very flexible and efficient data structure and a large number of problems can be solved with the help of segment trees.
Python Segment tree Module is also used to solve range query problems .It performs various operations in given range like sum , max , min and update value in a range .This modules helps to avoid the implementation of segmentation tree as we can directly use segment tree function for performing all operations.
It generally reduces the stress of implementing the Segment tree .
pip install segment-tree
Functions of Segment Tree:
- Query: It is the major function of segment tree which perform operations like finding maximum number in a range, finding minimum number in a range and finding the sum of given range .It takes 3 arguments as input which are start_index(i.e. from where the range will start), End_index(i.e. upto which index range end) and operation to be performed.
obj.query(Start_index, End_index, operation_name)
- Update: The second major function of segment tree is update which will update the value of a particular index within the range.It will replace the existing value present at that index with the new value .
The maximum value of this range is : 10 The minimum value of this range is : 3 The sum of this range is : 33 The updated array is : [1, 2, 25, 4, 5, 6, 7, 8, 9, 10, 11]
The maximum value of this range is : 200 The minimum value of this range is : 4 The sum of this range is : 655 The updated array is : [14, 28, 55, 105, 78, 0, 24, 99, 48, 200] The sum of this range is : 266 The updated array is : [14, 28, 55, 105, 10, 0, 24, 99, 48, 200]
- pwd module in Python
- grp module in Python
- MySQL-Connector-Python module in Python
- twitter-text-python (ttp) module - Python
- Python | Calendar Module
- Pyperclip module in Python
- OS Path module in Python
- struct module in Python
- Wikipedia module in Python
- C API from Extension Module in Python | Set 1
- C API from Extension Module in Python | Set 2
- Pymatrix module in python
- AppJar module in Python
- Keyword Module in Python
- spongemock module in Python
- Pylint module in Python
- PyInputPlus module in Python
- Cachetools module in Python
- OS Module in Python with Examples
- Psutil module in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.