







Sebuah pohon segmen (Segment Tree / ST) adalah pohon biner yang dibuat berdasarkan sebuah array (biasanya integer) supaya kita dapat menyelesaikan query Range Min/Max/Sum serta query Range Update pada array tersebut dalam O(log N) dibandingkan dengan cara naif dalam O(N). Dengan sebuah array A dari N element, kita dapat membuat pohon segmen RMinQ/RMaxQ/RSumQ dalam O(N).
Remarks: By default, we show e-Lecture Mode for first time (or non logged-in) visitor.
If you are an NUS student and a repeat visitor, please login.
Pro-tip 1: Since you are not logged-in, you may be a first time visitor (or not an NUS student) who are not aware of the following keyboard shortcuts to navigate this e-Lecture mode: [PageDown]/[PageUp] to go to the next/previous slide, respectively, (and if the drop-down box is highlighted, you can also use [→ or ↓/← or ↑] to do the same),and [Esc] to toggle between this e-Lecture mode and exploration mode.
Simpul-simpul yang di-update seperlunya (lazy update) akan memiliki highlight cincin ungu.
Tiap simpul yang berupa daun (leaf) dari Pohon Segmen ini melambangkan indeks di array A yang bersangkutan.
Pro-tip 2: We designed this visualization and this e-Lecture mode to look good on 1366x768 resolution or larger (typical modern laptop resolution in 2021). We recommend using Google Chrome to access VisuAlgo. Go to full screen mode (F11) to enjoy this setup. However, you can use zoom-in (Ctrl +) or zoom-out (Ctrl -) to calibrate this.
Terdapat tiga operasi dasar yang tersedia pada visualisasi struktur data Pohon Segmen (untuk tiap mode: RMinQ/RMaxQ/RSumQ):
1. Anda dapat membuat pohon segmen RMinQ/RMaxQ/RSumQ dari array integer masukkan anda sendiri (maksimum terdiri dari 16 integer 2 digit), atau membiarkan sistem menyediakan sebuah integer (acak) kecil atau sebuah array (terurut) kecil yang terdiri dari integer.
2. Anda dapat melakukan query RMinQ/RMaxQ/RSumQ dengan menyediakan dua indeks: kiri (L) dan kanan (R).
3. Anda dapat melakukan update pada range terentu dengan menyediakan sebuah indeks kiri (L), sebuah indeks kanan (R), dan NILAI (value) baru untuk range [L,R] ini. Kita menggunakan update seperlunya (lazy update) untuk mengoptimalkan performa.
Pro-tip 3: Other than using the typical media UI at the bottom of the page, you can also control the animation playback using keyboard shortcuts (in Exploration Mode): Spacebar to play/pause/replay the animation, ←/→ to step the animation backwards/forwards, respectively, and -/+ to decrease/increase the animation speed, respectively.
Unfortunately, this data structure is not yet available in C++ STL, Java API, Python or OCaml Standard Library as of 2020. Therefore, we have to write our own implementation.
Please look at the following C++/Java/Python/OCaml implementations of this Segment Tree data structure in Object-Oriented Programming (OOP) fashion:
segmenttree_ds.cpp
segmenttree_ds.java
segmenttree_ds.py
segmenttree_ds.ml
Again, you are free to customize this custom library implementation to suit your needs.
You have reached the last slide. Return to 'Exploration Mode' to start exploring!
Note that if you notice any bug in this visualization or if you want to request for a new visualization feature, do not hesitate to drop an email to the project leader: Dr Steven Halim via his email address: stevenhalim at gmail dot com.
Buat
Query Range
Update Range