Skip to content

Instantly share code, notes, and snippets.

Parth Mittal parthmittal

  • New Delhi, India
Block or report user

Report or block parthmittal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View segment_tree_global.py
max_N = (1 << 20) #This is the maximum size of array our tree will support
seg = [0] * (4 * max_N) #Initialises the 'tree' to all zeroes.
def build(someList, v, L, R):
global seg
if (L == R):
seg[v] = someList[L]
else:
mid = (L + R) / 2 #Integer division is equivalent to flooring.
build(someList, 2 * v, L, mid)
@parthmittal
parthmittal / segment_tree.py
Last active Jun 20, 2018
A class implementing the segment tree data structure
View segment_tree.py
class segment_tree:
"""A class which implements a range sum tree"""
def __init__(self, some_list):
"""
Initialises the tree, needs a list as a parameter
"""
self.N = len(some_list)
self.seg = [0] * (4 * len(some_list))
You can’t perform that action at this time.