From 98a41eef3f00ac2e3a6d5d8ec31159cdd9f47c20 Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Mon, 30 Sep 2024 09:48:01 +0200 Subject: [PATCH] Added comments time complexity for query(), update() and buildTree() --- DataStructures/SegmentTree/SegmentTree.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DataStructures/SegmentTree/SegmentTree.php b/DataStructures/SegmentTree/SegmentTree.php index 030231a..fbc39a1 100644 --- a/DataStructures/SegmentTree/SegmentTree.php +++ b/DataStructures/SegmentTree/SegmentTree.php @@ -83,7 +83,7 @@ public function getCurrentArray(): array } /** - * Builds the segment tree recursively. + * Builds the segment tree recursively. Takes O(n log n) in total. * * @param array $arr The input array. * @param int $start The starting index of the segment. @@ -115,7 +115,7 @@ private function buildTree(array $arr, int $start, int $end): SegmentTreeNode } /** - * Queries the aggregated value over a specified range. + * Queries the aggregated value over a specified range. Takes O(log n). * * @param int $start The starting index of the range. * @param int $end The ending index of the range. @@ -164,7 +164,7 @@ private function queryTree(SegmentTreeNode $node, int $start, int $end) } /** - * Updates the value at a specified index in the segment tree. + * Updates the value at a specified index in the segment tree. Takes O(log n). * * @param int $index The index to update. * @param int|float $value The new value to set.