Skip to content

Commit

Permalink
misc: extract common introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye committed Nov 28, 2024
1 parent d53a8ab commit 7ec4a03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 10 additions & 0 deletions next/tutorial/example/segment-tree/index.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 0 additions & 12 deletions next/tutorial/example/segment-tree/segment-tree.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 7ec4a03

Please sign in to comment.