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:

Chips RaffertyRafferty pada 1943LahirJohn William Pilbean Goffage(1909-03-26)26 Maret 1909Broken Hill, New South Wales, AustraliaMeninggal27 Mei 1971(1971-05-27) (umur 62)Sydney, New South Wales, AustraliaMakamAbu ditabur ke lubang pemancingan kesayangannya di Lovett Bay, PittwaterPekerjaanPemeranTahun aktif1939–1971Suami/istriEllen Jameson (1941–1964; kematiannya) John William Pilbean Goffage MBE (26 Maret 1909 – 27 Mei 1971), yang lebih dikenal sebagai Chips R...

 

Miko di Kuil Ikuta. Miko (巫女code: ja is deprecated ) adalah istilah dalam agama Shinto[1] di Jepang, merujuk pada wanita kuil (jinja)[2] atau pendeta-wanita pendamping[3] yang dulu pernah dipandang sebagai dukun[4] tetapi dalam budaya Jepang modern pekerjaan tersebut dikenali sebagai peran secara adat[5] dalam kehidupan di kuil sehari-hari, terlatih untuk mengerjakan tugas mulai dari melakukan penyucian[6] hingga melakukan Kagura,[7]...

 

American politician Joseph Wilson ErvinMember of the U.S. House of Representativesfrom North Carolina's 10th districtIn officeJanuary 3, 1945 – December 25, 1945Preceded byCameron A. MorrisonSucceeded bySam Ervin Personal detailsBorn(1901-03-03)March 3, 1901Morganton, North Carolina, U.S.DiedDecember 25, 1945(1945-12-25) (aged 44)Washington, D.C., U.S.Political partyDemocraticAlma materUniversity of North Carolina at Chapel HillOccupationlawyer Joseph Wilson Ervin ...

For the military airport near Cocoa Beach, Florida assigned the ICAO code KXMR, see Cape Canaveral Air Force Station Skid Strip. Radio station in Bismarck, North DakotaKXMRBismarck, North DakotaBroadcast areaBismarck-MandanFrequency710 kHzBrandingFox Sports 710ProgrammingFormatSports/classic rockAffiliationsFox Sports RadioKFAN Radio NetworkMinnesota TwinsOwnershipOwneriHeartMedia, Inc.(iHM Licenses, LLC)Sister stationsKBMR, KFYR, KQDY, KSSS, KYYYHistoryFirst air dateJanuary 2002;&#...

 

محمد الجسر رئيس مجلس النواب اللبناني في المنصب18 أكتوبر 1927 – 10 مايو 1932 معلومات شخصية الميلاد سنة 1881   طرابلس  تاريخ الوفاة سنة 1934 (52–53 سنة)  الحياة العملية المهنة عالم مسلم،  وسياسي  تعديل مصدري - تعديل   محمد بن حسين بن محمد الجسر الصيادي الرفاعي سياسي لبنان...

 

American actor (born 1954) For The Lost Boys character, see Michael Emerson (character). Michael EmersonEmerson at the 2013 San Diego Comic-ConBorn (1954-09-07) September 7, 1954 (age 69)Cedar Rapids, Iowa, U.S.EducationDrake University (BA)University of Alabama (MFA)OccupationActorYears active1986–presentSpouse Carrie Preston ​(m. 1998)​ Michael Emerson (born September 7, 1954) is an American actor who is best known for his roles as Benjamin Linus on ...

American activist from Wisconsin For other people named Angela Walker, see Angela Walker (disambiguation). Angela Nicole WalkerWalker in 2015Personal detailsBorn (1974-01-19) January 19, 1974 (age 50)Milwaukee, Wisconsin, U.S.Political partySocialistGreen[1]EducationUniversity of North FloridaWebsiteCampaign WebsiteMilitary serviceAllegiance United StatesBranch/service United States ArmyUnit United States Army Reserve[2] Angela Nicole Walker (born January 19, 1...

 

Species of bacterium Thermus aquaticus Scientific classification Domain: Bacteria Phylum: Deinococcota Class: Deinococci Order: Thermales Family: Thermaceae Genus: Thermus Species: T. aquaticus Binomial name Thermus aquaticusBrock & Freeze, 1969 Thermus aquaticus is a species of bacteria that can tolerate high temperatures, one of several thermophilic bacteria that belong to the Deinococcota phylum. It is the source of the heat-resistant enzyme Taq DNA polymerase, one of the most imp...

 

Сельское поселение России (МО 2-го уровня)Новотитаровское сельское поселение Флаг[d] Герб 45°14′09″ с. ш. 38°58′16″ в. д.HGЯO Страна  Россия Субъект РФ Краснодарский край Район Динской Включает 4 населённых пункта Адм. центр Новотитаровская Глава сельского пос�...

Film by Alex Gibney Boom! Boom! The World Vs Boris BeckerOfficial release posterDirected byAlex GibneyScreenplay byAlex GibneyProduced by John Battsek Alex Gibney Erin Edeiken George Chignell Starring Barbara Becker Boris Becker Björn Borg Novak Djokovic John McEnroe Ion Tiriac Mats Wilander Edited by Michael J. Palmer Graeme Butler (co-editor) Music by Peter Nashell Eric V. Hachikian Productioncompanies Jigsaw Productions Ventureland Distributed byApple TV+Release dates 19 February...

 

Questa voce sull'argomento calciatori cecoslovacchi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Karel Bejbl Nazionalità  Cecoslovacchia Calcio Ruolo Attaccante Termine carriera 1935 CarrieraSquadre di club1 1925-1926 Vršovice? (?)1926-1927 Slavia Praga? (?)1927-1935 Bohemians? (?)Nazionale 1927-1931 Cecoslovacchia10 (10) 1 I due numeri indicano le presenze e le reti segnate, p...

 

Traditional embroidery style from Lucknow, India Traditional Chikankari hand-embroidery by Craft Artisans of India Chikankari (Urdu: چِکن کاری, Hindi: चिकन की कढ़ाई, चिकनकारी) is a traditional embroidery style from Lucknow, India. Translated, the word means embroidery (using thread or wire), and it is one of Lucknow's best known textile decoration styles. The main market in Lucknow for Chikankari based products is Chowk. Production is mainly based...

England men's national lacrosse team, 5th highest ranked lacrosse team internationally EnglandAssociationEnglish Lacrosse AssociationConfederationELF (Europe)Head coachDoug ShanahanWorld ChampionshipAppearances13 (first in 1967)Best resultRunner-ups (1974)Websitewww.englandlacrosse.co.uk Medal record World Lacrosse Championship 1974 Melbourne European Lacrosse Championships 1995 1996 1997 1999 Manchester 2000 Glasgow 2001 Cardiff 2004 Prague 2008 Lahti 2012 Amsterdam 2016 Budapest The England...

 

Part of a series onForced labour and slavery Contemporary Child labour Child soldiers Conscription Debt Forced marriage Bride buying Child marriage Wife selling Forced prostitution Human trafficking Peonage Penal labour Contemporary Africa 21st-century jihadism Sexual slavery Wage slavery Historical Antiquity Egypt Babylonia Greece Rome Medieval Europe Ancillae Black Sea slave trade Byzantine Empire Kholop Prague slave trade Serfs History In Russia Emancipation Thrall Venetian slave trade Ba...

 

Yokutsan language of California PalewyamiPoso Creek, AltininRegionSan Joaquin Valley, CaliforniaEthnicityYokutsExtinct1930s[1]Language familyYok-Utian ? YokutsanPalewyamiLanguage codesISO 639-3(included in Yokuts [yok])Glottologpale1254 Palewyami, also known as Altinin and Poso Creek Yokuts, was a Yokuts language of California.[2] Palewyami was spoken in Kern County, along Poso Creek. The language has not been spoken since the 1930s.[1] References ^ a b Victor Gol...

American architect Rebecca L. BinderBornNew Jersey, United StatesNationalityAmericanAlma materUniversity of California, Los AngelesOccupationArchitectPracticeR. L. Binder FAIA Architects Websitewww.binderarchitects.com Ackerman Union, UCLA Store Orthopaedic Hospital MMHS Kennedy High School (Los Angeles) Rebecca L. Binder is an American architect,[1] designer, and educator. She established R. L. Binder FAIA Architects, LLP, in 1979, in Playa del Rey, California.[2] In 199...

 

South Korean swimmer (born 2003) This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Hwang Sun-woo – news · newspapers · books · scholar · JSTOR (January 2024) (Learn how and when to remove this mes...

 

For the Australian television series, see Bride & Prejudice (TV series). 2004 filmBride and PrejudiceTheatrical release posterDirected byGurinder ChadhaWritten by Paul Mayeda Berges Gurinder Chadha Based onPride and Prejudiceby Jane AustenProduced by Gurinder Chadha Deepak Nayar Starring Aishwarya Rai Martin Henderson Daniel Gillies Nadira Babbar Anupam Kher Naveen Andrews Indira Varma Namrata Shirodkar Sonali Kulkarni CinematographySantosh SivanEdited byJustin KrishMusic byAnu MalikProdu...

Civilian internment camp in Hong Kong Stanley Internment Camp赤柱拘留營Internment campOne of the former internees looks at Stanley Internment CampCoordinates22°12′57″N 114°13′00″E / 22.2158°N 114.21661°E / 22.2158; 114.21661LocationStanley, Hong KongOperated byJapanOriginal useSchool and prisonOperationalJanuary 1942 (1942-01) - 16 August 1945 (1945-08-16)InmatesNon-Chinese civiliansNumber of inmates2,800 Stanley Internment Camp (Ch...

 

English classical scholar (1759–1808) Richard Porson, after a picture by John Hoppner Portrait of Richard Porson, 1830 Richard Porson (25 December 1759 – 25 September 1808) was an English classical scholar. He was the discoverer of Porson's Law. The Greek typeface Porson was based on his handwriting. Early life Richard Porson was born at East Ruston, near North Walsham, Norfolk, the eldest son of Huggin Porson, parish clerk. His mother was the daughter of a shoemaker from the neighbouring...