X-fast trie

X-fast trie
TypeTrie
Invented1982
Invented byDan Willard
Time complexity in big O notation
Operation Average Worst case
Search O(log log M) O(log log M)
Insert O(log M) amortized
Delete O(log M) amortized
Space complexity
Space O(n log M) O(n log M)

In computer science, an x-fast trie is a data structure for storing integers from a bounded domain. It supports exact and predecessor or successor queries in time O(log log M), using O(n log M) space, where n is the number of stored values and M is the maximum value in the domain. The structure was proposed by Dan Willard in 1982,[1] along with the more complicated y-fast trie, as a way to improve the space usage of van Emde Boas trees, while retaining the O(log log M) query time.

Structure

A binary tree with 4 levels. The nodes on each level are: 3: (), 2: (0) and (1), 1: (00) and (10), 0: (001), (100) and (101). The unlabeled node is the root. There are directed edges between the following nodes: ()->(0), ()->(1), (0)->(00), (0)->(100) in blue, (1)->(10), (1)->(101) in blue, (00)->(001) twice, once in blue, (10)->(100), (10)->(101), (001)<->(100), (100)<->(101). The nodes on each level are contained in a box, labeled with LSS(<level>).
An x-fast trie containing the integers 1 (0012), 4 (1002) and 5 (1012). Blue edges indicate descendant pointers.

An x-fast trie is a bitwise trie: a binary tree where each subtree stores values whose binary representations start with a common prefix. Each internal node is labeled with the common prefix of the values in its subtree and typically, the left child adds a 0 to the end of the prefix, while the right child adds a 1. The binary representation of an integer between 0 and M − 1 uses ⌈log2 M⌉ bits, so the height of the trie is O(log M).

All values in the x-fast trie are stored at the leaves. Internal nodes are stored only if they have leaves in their subtree. If an internal node would have no left child, it stores a pointer to the smallest leaf in its right subtree instead, called a descendant pointer. Likewise, if it would have no right child, it stores a pointer to the largest leaf in its left subtree. Each leaf stores a pointer to its predecessor and successor, thereby forming a doubly linked list. Finally, there is a hash table for each level that contains all the nodes on that level. Together, these hash tables form the level-search structure (LSS). To guarantee the worst-case query times, these hash tables should use dynamic perfect hashing or cuckoo hashing.

The total space usage is O(n log M), since each element has a root-to-leaf path of length O(log M).

Operations

Like van Emde Boas trees, x-fast tries support the operations of an ordered associative array. This includes the usual associative array operations, along with two more order operations, Successor and Predecessor:

  • Find(k): find the value associated with the given key
  • Successor(k): find the key/value pair with the smallest key larger than or equal to the given key
  • Predecessor(k): find the key/value pair with the largest key less than or equal to the given key
  • Insert(k, v): insert the given key/value pair
  • Delete(k): remove the key/value pair with the given key

Find

Finding the value associated with a key k that is in the data structure can be done in constant time by looking up k in LSS[0], which is a hash table on all the leaves.[2]

For example, if we are looking for 4 in the above graph, we will implement the following steps:

  • Step 1: Convert the decimal 4 to binary, which is 100.
  • Step 2: Start from the root, and try to follow the path to each level. The first digit of 100 is 1, so follow the right path (1) of the root to the node "1".
  • Step 3: Repeat the Step 2, the 2nd digit of 100 is 0, so follow the left path (0) of the node "1" to the node "10".
  • Step 4: Repeat the Step 3, the 3rd digits of 100 is 0, so follow the left path (0) of the node "10" to the node "100".

Successor and predecessor

To find the successor or predecessor of a key k, we first find Ak, the lowest ancestor of k. This is the node in the trie that has the longest common prefix with k. To find Ak, we perform a binary search on the levels. We start at level h/2, where h is the height of the trie. On each level, we query the corresponding hash table in the level-search structure with the prefix of k of the right length. If a node with that prefix does not exist, we know that Ak must be at a higher level and we restrict our search to those. If a node with that prefix does exist, Ak can not be at a higher level, so we restrict our search to the current and lower levels.

Once we find the lowest ancestor of k, we know that it has leaves in one of its subtrees (otherwise it wouldn't be in the trie) and k should be in the other subtree. Therefore, the descendant pointer points to the successor or the predecessor of k. Depending on which one we are looking for, we might have to take one step in the linked list to the next or previous leaf.

Since the trie has height O(log M), the binary search for the lowest ancestor takes O(log log M) time. After that, the successor or predecessor can be found in constant time, so the total query time is O(log log M).[1]

For example, if we are looking for the predecessor of 3 in the above graph, we will implement the following steps:

  • Step 1: Convert the decimal 4 to binary, which is 011.
  • Step 2: Start from the root, and try to follow the path to each level. The first digit of 011 is 0, so follow the left path (0) of the root to the node "0".
  • Step 3: Repeat the Step 2, the 2nd digit of 011 is 1, so try to follow the right path (1) . However, the node "0" has no right path, so follow the pointer to the node "001".
  • Step 4: 001 is smaller than 011, so it represents the predecessor of 011. Therefore, the predecessor of 3 is 1 (001).

Insert

To insert a key-value pair (k, v), we first find the predecessor and successor of k. Then we create a new leaf for k, insert it in the linked list of leaves between the successor and predecessor, and give it a pointer to v. Next, we walk from the root to the new leaf, creating the necessary nodes on the way down, inserting them into the respective hash tables and updating descendant pointers where necessary.

Since we have to walk down the entire height of the trie, this process takes O(log M) time.[3]

Delete

To delete a key k, we find its leaf using the hash table on the leaves. We remove it from the linked list, but remember which were the successor and predecessor. Then we walk from the leaf to the root of the trie, removing all nodes whose subtree only contained k and updating the descendant pointers where necessary. Descendant pointers that used to point to k will now point to either the successor or predecessor of k, depending on which subtree is missing.

Like insertion, this takes O(log M) time, as we have to walk through every level of the trie.[3]

Discussion

Willard introduced x-fast tries largely as an introduction to y-fast tries, which provide the same query time, while using only O(n) space and allowing insertions and deletions in O(log log M) time.[1]

A compression technique similar to patricia tries can be used to significantly reduce the space usage of x-fast tries in practice.[4]

By using an exponential search before the binary search over the levels and by querying not only the current prefix x, but also its successor x + 1, x-fast tries can answer predecessor and successor queries in time O(log log Δ), where Δ is the difference between the query value and its predecessor or successor.[2]

References

  1. ^ a b c Willard, Dan E. (1983). "Log-logarithmic worst-case range queries are possible in space Θ(N)". Information Processing Letters. 17 (2). Elsevier: 81–84. doi:10.1016/0020-0190(83)90075-3. ISSN 0020-0190.
  2. ^ a b Bose, Prosenjit; Douïeb, Karim; Dujmović, Vida; Howat, John; Morin, Pat (2010), Fast Local Searches and Updates in Bounded Universes (PDF), Proceedings of the 22nd Canadian Conference on Computational Geometry (CCCG2010), pp. 261–264
  3. ^ a b Schulz, André; Christiano, Paul (2010-03-04). "Lecture Notes from Lecture 9 of Advanced Data Structures (Spring '10, 6.851)" (PDF). Retrieved 2011-04-13.
  4. ^ Kementsietsidis, Anastasios; Wang, Min (2009), Provenance Query Evaluation: What's so special about it?, Proceedings of the 18th ACM conference on Information and knowledge management, pp. 681–690

Read other articles:

Anggaran Pendapatan dan Belanja Negara (APBN) adalah rencana keuangan tahunan Pemerintah negara Indonesia yang disetujui oleh Dewan Perwakilan Rakyat.[1] APBN berisi daftar sistematis dan terperinci yang memuat rencana penerimaan dan pengeluaran negara selama satu tahun anggaran (1 Januari - 31 Desember). APBN, perubahan APBN, dan pertanggungjawaban APBN setiap tahun ditetapkan dengan Undang-Undang . Dasar Hukum APBN Undang-Undang Dasar 1945 merupakan dasar hukum yang paling tinggi da...

 

Pour les articles homonymes, voir David Friedman et Friedman. Ne doit pas être confondu avec Milton Friedman. David FriedmanDavid Friedman en 2016.FonctionRédacteur en chefBiographieNaissance 12 février 1945 (79 ans)New YorkNationalité américaineFormation Université HarvardUniversité de ChicagoActivités Économiste, professeur d'université, romancier, écrivain, physicien, blogueur, poètePère Milton FriedmanMère Rose FriedmanEnfant Patri FriedmanAutres informationsA travaill...

 

U.S. Army's branch for personnel service support and human resources Adjutant General's Corpsbranch insigniaActive16 June 1775Country United StatesBranchU.S. ArmyTypeAdjutant GeneralRolePersonnelHome stationFort Jackson, South CarolinaMotto(s)Defend and ServeBranch colorDark Blue and Scarlet piping CommandersChief of the AG CorpsCOL Chesley D. ThigpenThe Adjutant General of the U.S. ArmyBrigadier General Gregory S. JohnsonU.S Army Deputy Chief of Staff, G-1Lieutenant General Douglas F. S...

† Человек прямоходящий Научная классификация Домен:ЭукариотыЦарство:ЖивотныеПодцарство:ЭуметазоиБез ранга:Двусторонне-симметричныеБез ранга:ВторичноротыеТип:ХордовыеПодтип:ПозвоночныеИнфратип:ЧелюстноротыеНадкласс:ЧетвероногиеКлада:АмниотыКлада:Синапсиды�...

 

Bupati Aceh SingkilPetahanaMarthunis, S.T. D.E.Asejak 21 Juli 2022Masa jabatan5 tahunPejabat pertamaMakmur Syahputra BancinSitus webSitus Resmi Kabupaten Aceh Singkil Berikut nama-nama Bupati Aceh Singkil dari masa ke masa No Bupati Mulai menjabat Akhir menjabat Prd. Ket. Wakil Bupati 1 Makmur Syahputra Bancin 2000 2005 1 Muadz Vohry Ir. M. Azmy (Penjabat) 2005 2006 Hasdaruddin(Penjabat) 2006 2007 (1) Makmur Syahputra Bancin 2007 15 Oktober 2011 2 [ket. 1] Khazali 2 Khazali 2011 ...

 

أندرس دبليو. بيرثيلسن معلومات شخصية الميلاد 28 سبتمبر 1969 (55 سنة)[1][2]  مواطنة مملكة الدنمارك  الحياة العملية المهنة ممثل،  وممثل أفلام،  ومؤدي أصوات،  ومخرج أفلام  اللغات الدنماركية  الجوائز جائزة روبرت لأفضل ممثل في دور رئيسي (عن عمل:A Lucky Man) (2023)  ا...

American politician Elliott W. SproulMember of the U.S. House of Representativesfrom Illinois's 3rd districtIn officeMarch 4, 1921 – March 3, 1931Preceded byWilliam Warfield WilsonSucceeded byEdward A. Kelly Personal detailsBorn(1856-12-28)December 28, 1856Apohaqui, Kings County, New Brunswick, CanadaDiedJune 22, 1935(1935-06-22) (aged 78)Chicago, Illinois, U.S.Political partyRepublican Elliott Wilford Sproul (December 28, 1856 – June 22, 1935) was a U.S. Represe...

 

Grup K-pop asal Korea Selatan, Big Bang telah menggelar 15 tur konser, dua diantaranya merupakan tur dunia dan lima lainnya adalah tur Jepang. Grup ini menggelar konser perdana mereka pada Desember 2006 yang bertajuk 1st Live Concert The R.E.A.L. Selama karier mereka, grup ini telah menggelar konser baik sebagai grup maupun penyanyi solo. Dari tur konser mereka tersebut, mereka berhasil menarik sebanyak lebih dari 3,5 juta penggemar dari seluruh dunia. 1st Live Concert - The R.E.A.L 1st Live ...

 

Canadian video game developer Maddy ThorsonThorson in 2021Born (1988-03-18) 18 March 1988 (age 36)NationalityCanadianOccupationVideo game developerNotable workTowerFall, Celeste Madeline Stephanie Thorson (born 18 March 1988; formerly known as Matt Thorson) is a Canadian video game developer, known as one of the lead creators for the video games TowerFall and Celeste, developed under the studio Maddy Makes Games (previously Matt Makes Games). Since September 2019, Thorson has worked as D...

هنودمعلومات عامةنسبة التسمية الهند التعداد الكليالتعداد قرابة 1.21 مليار[1][2]تعداد الهند عام 2011ق. 1.32 مليار[3]تقديرات عام 2017ق. 30.8 مليون[4]مناطق الوجود المميزةبلد الأصل الهند البلد الهند  الهند نيبال 4,000,000[5] الولايات المتحدة 3,982,398[6] الإمار...

 

Election for the governorship of the U.S. state of Minnesota 1865 Minnesota gubernatorial election ← 1863 November 7, 1865 1867 →   Nominee William Rainey Marshall Henry Mower Rice Party Republican Democratic Popular vote 17,318 13,842 Percentage 55.58% 44.42% County Results: Marshall:      50-60%      60-70%      70-80%      80-90%      ...

 

Disbanded United States Air Force organization 520th Air Defense GroupF-86D Sabres of the group's 432d Fighter-Interceptor Squadron[a]Active1944–1945, 1953–1955Country United StatesBranch United States Air ForceTypeFighter interceptorRoleAir DefenseMilitary unit The 520th Air Defense Group is a disbanded United States Air Force organization. Its last assignment was with the 4706th Air Defense Wing at Truax Field, Wisconsin, where it was inactivated in 1955. The group was...

Baeksang Arts Award for Most Popular Actress2024 recipient: An Yu-jinAwarded forMost voted actress in the popularity pollCountrySouth KoreaPresented byBaeksang Arts AwardsMost recent winnerAn Yu-jin (2024)Websitebaeksangartsawards The Baeksang Arts Award for Most Popular Actress (Korean: 백상예술대상 인기상; RR: Baeksang Yesul Daesang Ingisang) is an award presented annually at the Baeksang Arts Awards ceremony organised by Ilgan Sports and JTBC Plus, affiliate...

 

Art institution in London, England Royal Academy redirects here. For other uses, see Royal Academy (disambiguation). For the Royal Academy of Art in the Netherlands, see Royal Academy of Art, The Hague. Royal Academy of ArtsFront view, October 2010Established1768; 256 years ago (1768)LocationBurlington House, Piccadilly, London, United KingdomVisitors1,285,595 (as of 2016)[1]PresidentRebecca SalterPublic transit access Green Park; Piccadilly CircusWebsiteroyalacademy...

 

Germanic people in Northern Europe mentioned by Tacitus Map showing the Roman empire in AD 125 and contemporary barbarian Europe, showing two possible locations of the Sitones. One, based on Tacitus, places them in central Sweden. Another view places them roughly in modern Estonia and/or Finland. The Sitones were a Germanic people living somewhere in Northern Europe in the first century CE. They are mentioned only by Cornelius Tacitus in 97 CE in Germania.[1] Tacitus considered them s...

  لمعانٍ أخرى، طالع كيب (توضيح). تحتاج النصوص المترجمة في هذه المقالة إلى مراجعة لضمان معلوماتها وإسنادها وأسلوبها ومصطلحاتها ووضوحها للقارئ، لأنها تشمل ترجمة اقتراضية أو غير سليمة. فضلاً ساهم في تطوير هذه المقالة بمراجعة النصوص وإعادة صياغتها بما يتناسب مع دليل الأس...

 

Process by which software is developed This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Software development process – news · newspapers · books · scholar · JSTOR (December 2010) (Learn how and when to remove this message) Part of a series onSoftware development Core activities Data modeling Processes Require...

 

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Silent Hill: Orphan – news · newspapers · books · scholar · JSTOR (February 2008) (Learn how and when to remove this message) 2007 video gameSilent Hill: OrphanCover of the third releaseDeveloper(s)Gamefederation StudioPublisher(s)KonamiDirector(s)Eirik Moseng&...

Trionfo della VirtùAutoreAndrea Mantegna Data1502 Tecnicatempera su tela Dimensioni160×192 cm UbicazioneLouvre, Parigi Il Trionfo della Virtù (o Minerva scaccia i Vizi dal giardino della Virtù) è un dipinto tempera su tela (160 × 192 cm) di Andrea Mantegna, completato nel 1502 e conservato oggi al Louvre di Parigi. Indice 1 Storia 2 Descrizione e stile 3 Note 4 Bibliografia 5 Voci correlate 6 Altri progetti Storia La tela fu la seconda della serie di decorazioni pittoriche per...

 

Indoor arena in Bulacan, Philippines Philippine ArenaLocationCiudad de Victoria, Bocaue, Bulacan, Philippines[note 1]Coordinates14°47′37″N 120°57′13″E / 14.79359°N 120.95354°E / 14.79359; 120.95354Public transit  5  North Luzon Express TerminalOwnerNew Era University (Iglesia ni Cristo)OperatorMaligaya Development CorporationRecord attendance55,000 (Eat Bulaga!: Sa Tamang Panahon, October 24, 2015)[2]Field size220 m × 17...