MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / update

Method update

data_structures/binary_tree/segment_tree.py:47–57  ·  view source on GitHub ↗

Update the values in the segment tree in the range [a,b] with the given value. >>> s = SegmentTree([1, 2, 3, 4, 5]) >>> s.update(2, 4, 10) True >>> s.query(1, 5) 10

(self, a, b, val)

Source from the content-addressed store, hash-verified

45 self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])
46
47 def update(self, a, b, val):
48 """
49 Update the values in the segment tree in the range [a,b] with the given value.
50
51 >>> s = SegmentTree([1, 2, 3, 4, 5])
52 >>> s.update(2, 4, 10)
53 True
54 >>> s.query(1, 5)
55 10
56 """
57 return self.update_recursive(1, 0, self.N - 1, a - 1, b - 1, val)
58
59 def update_recursive(self, idx, left, right, a, b, val):
60 """

Callers 1

segment_tree.pyFile · 0.45

Calls 1

update_recursiveMethod · 0.95

Tested by

no test coverage detected