Skip to content

Commit 3691375

Browse files
jxuadamant-pwn
authored andcommitted
Segment tree: add details of implicit data structure
1 parent a79feba commit 3691375

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/data_structures/segment_tree.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ The green vertices are the vertices that we visit and update.
158158

159159
The main consideration is how to store the Segment Tree.
160160
Of course we can define a $\text{Vertex}$ struct and create objects, that store the boundaries of the segment, its sum and additionally also pointers to its child vertices.
161-
However this requires storing a lot of redundant information.
162-
We will use a simple trick, to make this a lot more efficient.
163-
We only store the sums in an array.
161+
However, this requires storing a lot of redundant information in the form of pointers.
162+
We will use a simple trick to make this a lot more efficient of using an _implicit data structure_: Only storing the sums in an array.
163+
(A similar method is used for binary heaps).
164164
The sum of the root vertex at index 1, the sums of its two child vertices at indices 2 and 3, the sums of the children of those two vertices at indices 4 to 7, and so on.
165-
It is easy to see, that the left child of a vertex at index $i$ is stored at index $2i$, and the right one at index $2i + 1$.
165+
With 1-indexing, conveniently the left child of a vertex at index $i$ is stored at index $2i$, and the right one at index $2i + 1$.
166166

167167
This simplifies the implementation a lot.
168168
We don't need to store the structure of the tree in memory.

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