臭屁什么意思| 全身酸痛吃什么药好| 冰藤席是什么材质| 什么降血糖| 北京大学前身叫什么| 舌头边上有锯齿状是什么原因| 什么叫统招| 荆芥是什么菜| 梦见打老公是什么意思| 孕妇梦见小蛇是什么意思| 痛经 吃什么| eb病毒阳性是什么意思| 酸是什么| 感冒了吃什么食物最好| dhea是什么| 角色扮演是什么意思| 牙龈肿是什么原因引起的| 足石念什么| yellow是什么颜色| 厚黑学的精髓是什么| 行运是什么意思| 什么动作容易怀孕| 安睡裤是干什么用的| 男字五行属什么| 血尿是什么原因引起的| 公元前3000年是什么朝代| 梦见大水是什么意思| 阴茎中途疲软吃什么药| 什么叫人均可支配收入| 童子是什么意思| 椭圆机是什么| 吃什么补维生素b12| 怀孕十天左右有什么反应| 熤是什么意思| 媱字五行属什么| 化干戈为玉帛是什么意思| 拔罐对身体有什么好处和坏处| 梦见婆婆去世预示什么| 牙齿松动什么原因| cd3cd4cd8都代表什么| 妇科检查bv阳性是什么意思| 筹钱是什么意思| 盐是什么| 直肠炎是什么原因引起的| 金牛男喜欢什么样的女生| 扁桃体肿大吃什么药好| 打了狂犬疫苗不能吃什么| 什么是静息心率| 颜面扫地什么意思| 65是什么意思| 藏红花和什么一起泡水喝效果好| 口大是什么字| 身旺是什么意思| 什么都想要| 每天吃一个西红柿有什么好处| 夏天喝什么饮料好| 脑梗适合吃什么水果| 什么是无期徒刑| 7月10号什么星座| 单核细胞比率偏高是什么意思| 乳腺结节和乳腺增生有什么区别| 憩是什么意思| 右脚麻是什么病的前兆| 17楼五行属什么| 小孩晚上睡觉流口水是什么原因| 空囊是什么原因造成的| 肌酐700多意味着什么| 白眼球有红血丝是什么原因| 诺如病毒吃什么药| 支原体弱阳性是什么意思| 白羊座上升星座是什么| 心博是什么意思| 甲状腺结节有什么症状| 为什么做完爱下面会疼| 什么的风雨| 深度睡眠是什么意思| 棕色是什么颜色| 什么药一吃就哑巴了| vad是什么意思| 老戏骨是什么意思| 大校是什么级别| 什么是亚麻籽| 心率低吃什么药好| 吃什么能消除脂肪瘤| 布鲁氏菌病是什么病| 粗糙的什么| 手容易出汗是什么原因| 长残了是什么意思| 三本是什么| 什么然而至| 乳腺一类是什么意思| 人咬人有什么危害| 吃什么可以增加免疫力| 总打喷嚏是什么原因| 身体出汗多是什么原因| 男人壮阳吃什么最快| 世界上什么东西最大| 什么药治咳嗽最好| 凝血常规是查什么的| 月经期间可以喝什么茶| 床垫什么材质的好| 中午吃什么饭 家常菜| 鲜黄花菜含有什么毒素| 人为什么有两个鼻孔| 月亮像什么的比喻句| 回心转意是什么意思| 美白吃什么| 狼入虎口是什么意思| 上校军衔是什么级别| 属羊的本命佛是什么佛| 智齿有什么用| 副肾是什么药名| 坐享其成是什么意思| 无花果吃了有什么好处| 一什么水珠| 最可爱的动物是什么生肖| 晚上10点是什么时辰| 西五行属什么| 敲定是什么意思| 水奶和奶粉什么区别| 柿子不能和什么食物一起吃| 生孩子需要准备什么东西| 婴儿足底采血查什么| 胃胀不消化吃什么药好| 印堂发黑是什么征兆| 钴蓝色是什么颜色| 情人果是什么| 屎黄色是什么颜色| 打鸡血是什么意思| 80年属猴的是什么命| 畏寒肢冷是什么意思| 白头发挂什么科| 漏尿是什么原因造成的| 6月18号是什么星座| 玄凤鹦鹉吃什么| 1885年属什么生肖| hpv疫苗是什么疫苗| 铁达时手表什么档次| 胃疼做什么检查| 月经量少吃什么药调理| 什么护肤产品补水最好| 大黄是什么| 鸽子单眼伤风用什么药| 什么雪糕最好吃| 食物中毒拉肚子吃什么药| 一边什么一边什么| ivory是什么意思| 雀子是什么意思| 什么开窍于耳| 万圣节是什么时候| 手指是什么生肖| 交替是什么意思| 用什么刷牙能使牙齿变白| 慈是什么意思| 膜性肾病什么意思| cl是什么牌子| 便秘吃什么蔬菜| 吃了饭胃胀是什么原因| 10月15日什么星座| 怀孕做无创是查什么| 小孩感冒吃什么药| 牙疼能吃什么食物| 七夕什么时候| 什么的雪花| 什么虫子咬完是小红点| 男生为什么会勃起| 突然头昏是什么原因引起的| 淋巴细胞高是什么意思| 面黄肌瘦是什么意思| 宋江是属什么生肖| 东北话篮子是什么意思| 你喜欢什么| 凉血是什么意思| 左手大拇指抖动是什么原因| 产后复查挂什么科| 舌头麻木是什么原因| 12月份什么星座| 慢性鼻窦炎吃什么药| 注意身体是什么意思| 青少年耳鸣是什么原因引起的| 梦见抓蛇是什么预兆| 被紫外线灯照到有什么后果呀| 胸长什么样| 缘定三生是什么意思| 儿童弱视是什么原因引起的| 熬中药用什么锅最好| 梦见捡手机是什么意思| 吃什么清理血管| 口腔炎吃什么药| 梦见捡了好多钱是什么预兆| 出身是什么意思| 股票roe是什么意思| 眼睛长结石是什么原因引起的| 抗原和抗体有什么区别| 内膜回声欠均匀是什么意思| 脸颊红是什么原因| 什么叫2型糖尿病| 嘴唇干裂脱皮是什么原因| 血脂高是什么原因引起的| 1994年是什么命| 申属于五行属什么| 健身吃什么水果| 口嫌体正直什么意思| 五朵玫瑰花代表什么意思| 为什么喝纯牛奶会拉肚子| 梦见猪下崽预兆什么| 什么是埋线双眼皮| 才子是什么意思| 10月28号是什么星座| 脸肿眼睛肿是什么原因引起的| 收尿干什么用的| 梦见媳妇出轨什么预兆| 温字五行属什么| 孕妇晚餐吃什么比较好| 驴血是什么颜色| 水泡型脚气用什么药| 着床是什么意思| 怀孕了想打掉吃什么药| 来世是什么意思| 阴茎不硬是什么原因| 尿崩症是什么症状| 海葡萄是什么东西| 小狗能吃什么| 宜子痣是什么意思| 印度人口什么时候超过中国| 飞蚊症用什么眼药水| 玖姿女装属于什么档次| 猪狗不如是什么生肖| 什么面什么刀| 什么肉最好吃| 做梦牙掉了是什么征兆| 6月份是什么星座的| 大便干结吃什么药| 什么鱼红烧最好吃| 新疆是什么族| 7月14号是什么星座| 母慈子孝下一句是什么| 招财进宝是什么意思| 瑄五行属什么| 03年属什么生肖| c4是什么意思| 结婚60年是什么婚| 安属于五行属什么| 黑舌头的狗是什么狗| dq是什么意思| 营养师属于什么专业| 睡觉头晕是什么原因引起的| 附件炎吃什么药效果好| 5月22是什么星座| male是什么意思| 传染病八项包括什么| 铀是什么| 118号是什么星座| hvp阳性是什么病| 禁欲系是什么意思| 张牙舞爪是什么意思| 年底是什么时候| 吃什么水果对肾有好处| 冥冥中是什么意思| 懋是什么意思| 山字五行属什么| 宫腔灌注是治疗什么的| 胆红素阴性是什么意思| 什么人不能吃石斛| 百度Jump to content

什么的小学生

From Wikipedia, the free encyclopedia
Ternary Search Tree (TST)
Typetree
Time complexity in big O notation
Operation Average Worst case
Search O(log n) O(n)
Insert O(log n) O(n)
Delete O(log n) O(n)
Space complexity
百度 首先,从生理和性科学角度分析,姐弟恋性爱可能更和谐。

In computer science, a ternary search tree is a type of trie (sometimes called a prefix tree) where nodes are arranged in a manner similar to a binary search tree, but with up to three children rather than the binary tree's limit of two. Like other prefix trees, a ternary search tree can be used as an associative map structure with the ability for incremental string search. However, ternary search trees are more space efficient compared to standard prefix trees, at the cost of speed. Common applications for ternary search trees include spell-checking and auto-completion.

Description

[edit]

Each node of a ternary search tree stores a single character, an object (or a pointer to an object depending on implementation), and pointers to its three children conventionally named equal kid, lo kid and hi kid, which can also be referred respectively as middle (child), lower (child) and higher (child).[1] A node may also have a pointer to its parent node as well as an indicator as to whether or not the node marks the end of a word.[2] The lo kid pointer must point to a node whose character value is less than the current node. The hi kid pointer must point to a node whose character is greater than the current node.[1] The equal kid points to the next character in the word. The figure below shows a ternary search tree with the strings "cute","cup","at","as","he","us" and "i":

          c
        / | \
       a  u  h
       |  |  | \
       t  t  e  u
     /  / |   / |
    s  p  e  i  s

As with other trie data structures, each node in a ternary search tree represents a prefix of the stored strings. All strings in the middle subtree of a node start with that prefix.

Operations

[edit]

Insertion

[edit]

Inserting a value into a ternary search can be defined recursively or iteratively much as lookups are defined. This recursive method is continually called on nodes of the tree given a key which gets progressively shorter by pruning characters off the front of the key. If this method reaches a node that has not been created, it creates the node and assigns it the character value of the first character in the key. Whether a new node is created or not, the method checks to see if the first character in the string is greater than or less than the character value in the node and makes a recursive call on the appropriate node as in the lookup operation. If, however, the key's first character is equal to the node's value then the insertion procedure is called on the equal kid and the key's first character is pruned away.[1] Like binary search trees and other data structures, ternary search trees can become degenerate depending on the order of the keys.[3][self-published source?] Inserting keys in alphabetical order is one way to attain the worst possible degenerate tree.[1] Inserting the keys in random order often produces a well-balanced tree.[1]

function insertion(string key) is
	node p := root 
    //initialized to be equal in case root is null
	node last := root
	int idx := 0
	while p is not null do
        //recurse on proper subtree
		if key[idx] < p.splitchar then
			last := p
			p := p.left
		else if key[idx] > p.splitchar then
			last := p
			p := p.right
		else:
            // key is already in our Tree
			if idx == length(key) then
				return 
            //trim character from our key 
			idx := idx+1
			last := p
			p := p.mid
	p := node()
    //add p in as a child of the last non-null node (or root if root is null)
    if root == null then
        root := p
	else if last.splitchar < key[idx] then
		last.right := p
	else if last.splitchar > key[idx] then
		last.left := p
	else 
		last.mid := p
	p.splitchar := key[idx]
	idx := idx+1
    // Insert remainder of key
	while idx < length(key) do
		p.mid := node()
        p.mid.splitchar := key[idx]
		idx += 1
[edit]

To look up a particular node or the data associated with a node, a string key is needed. A lookup procedure begins by checking the root node of the tree and determining which of the following conditions has occurred. If the first character of the string is less than the character in the root node, a recursive lookup can be called on the tree whose root is the lo kid of the current root. Similarly, if the first character is greater than the current node in the tree, then a recursive call can be made to the tree whose root is the hi kid of the current node.[1] As a final case, if the first character of the string is equal to the character of the current node then the function returns the node if there are no more characters in the key. If there are more characters in the key then the first character of the key must be removed and a recursive call is made given the equal kid node and the modified key.[1] This can also be written in a non-recursive way by using a pointer to the current node and a pointer to the current character of the key.[1]

Pseudocode

[edit]
 function search(string query) is
     if is_empty(query) then
         return false
 
     node p := root
     int idx := 0
 
     while p is not null do
         if query[idx] < p.splitchar then
             p := p.left
         else if query[idx] > p.splitchar then
             p := p.right;
         else
             if idx = length(query) then
                 return true
             idx := idx + 1
             p := p.mid
 
     return false

Deletion

[edit]

The delete operation consists of searching for a key string in the search tree and finding a node, called firstMid in the below pseudocode, such that the path from the middle child of firstMid to the end of the search path for the key string has no left or right children. This would represent a unique suffix in the ternary tree corresponding to the key string. If there is no such path, this means that the key string is either fully contained as a prefix of another string, or is not in the search tree. Many implementations make use of an end of string character to ensure only the latter case occurs. The path is then deleted from firstMid.mid to the end of the search path. In the case that firstMid is the root, the key string must have been the last string in the tree, and thus the root is set to null after the deletion.

 function delete(string key) is
     if is_empty(key) then
         return 
 
     node p := root
     int idx := 0

 	 node firstMid := null
     while p is not null do
         if key[idx] < p.splitchar then
             firstMid := null
             p := p.left
         else if key[idx] > p.splitchar then
             firstMid := null
             p := p.right
         else
             firstMid := p
             while p is not null and key[idx] == p.splitchar do
             	idx := idx + 1
             	p := p.mid
             
     if firstMid == null then
         return  // No unique string suffix

     // At this point, firstMid points to the node before the strings unique suffix occurs
     node q := firstMid.mid 
     node p := q
     firstMid.mid := null // disconnect suffix from tree
     while q is not null do //walk down suffix path and delete nodes 
         p := q
         q := q.mid 
         delete(p)			// free memory associated with node p
     if firstMid == root then 
         delete(root)       //delete the entire tree
         root := null

Traversal

[edit]

[clarification needed][example needed]

Partial-match searching

[edit]

[clarification needed][example needed]

Near-neighbor searching

[edit]

[clarification needed][example needed]

Running time

[edit]

The running time of ternary search trees varies significantly with the input. Ternary search trees run best when given several similar strings, especially when those strings share a common prefix. Alternatively, ternary search trees are effective when storing a large number of relatively short strings (such as words in a dictionary).[1] Running times for ternary search trees are similar to binary search trees, in that they typically run in logarithmic time, but can run in linear time in the degenerate (worst) case. Further, the size of the strings must also be kept in mind when considering runtime. For example, in the search path for a string of length k, there will be k traversals down middle children in the tree, as well as a logarithmic number of traversals down left and right children in the tree. Thus, in a ternary search tree on a small number of very large strings the lengths of the strings can dominate the runtime.[4]

Time complexities for ternary search tree operations:[1]

Average-case running time Worst-case running time
Lookup O(log n + k) O(n + k)
Insertion O(log n + k) O(n + k)
Delete O(log n + k) O(n + k)

Comparison to other data structures

[edit]

Tries

[edit]

While being slower than other prefix trees, ternary search trees can be better suited for larger data sets due to their space-efficiency.[1]

Hash maps

[edit]

Hashtables can also be used in place of ternary search trees for mapping strings to values. However, hash maps also frequently use more memory than ternary search trees (but not as much as tries). Additionally, hash maps are typically slower at reporting a string that is not in the same data structure, because it must compare the entire string rather than just the first few characters. There is some evidence that shows ternary search trees running faster than hash maps.[1] Additionally, hash maps do not allow for many of the uses of ternary search trees, such as near-neighbor lookups.

If storing dictionary words is all that is required (i.e., storage of information auxiliary to each word is not required), a minimal deterministic acyclic finite state automaton (DAFSA) would use less space than a trie or a ternary search tree. This is because a DAFSA can compress identical branches from the trie which correspond to the same suffixes (or parts) of different words being stored.

Uses

[edit]

Ternary search trees can be used to solve many problems in which a large number of strings must be stored and retrieved in an arbitrary order. Some of the most common or most useful of these are below:

See also

[edit]

References

[edit]
  1. ^ a b c d e f g h i j k l m n "Ternary Search Trees". Dr. Dobb's.
  2. ^ a b Ostrovsky, Igor. "Efficient auto-complete with a ternary search tree".
  3. ^ a b Wrobel, Lukasz. "Ternary Search Tree".
  4. ^ Bentley, Jon; Sedgewick, Bob. "Ternary Search Tree".
  5. ^ a b c Flint, Wally (February 16, 2001). "Plant your data in a ternary search tree". JavaWorld. Retrieved 2025-08-05.
[edit]
  • Ternary Search Trees page with papers (by Jon Bentley and Robert Sedgewick) about ternary search trees and algorithms for "sorting and searching strings"
  • Ternary Search Tries – a video by Robert Sedgewick
  • TST.java.html Implementation in Java of a TST by Robert Sedgewick and Kevin Wayne
为什么会牙疼 肺部结节挂什么科 纯碱是什么 学考成绩什么时候公布 检察长什么级别
7月25是什么星座 小姐的全套都有什么 裸婚是什么意思 戴银镯子变黑是什么原因 头晕呕吐吃什么药
丞五行属什么 乙肝核心抗体高是什么意思 5月5号什么星座 安宫牛黄丸有什么作用 94年属狗的是什么命
采是什么意思 乙肝表面抗体弱阳性什么意思 什么药 谷草谷丙是什么 阴道痒吃什么药
宽宽的什么填空hcv9jop4ns9r.cn 一个至一个秦是什么字hcv8jop2ns0r.cn 哺乳期可以喝什么饮料hcv8jop7ns9r.cn 眼压是什么意思hcv8jop3ns8r.cn 脑梗是什么引起的hcv8jop3ns6r.cn
dvt是什么意思hcv9jop6ns1r.cn 甲亢有些什么症状hcv7jop7ns4r.cn 胀气是什么症状hcv8jop3ns9r.cn 甲功七项挂什么科hcv8jop5ns3r.cn 肾精亏虚吃什么药hcv9jop0ns2r.cn
pad是什么hcv8jop2ns9r.cn 蔬菜有什么hcv9jop0ns6r.cn 蓝莓是什么颜色hcv9jop4ns7r.cn 2002年是什么生肖hcv8jop6ns0r.cn naomi什么意思hcv8jop0ns1r.cn
放屁多是什么原因引起的hcv8jop8ns5r.cn 胃溃疡适合吃什么食物hcv8jop2ns0r.cn 漂亮的什么hcv8jop6ns7r.cn 骨转移用什么药hcv9jop6ns1r.cn 切尔斯什么意思hcv9jop2ns3r.cn
百度