Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trie #79

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Add trie #79

wants to merge 23 commits into from

Conversation

conan1412yang99
Copy link

@conan1412yang99 conan1412yang99 commented May 14, 2023

  • Read Contribute to NTHU-CPP.
  • Rebase to the latest main branch.
  • List all the references.
  • Successfully build the website by mdBook with no error after the change.
  • Exclude any irrelevant files.
  • Link to the issue which is related to your change.
  • Review the content by myself.
  • Pass tests/CI.

#35

@harry900831 harry900831 linked an issue May 18, 2023 that may be closed by this pull request
@conan1412yang99 conan1412yang99 marked this pull request as ready for review June 22, 2023 16:03
@conan1412yang99 conan1412yang99 changed the title Add trie (wip) Add trie Jun 22, 2023
Copy link
Contributor

@harry900831 harry900831 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image path should be image/trie/xxx.jpg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be consistent about the style of the figure

Comment on lines +18 to +19
有了這個樹狀的 Trie,我們可以在節點上儲存一些資訊,在查詢是否存在的這個例子,我們可以在每個節點上
存一個 `int` 代表目前的字串集合,有幾個字串等於這個節點代表的字串。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這一段應該在後面查詢再解釋

有了這個樹狀的 Trie,我們可以在節點上儲存一些資訊,在查詢是否存在的這個例子,我們可以在每個節點上
存一個 `int` 代表目前的字串集合,有幾個字串等於這個節點代表的字串。

![](./image/p1.jpg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的文字敘述是邊代表字元
但你圖不是這樣表示啊?

有了這個樹狀的 Trie,我們可以在節點上儲存一些資訊,在查詢是否存在的這個例子,我們可以在每個節點上
存一個 `int` 代表目前的字串集合,有幾個字串等於這個節點代表的字串。

![](./image/p1.jpg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

圖的解析度有點差


### 查詢

查詢一個字串是否出現在集合中,我們可以從跟節點(空字串)開始,照著要查詢的字串,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

跟->根

Comment on lines 89 to 91
### 例題: BZOJ1954 樹上最大 xor sum 路徑

一棵帶有正整數邊權的無根樹,求 \\((u, v)\\) 使得節點 \\(u\\) 到 \\(v\\) 的路徑之間邊權 xor 總和最大,輸出這個邊權 xor 總和。 (\\(1 \leq N \leq 10^5, 0 \leq w \le 2^31\\))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

題目格式請參考其他文章


## 其他例題

### 最大 XOR sum 子陣列
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem source?


因此我們同樣可以使用 xor trie 的技巧,先將所有 \\(P(i)\\)加入 xor trie,接著我們枚舉第一個元素 L,我們即可以在 trie 中尋找最大化 \\(P(L) \oplus P(R)\\) 的 R。

### First Second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem source?


### 複雜度分析

考慮到每次新增會增加一個長度為 \\(L\\) 所會創造出的節點數還是 \\(O(L)\\),時間複雜度和空間複雜度與一般的 trie 一樣皆是線性於操作的字串長度。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

persistent 資料結構的空間複雜度需要好好分析
不能以單一操作來分析空間複雜度...

Comment on lines +433 to +436
- https://oi-wiki.org/string/trie/#%E7%BB%B4%E6%8A%A4%E5%BC%82%E6%88%96%E6%9E%81%E5%80%BC
- https://www.topcoder.com/thrive/articles/Using%20Tries
- https://iq.opengenus.org/persistent-trie/
- https://codeforces.com/blog/entry/93724
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [text](link)
    Please give these links a text

You should also read more on this topic. You can refer to lots of codeforces blog.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@harry900831 harry900831 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harry900831
Copy link
Contributor

friendly ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Trie
2 participants