Search tree

In computer science, a search tree is a tree data structure used for locating specific keys from within a set. In order for a tree to function as a search tree, the key for each node must be greater than any keys in subtrees on the left, and less than any keys in subtrees on the right.[1]

The advantage of search trees is their efficient search time given the tree is reasonably balanced, which is to say the leaves at either end are of comparable depths. Various search-tree data structures exist, several of which also allow efficient insertion and deletion of elements, which operations then have to maintain tree balance.

Search trees are often used to implement an associative array. The search tree algorithm uses the key from the key–value pair to find a location, and then the application stores the entire key–value pair at that particular location.

Types of trees

Binary search tree
Binary search tree

Binary search tree

A Binary Search Tree is a node-based data structure where each node contains a key and two subtrees, the left and right. For all nodes, the left subtree's key must be less than the node's key, and the right subtree's key must be greater than the node's key. These subtrees must all qualify as binary search trees.

The worst-case time complexity for searching a binary search tree is the height of the tree, which can be as small as O(log n) for a tree with n elements.

B-tree

B-trees are generalizations of binary search trees in that they can have a variable number of subtrees at each node. While child-nodes have a pre-defined range, they will not necessarily be filled with data, meaning B-trees can potentially waste some space. The advantage is that B-trees do not need to be re-balanced as frequently as other self-balancing trees.

Due to the variable range of their node length, B-trees are optimized for systems that read large blocks of data, they are also commonly used in databases.

The time complexity for searching a B-tree is O(log n).

(a,b)-tree

An (a,b)-tree is a search tree where all of its leaves are the same depth. Each node has at least a children and at most b children, while the root has at least 2 children and at most b children.

a and b can be decided with the following formula:[2]

The time complexity for searching an (a,b)-tree is O(log n).

Ternary search tree

A ternary search tree is a type of tree that can have 3 nodes: a low child, an equal child, and a high child. Each node stores a single character and the tree itself is ordered the same way a binary search tree is, with the exception of a possible third node.

Searching a ternary search tree involves passing in a string to test whether any path contains it.

The time complexity for searching a balanced ternary search tree is O(log n).

Searching algorithms

Searching for a specific key

Assuming the tree is ordered, we can take a key and attempt to locate it within the tree. The following algorithms are generalized for binary search trees, but the same idea can be applied to trees of other formats.

Recursive

search-recursive(key, node)
    if node is NULL
        return EMPTY_TREE
    if key < node.key
        return search-recursive(key, node.left)
    else if key > node.key
        return search-recursive(key, node.right)
    else
        return node

Iterative

searchIterative(key, node)
    currentNode := node
    while currentNode is not NULL
        if currentNode.key = key
            return currentNode
        else if currentNode.key > key
            currentNode := currentNode.left
        else
            currentNode := currentNode.right

Searching for min and max

In a sorted tree, the minimum is located at the node farthest left, while the maximum is located at the node farthest right.[3]

Minimum

findMinimum(node)
    if node is NULL
        return EMPTY_TREE
    min := node
    while min.left is not NULL
        min := min.left
    return min.key

Maximum

findMaximum(node)
    if node is NULL
        return EMPTY_TREE
    max := node
    while max.right is not NULL
        max := max.right
    return max.key

See also

References

  1. ^ Black, Paul and Pieterse, Vreda (2005). "search tree". Dictionary of Algorithms and Data Structures
  2. ^ Toal, Ray. "(a,b) Trees"
  3. ^ Gildea, Dan (2004). "Binary Search Tree"

Read other articles:

Opera by Bedřich Smetana You can help expand this article with text translated from the corresponding article in Czech. (March 2024) Click [show] for important translation instructions. Machine translation, like DeepL or Google Translate, is a useful starting point for translations, but translators must revise errors as necessary and confirm that the translation is accurate, rather than simply copy-pasting machine-translated text into the English Wikipedia. Do not translate text that ap...

 

Boeing 707 Boeing 707-321B milik maskapai Pan American World Airways Jenis Pesawat jet berbadan sempit Negara asal Amerika Serikat Pembuat Boeing Commercial Airplanes Penerbangan perdana 20 Desember 1957; 66 tahun lalu (1957-12-20)[1] Pengenalan 26 Oktober 1958; 65 tahun lalu (1958-10-26), oleh Pan Am Status Tidak beroperasi dan aktif sebagai pesawat militer [a] Pengguna utama Pan Am(telah pensiun)Trans World Airlines(telah pensiun)American Airlines(telah pensi...

 

Voce principale: Associazione Calcio Cesena. Associazione Calcio CesenaStagione 2008-2009Sport calcio Squadra Cesena Allenatore Pierpaolo Bisoli All. in seconda Giuseppe Angelini Presidente Igor Campedelli Lega Pro Prima Divisione1º (in Serie B) Coppa ItaliaSecondo turno Coppa Italia Lega ProSecondo turno Supercoppa di Lega di Prima DivisioneFinalista Maggiori presenzeCampionato: Motta (34)Totale: Motta (39) Miglior marcatoreCampionato: Motta (14)Totale: Motta (15) StadioStadio Dino Ma...

Voce principale: Associazione Sportiva Lucchese Libertas 1905. Associazione Sportiva Lucchese LibertasStagione 1998-1999Sport calcio Squadra Lucchese Allenatore Tarcisio Burgnich (1ª-6ª) Giuseppe Papadopulo (7ª-27ª) Tarcisio Burgnich (28ª-38ª) Presidente Egiziano Maestrelli Serie B19º posto (retrocessa in Serie C1) Coppa ItaliaSecondo turno Maggiori presenzeCampionato: Colacone (38) Miglior marcatoreCampionato: Tarantino (8) StadioStadio Porta Elisa 1997-1998 1999-2000 Si invita ...

 

2006 single by Keane 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: Crystal Ball Keane song – news · newspapers · books · scholar · JSTOR (February 2013) (Learn how and when to remove this message) Crystal BallSingle by Keanefrom the album Under the Iron Sea B-sideMaybe I Can ChangeThe Iron Sea: Magic ...

 

Crazy TaxiDéveloppeur HitmakerÉditeur SegaDate de sortie 1999Genre CourseMode de jeu Un joueurPlate-forme Dreamcast, GameCube, Naomi, PC, PlayStation 2, PlayStation 3, Xbox 360, Android, iOSLangue AnglaisÉvaluation ELSPA : 11-14ESRB : T ?OFLC (AU) : G ?Crazy Taxi-Crazy Taxi 2modifier - modifier le code - modifier Wikidata Crazy Taxi est un jeu vidéo développé par Hitmaker et édité par Sega, sorti en arcade sur Naomi en 1999 et sur Dreamcast le 24 janvier 2000, puis par ...

Agneta EkmannerLahir4 Desember 1938 (umur 85)Stockholm, SwediaPekerjaanPemeranTahun aktif1965-kini Agneta Ekmanner (lahir 4 Desember 1938) adalah seorang pemeran asal Swedia.[1] Ia tampil dalam lebih dari 50 film dan acara televisi sejak 1965. Filmografi pilihan Love 65 (1965) Hugs and Kisses (1967) The Corridor (1968) Per (1975) Paradise Place (1977) The Mozart Brothers (1986) Lethal Film (1988) Svart Lucia (1992) Murder at the Savoy (1993) Roseanna (1993) The Fire Engine ...

 

سفارة المملكة المتحدة في إيطاليا المملكة المتحدة إيطاليا الإحداثيات 41°54′30″N 12°30′05″E / 41.90823°N 12.50126°E / 41.90823; 12.50126 البلد إيطاليا[1]  المكان البلدية الأولى [الإنجليزية]‏ الاختصاص إيطاليا،  وسان مارينو[2]  الموقع الالكتروني الموقع الرسمي تعدي...

 

For the era in American politics, see Fourth Party System. For the visual effects studio, see 4th Creative Party. The Fourth Party Churchill, Balfour, Drummond-Wolff and Gorst as caricatured by Spy (Leslie Ward) in Vanity Fair, December 1880 The Fourth Party was an informal label given to four British MPs, Lord Randolph Churchill, Henry Drummond Wolff, John Gorst and Arthur Balfour, who gained national attention by acting together in the 1880–1885 parliament. They attacked what they saw as ...

Government of the United Kingdom First Wilson ministry and second Wilson ministry redirect here. For the ministries of premier Frank Wilson, see first Wilson ministry (Western Australia) and second Wilson ministry (Western Australia). Wilson ministriesCabinet of the United Kingdom1964–19661966–1970Wilson (1964)Date formedFirst: 16 October 1964 (1964-10-16)Second: 31 March 1966 (1966-03-31)Date dissolvedFirst: 31 March 1966 (1966-03-31)Second: 1...

 

齐同生(1952年7月—),男,汉族,河北平山人。1968年11月参加工作,1984年11月加入中国共产党,甘肃工业大学五系化工机械专业毕业,大学普通班学历。现任宁夏回族自治区十届政协主席。 简历 1968年11月至1985年9月,在平罗县崇岗公社、石炭井矿务局大武口总机修厂、甘肃工业大学、宁夏化工设计院等单位插队、学习、工作。 1985年9月至1994年,历任宁夏工业设计院副院长�...

 

Graphical system analysis method An example block diagram, showing the Microsoft Windows 2000 operating system architecture. A block diagram is a diagram of a system in which the principal parts or functions are represented by blocks connected by lines that show the relationships of the blocks.[1] They are heavily used in engineering in hardware design, electronic design, software design, and process flow diagrams. Block diagrams are typically used for higher level, less detailed desc...

Norwegian painter Adolph TidemandPortrait by Julius Roeting, 1860Born(1814-08-14)14 August 1814Mandal, Vest-Agder, NorwayDied8 August 1876(1876-08-08) (aged 61)Christiania, United Kingdoms of Sweden and NorwayNationalityNorwegianEducationKunstakademie DüsseldorfKnown forPaintingNotable workBridal Procession on the HardangerfjordMovementNorwegian romantic nationalism Adolph Tidemand by G. & A. Overbeck (firm), c. 1868 Adolph Tidemand (14 August 1814 – 8 August 187...

 

PlayStation ClassicKonsol PlayStation Classic dan kontrolernyaPengembangSony Interactive EntertainmentPembuatSony ElectronicsKeluarga produkPlayStationJenisKonsol terdedikasiTanggal rilisWW: 3 Desember 2018; 5 tahun lalu (2018-12-03)Harga perkenalanUS$99,99€99,99¥9.980GB£89,99A$149,99CAD129,99MediaInternal flash memorySistem operasiPCSX ReArmedCPUQuad-Core ARM Cortex-A35Kapasitas penyimpanan16 GB eMMC FlashMemori1 GB DDR3 RAMGrafisPower VR GE8300Masukan pengontrol2 port kon...

 

1st century Roman senator, consul and governor Quintus Julius Cordinus Gaius Rutilius GallicusConsul of the Roman RepublicIn officeSeptember 70 – October 70Preceded byGaius Licinius Mucianus with Quintus Petillius CerialisSucceeded byLucius Annius Bassus with Gaius Laecanius Bassus Caecina PaetusIn officeMarch 85 – April 85Serving with Lucius Valerius Catullus MessalinusPreceded byDomitian with Titus Aurelius FulvusSucceeded byMarcus Arrecinus Clemens with Lucius...

Giuseppe Lazzati Deputato dell'Assemblea CostituenteGruppoparlamentareDemocratico Cristiano CollegioIV (Milano) Sito istituzionale Deputato della Repubblica ItalianaLegislaturaI GruppoparlamentareDemocratico cristiano CollegioMilano Incarichi parlamentari membro della VI commissione istruzione e belle arti (27 gennaio 1950 - 24 giugno 1953) membro della IX commissione agricoltura e alimentazione (15 giugno 1948 - 27 gennaio 1950) membro della commissione speciale per l'esame del disegno ...

 

Mountain in Uttarakhand, India For Kemet, see Ancient Egypt. For the written Hebrew character vowel form markup, see Romanization of Hebrew. कामेत पर्वत KametKemetKametHighest pointElevation7,756 m (25,446 ft)[1]Ranked 29thProminence2,825 m (9,268 ft)[1]Ranked 121stListingUltra Mountains of UttarakhandCoordinates30°55′12″N 79°35′30″E / 30.92000°N 79.59167°E / 30.92000; 79.59167[1]Geography...

 

Hindu temple in Siem Reap, Cambodia Preah PithuPrasat Preah PithuTemple X of Preah PithuReligionAffiliationHinduismProvinceSiem ReapLocationLocationAngkor ThomCountryCambodiaLocation in CambodiaGeographic coordinates13°26′56″N 103°51′41″E / 13.44889°N 103.86139°E / 13.44889; 103.86139ArchitectureTypeKhmer (Angkor Wat style modified to post-Bayon style)CreatorSuryavarman II, Jayavarman VIIICompleted12th to 13th centuryTemple(s)5 Plan of Preah Pithu temples P...

Bundesliga 1983/84 Meister VfB Stuttgart Europapokal derLandesmeister VfB Stuttgart UEFA-Pokal Hamburger SV Bor. M’gladbach Werder Bremen 1. FC Köln Pokalsieger FC Bayern München Europapokal derPokalsieger FC Bayern München Relegation ↓ Eintracht Frankfurt (5:0 und 1:1 gegen MSV Duisburg) Absteiger Kickers Offenbach 1. FC Nürnberg Mannschaften 18 Spiele 306 + 2 Relegationsspiele Tore 1.097 (ø 3,58 pro Spiel) Zuschauer 6.307.967 (ø 20.614 ...

 

Aeropuerto Internacional de São Paulo-Guarulhos Aeroporto Internacional de São Paulo/Guarulhos – Governador André Franco Montoro IATA: GRU OACI: SBGR FAA: LocalizaciónUbicación Guarulhos, BrasilElevación 750Sirve a São PauloDetalles del aeropuertoTipo PúblicoOperador Infraero y GRU AirportServicios y conexionesHub para Gol Linhas AéreasLATAM BrasilBase para Azul Linhas Aéreas BrasileirasEstadísticas (2018)Movimiento de pasajeros 42 881 981Operaciones aéreas 292 81...