From 7ec4a03dcceddcbdbb5aef36e48ffdd097c89eba Mon Sep 17 00:00:00 2001 From: zihang Date: Thu, 28 Nov 2024 15:30:38 +0800 Subject: [PATCH] misc: extract common introduction --- next/tutorial/example/segment-tree/index.md | 10 ++++++++++ next/tutorial/example/segment-tree/segment-tree.md | 12 ------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/next/tutorial/example/segment-tree/index.md b/next/tutorial/example/segment-tree/index.md index 91b1aca6..56920e38 100644 --- a/next/tutorial/example/segment-tree/index.md +++ b/next/tutorial/example/segment-tree/index.md @@ -1,5 +1,15 @@ # Segment Tree +The Segment Tree is a common data structure used to solve various range modification and query problems. For instance, consider the following problem: + +- Given a known-length array of numbers with initial values, we need to perform multiple range addition operations (adding a value to all elements in a range) and range sum operations (calculating the sum of elements in a range). + +Using a standard array, assuming the length og this array is N, each modification and query would take O(N) time. However, after constructing a Segment Tree in O(log N) time, both operations can be performed in O(log N), highlighting the importance of Segment Trees for range queries. + +This example illustrates just one simple problem that Segment Trees can address. They can handle much more complex and interesting scenarios. In the upcoming articles, we will explore the concept of Segment Trees and how to implement them in MoonBit, ultimately creating a tree that supports range addition and multiplication, enables range sum queries, and has immutable properties. + +In this section, we will learn the basic principles of Segment Trees and how to write a simple Segment Tree in MoonBit that supports point modifications and queries. + ```{toctree} :maxdepth: 2 :caption: Contents: diff --git a/next/tutorial/example/segment-tree/segment-tree.md b/next/tutorial/example/segment-tree/segment-tree.md index ddbd525f..aa9e1a5d 100644 --- a/next/tutorial/example/segment-tree/segment-tree.md +++ b/next/tutorial/example/segment-tree/segment-tree.md @@ -1,17 +1,5 @@ # Segment Trees (Part 1) -## Introduction - -The Segment Tree is a common data structure used to solve various range modification and query problems. For instance, consider the following problem: - -- Given a known-length array of numbers with initial values, we need to perform multiple range addition operations (adding a value to all elements in a range) and range sum operations (calculating the sum of elements in a range). - -Using a standard array, assuming the length og this array is N, each modification and query would take O(N) time. However, after constructing a Segment Tree in O(log N) time, both operations can be performed in O(log N), highlighting the importance of Segment Trees for range queries. - -This example illustrates just one simple problem that Segment Trees can address. They can handle much more complex and interesting scenarios. In the upcoming articles, we will explore the concept of Segment Trees and how to implement them in MoonBit, ultimately creating a tree that supports range addition and multiplication, enables range sum queries, and has immutable properties. - -In this section, we will learn the basic principles of Segment Trees and how to write a simple Segment Tree in MoonBit that supports point modifications and queries. - ## What is a Segment Tree? This section focuses on concepts and theory. If you're already familiar with Segment Trees and their principles, feel free to skip to the next section.