Skip to content

Commit 60ce472

Browse files
authored
Clarify segment tree wording and indexing
1 parent fa72825 commit 60ce472

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/data_structures/segment_tree.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ If we computed each query naively, each query would take $O(n)$ time. The Segmen
3030

3131
We can take a divide-and-conquer approach when it comes to array segments.
3232
We compute and store the sum of the elements of the whole array, i.e. the sum of the segment $a[0 \dots n-1]$.
33-
We then split the array into two halves $a[0 \dots n/2]$ and $a[n/2+1 \dots n-1]$ and compute the sum of each halve and store them.
34-
Each of these two halves in turn also split in half, their sums are computed and stored.
35-
And this process repeats until all segments reach size $1$.
36-
In other words we start with the segment $a[0 \dots n-1]$, split the current segment in half (if it has not yet become a segment containing a single element), and then calling the same procedure for both halves.
37-
For each such segment we store the sum of the numbers on it.
33+
We then split the array into two halves $a[0 \dots n/2-1]$ and $a[n/2 \dots n-1]$ and compute the sum of each halve and store them.
34+
Each of these two halves in turn are split in half, and so on until all segments reach size $1$.
3835

39-
We can say, that these segments form a binary tree:
36+
We can view these segments as forming a binary tree:
4037
the root of this tree is the segment $a[0 \dots n-1]$, and each vertex (except leaf vertices) has exactly two child vertices.
4138
This is why the data structure is called "Segment Tree", even though in most implementations the tree is not constructed explicitly (see [Implementation](segment_tree.md#implementation)).
4239

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy