Share to: share facebook share twitter share wa share telegram print page

Self-balancing binary search tree

An example of an unbalanced tree; following the path from the root to a node takes an average of 3.27 node accesses
The same tree after being height-balanced; the average path effort decreased to 3.00 node accesses

In computer science, a self-balancing binary search tree (BST) is any node-based binary search tree that automatically keeps its height (maximal number of levels below the root) small in the face of arbitrary item insertions and deletions.[1] These operations when designed for a self-balancing binary search tree, contain precautionary measures against boundlessly increasing tree height, so that these abstract data structures receive the attribute "self-balancing".

For height-balanced binary trees, the height is defined to be logarithmic in the number of items. This is the case for many binary search trees, such as AVL trees and red–black trees. Splay trees and treaps are self-balancing but not height-balanced, as their height is not guaranteed to be logarithmic in the number of items.

Self-balancing binary search trees provide efficient implementations for mutable ordered lists, and can be used for other abstract data structures such as associative arrays, priority queues and sets.

Overview

Tree rotations are very common internal operations on self-balancing binary trees to keep perfect or near-to-perfect balance.

Most operations on a binary search tree (BST) take time directly proportional to the height of the tree, so it is desirable to keep the height small. A binary tree with height h can contain at most 20+21+···+2h = 2h+1−1 nodes. It follows that for any tree with n nodes and height h:

And that implies:

.

In other words, the minimum height of a binary tree with n nodes is log2(n), rounded down; that is, .[1]

However, the simplest algorithms for BST item insertion may yield a tree with height n in rather common situations. For example, when the items are inserted in sorted key order, the tree degenerates into a linked list with n nodes. The difference in performance between the two situations may be enormous: for example, when n = 1,000,000, the minimum height is .

If the data items are known ahead of time, the height can be kept small, in the average sense, by adding values in a random order, resulting in a random binary search tree. However, there are many situations (such as online algorithms) where this randomization is not viable.

Self-balancing binary trees solve this problem by performing transformations on the tree (such as tree rotations) at key insertion times, in order to keep the height proportional to log2(n). Although a certain overhead is involved, it is not bigger than the always necessary lookup cost and may be justified by ensuring fast execution of all operations.

While it is possible to maintain a BST with minimum height with expected time operations (lookup/insertion/removal), the additional space requirements required to maintain such a structure tend to outweigh the decrease in search time. For comparison, an AVL tree is guaranteed to be within a factor of 1.44 of the optimal height while requiring only two additional bits of storage in a naive implementation.[1] Therefore, most self-balancing BST algorithms keep the height within a constant factor of this lower bound.

In the asymptotic ("Big-O") sense, a self-balancing BST structure containing n items allows the lookup, insertion, and removal of an item in worst-case time, and ordered enumeration of all items in time. For some implementations these are per-operation time bounds, while for others they are amortized bounds over a sequence of operations. These times are asymptotically optimal among all data structures that manipulate the key only through comparisons.

Implementations

Data structures implementing this type of tree include:

Applications

Self-balancing binary search trees can be used in a natural way to construct and maintain ordered lists, such as priority queues. They can also be used for associative arrays; key-value pairs are simply inserted with an ordering based on the key alone. In this capacity, self-balancing BSTs have a number of advantages and disadvantages over their main competitor, hash tables. One advantage of self-balancing BSTs is that they allow fast (indeed, asymptotically optimal) enumeration of the items in key order, which hash tables do not provide. One disadvantage is that their lookup algorithms get more complicated when there may be multiple items with the same key. Self-balancing BSTs have better worst-case lookup performance than most[2] hash tables ( compared to ), but have worse average-case performance ( compared to ).

Self-balancing BSTs can be used to implement any algorithm that requires mutable ordered lists, to achieve optimal worst-case asymptotic performance. For example, if binary tree sort is implemented with a self-balancing BST, we have a very simple-to-describe yet asymptotically optimal sorting algorithm. Similarly, many algorithms in computational geometry exploit variations on self-balancing BSTs to solve problems such as the line segment intersection problem and the point location problem efficiently. (For average-case performance, however, self-balancing BSTs may be less efficient than other solutions. Binary tree sort, in particular, is likely to be slower than merge sort, quicksort, or heapsort, because of the tree-balancing overhead as well as cache access patterns.)

Self-balancing BSTs are flexible data structures, in that it's easy to extend them to efficiently record additional information or perform new operations. For example, one can record the number of nodes in each subtree having a certain property, allowing one to count the number of nodes in a certain key range with that property in time. These extensions can be used, for example, to optimize database queries or other list-processing algorithms.

See also

References

  1. ^ a b c Donald Knuth. The Art of Computer Programming, Volume 3: Sorting and Searching, Second Edition. Addison-Wesley, 1998. ISBN 0-201-89685-0. Section 6.2.3: Balanced Trees, pp.458–481.
  2. ^ Cuckoo hashing provides worst-case lookup performance of .

Read other articles:

جامعة مكة المكرمة المفتوحة شعار جامعة مكة المكرمة المفتوحة معلومات التأسيس 2007 النوع خاصة، مفتوحة تكاليف الدراسة الدبلوم العالي للدراسات الإسلامية 1066 $ دولار. الدراسة كاملة للماجستير :6666$ دولار. الدراسة كاملة للدكتوراه : 8000$ دولار. التسجيل : 135$ دولار. التوجهات الدراسية ا

Sungai MamberamoLokasiNegara IndonesiaCiri-ciri fisikHulu sungaiPuncak Mandala Muara sungaiSamudera Pasifik - koordinat1°27′57″S 137°54′01″E / 1.465833°S 137.900278°E / -1.465833; 137.900278Koordinat: 1°27′57″S 137°54′01″E / 1.465833°S 137.900278°E / -1.465833; 137.900278Panjang1102 kmDebit air  - rata-rata4.580 m³/detik Daerah Aliran SungaiSistem sungaiDAS Mamberamo[1]Kode DASDAS740064…

Región de GießenGießen Regierungsbezirk Escudo Mapa resaltado de la región en Alemania.Coordenadas 50°40′N 8°40′E / 50.67, 8.67Capital GießenEntidad Regierungsbezirk • País  Alemania • Land HesseSuperficie   • Total 5381,14 km²Altitud   • Media 274 m s. n. m.Población (30 de septiembre de 2006)   • Total 1 061 444 hab. • Densidad 197 hab/km² Sitio web oficial [editar datos en Wik…

Опис файлу Опис Логотип Футбольної ліги Греції, колишньої Бета Етнікі Джерело http://www.epae.org/default.fds?langid=1 Час створення 2010 Автор зображення Футбольна ліга (Греція) Ліцензія див. нижче Ліцензування Це логотип (емблема) організації, товару, або заходу, що перебуває під захистом ав…

Papan selamat datang di Kawasan Bebas Sabang Kawasan Perdagangan Bebas dan Pelabuhan Bebas Indonesia adalah sebuah kawasan perdagangan dan pelabuhan yang berada dalam wilayah Indonesia yang di dalamnya terjadi proses penggudangan barang, handling, kegiatan manufaktur serta kegiatan reekspor tanpa hambatan oleh otoritas kepabeanan.[1] Di dalam Kawasan Bebas diperlakukan kebijakan melalui penghapusan atas rezim bea dan cukai berikut halangan non-tarif serta pajak pada perdagangan internasi…

Stasiun Rikuchū-Orii陸中折居駅Stasiun Rikuchū-Orii pada Mei 2013LokasiMizusawa-ku Shinjo-aze, Ōshū-shi, Iwate-ken 023-0841JepangKoordinat39°05′39″N 141°08′27″E / 39.0942°N 141.1407°E / 39.0942; 141.1407Koordinat: 39°05′39″N 141°08′27″E / 39.0942°N 141.1407°E / 39.0942; 141.1407Pengelola JR EastJalur■ Jalur Utama TōhokuLetak dari pangkal465.1 km dari TokyoJumlah peron2 peron sampingJumlah jalur2Informasi lainStatu…

Bob HolnessLahirRobert Wentworth John HolnessMeninggal6 Januari 2012(2012-01-06) (umur 83)PekerjaanAktor, pembawa acara, penyiar radio Robert Wentworth John Holness (alias Bob Holness, 12 November 1928 – 6 Januari 2012) merupakan seorang aktor dan presenter serta penyiar radio asal Inggris. Singkatnya setelah ia lahir di Afsel, ia beserta kedua orang tuanya pindah ke Ashford, Kent, Inggris. Ia lantas bersekolah di The Norton Knatchbull School, dan kemudian dilanjutkan dengan…

Удмуртський державний університетУдГУ 56°51′02″ пн. ш. 53°13′26″ сх. д. / 56.850555555583774492° пн. ш. 53.22388888891677539° сх. д. / 56.850555555583774492; 53.22388888891677539Координати: 56°51′02″ пн. ш. 53°13′26″ сх. д. / 56.850555555583774492° пн. ш. 53.22388888891677539° сх. д.&#x…

Behrste (plattdeutsch Beeß) ist ein kleiner Ortsteil der Gemeinde Estorf im niedersächsischen Landkreis Stade. Zu Behrste gehören die beiden kleineren Ansiedlungen Forst und Hude. Behrste BeeßVorlage:Infobox Ortsteil einer Gemeinde in Deutschland/Wartung/Alternativname Gemeinde Estorf Wappen von Behrste Koordinaten: 53° 32′ N, 9° 12′ O53.5386759.194527Koordinaten: 53° 32′ 19″ N, 9° 11′ 40″ O Fläche: 5,83 km² Einwohner: …

Seweryn Wysłouch Seweryn Wysłouch (March 19, 1900 in Pirkowicze near Drohiczyn – February 28, 1968 in Wrocław) was a legal historian and vice-rector of Wrocław University. Biography Seweryn was born in Pirkowicze near Drohiczyn (Polesie, Poland), the Wysłouch family manor. In 1927 he graduated from the School of Law and Social Sciences of the Stefan Batory University in Vilnius and began to work there as an academic. His career was interrupted by the outbreak of the Second World War, …

坐标:54°1′S 38°3′W / 54.017°S 38.050°W / -54.017; -38.050 伯德島是大西洋的島嶼,屬於南喬治亞群島的一部分,長4.8公里、寬0.8公里,面積3.4平方公里,最高點海拔高度356米,由英國探險家詹姆斯·庫克在1775年1月14日發現,島上人口僅4人。 外部連結 BAS Bird Island page(页面存档备份,存于互联网档案馆) Map(页面存档备份,存于互联网档案馆) 这是一篇與英國地…

Finnish football club Football clubLaajasalon PalloseuraFull nameLaajasalon PalloseuraNickname(s)LPSFounded1978; 45 years ago (1978)StadiumReilusti parempi Saari areenaChairmanTimo ViheriärantaHead CoachNiko RuuthCoachNiko RuuthLeagueKolmonen20216th – Kolmonen (Group B)WebsiteClub website Home colours Away colours Laajasalon Palloseura (abbreviated LPS) is a football club from Laajasalo, Helsinki in Finland. The club was formed in 1978 and their home ground is at the La…

Artis Marina Abramovic pada tahun 2012 Rhythm 0 adalah sebuah pertunjukan karya seni selama enam jam yang diciptakan oleh seniman Serbia Marina Abramović di Naples pada tahun 1974.[1] Karya ini melibatkan Abramović sendiri dengan berdiri diam, sementara penonton diundang untuk melakukan apa pun yang mereka inginkan padanya, dengan menggunakan salah satu dari 72 objek yang telah ditempatkan di atas meja. Objek-objek tersebut termasuk mawar, bulu, parfum, madu, roti, anggur, gunting, pis…

Nama ini menggunakan cara penamaan Spanyol: nama keluarga pertama atau paternalnya adalah González dan nama keluarga kedua atau maternalnya adalah Galeano. Derlis González Informasi pribadiNama lengkap Derlis Alberto González GaleanoTanggal lahir 23 Maret 1994 (umur 29)Tempat lahir Mariano Roque Alonso, ParaguayTinggi 1,72 m (5 ft 7+1⁄2 in)Posisi bermain Striker / WingerInformasi klubKlub saat ini BaselNomor 25Karier junior2008–2010 Rubio Ñu2012 BenficaKarier…

American politician from Colorado Kyle MullicaMember of the Colorado Senatefrom the 24th districtIncumbentAssumed office January 9, 2023Preceded byFaith WinterMember of the Colorado House of Representativesfrom the 34th districtIn officeJanuary 4, 2019 – January 9, 2023Preceded byAlexander WinklerSucceeded byJenny Willford Personal detailsBorn (1986-07-31) July 31, 1986 (age 37)Political partyDemocratic Kyle Alan John Mullica (born July 31, 1986) is an American po…

Painting by Gustave Courbet Self-Portrait with a Black DogArtistGustave CourbetYear1842-1844MediumOil on canvasDimensions46.3 cm × 55.5 cm (18.2 in × 21.9 in)LocationPetit Palais, Paris Self-Portrait with a Black Dog, Portrait of the Artist or Courbet with a Black Dog (French: Courbet au chien noir) is an 1842 oil-on-canvas painting by the French artist Gustave Courbet, retouched by the artist in 1844. It is now in the Petit Palais in Paris. History Th…

Finnish actress and writer Kiti KokkonenKiti Kokkonen at Helsinki Book Fair in 2012Born (1974-10-04) 4 October 1974 (age 49)Helsinki, Finland Kiti Karoliina Kokkonen (born 4 October 1974 in Helsinki, Finland) is a Finnish film and television actress, voice actress and writer.[1][2] She has been the artistic director of Suomen Komediateatteri [fi] (Finnish Comedy Theatre) since February 2010.[3] She is the daughter of film director Ere Kokkonen and actres…

2009 French horror film This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) 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: High Lane film – news · newspapers · books · scholar · JSTOR (March 2014) (Learn …

American religious leader SheikhE. Mealy ElMealy El, circa 1928.1st Grand Sheik of theMoorish Science Temple of America(Mealy El faction)Appointed byNoble Drew AliPreceded byPosition established Personal detailsBornEdward MealySeptember 17, 1870Wilkerson, Mississippi, United StatesDied1935 (aged 64–65)SpouseDealia Mealy El Edward Mealy El (born Edward Mealy; September 17, 1870 – 1935), often known as E. Mealy El, was an American religious leader who was Noble Drew Ali's successor as…

1922 film by Victor Fleming Red Hot RomanceMakeup test during production. Writers Emerson and Loos at left, director Fleming seated, and Sydney and Collins at right.[1]Directed byVictor FlemingWritten byJohn EmersonAnita LoosProduced byJohn EmersonAnita LoosStarringBasil SydneyCinematographyOliver T. MarshErnest G. PalmerDistributed byAssociated First NationalRelease date February 13, 1922 (1922-02-13) Running time60 minutesCountryUnited StatesLanguageSilent (English inter…

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 3.135.207.200