Ternary tree

A simple ternary tree of size 10 and height 2.

In computer science, a ternary tree is a tree data structure in which each node has at most three child nodes, usually distinguished as "left", “mid” and "right". Nodes with children are parent nodes, and child nodes may contain references to their parents. Outside the tree, there is often a reference to the "root" node (the ancestor of all nodes), if it exists. Any node in the data structure can be reached by starting at root node and repeatedly following references to either the left, mid or right child.

Ternary trees are used to implement Ternary search trees and Ternary heaps.

Definition

  • Directed Edge - The link from the parent to the child.
  • Root - The node with no parents. There is at most one root node in a rooted tree.
  • Leaf Node - Any node that has no children.
  • Parent Node - Any node connected by a directed edge to its child or children.
  • Child Node - Any node connected to a parent node by a directed edge.
  • Depth - Length of the path from the root to the node. The set of all nodes at a given depth is sometimes called a level of the tree. The root node is at depth zero.
  • Height - Length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a height of zero. In the example diagram, the tree has height of 2.
  • Sibling - Nodes that share the same parent node.
  • A node p is an ancestor of a node q if it exists on the path from q to the root. The node q is then termed a descendant of p.
  • The size of a node is the number of descendants it has, including itself.

Properties of ternary trees

  • Maximum number of nodes

– Let be height of a ternary tree.

– Let be the maximum number of nodes in a ternary tree of height h

h M(h)
0 1
1 4
2 13
3 40

– Every tree of height h has at most nodes.

  • If a node occupies TREE , then its Left Child is stored in TREE .
  • Mid Child is stored in TREE .
  • Right Child is stored in TREE .

Common operations

Insertion

Nodes can be inserted into ternary trees in between three other nodes or added after an external node. In Ternary trees, a node that is inserted is specified as to which child it is.

External nodes

Say that the external node being added onto is node A. To add a new node after node A, A assigns the new node as one of its children and the new node assigns node A as its parent.

Internal nodes

Insertion on internal nodes is more complex than on external nodes. Say that the internal node is node A and that node B is the child of A. (If the insertion is to insert a right child, then B is the right child of A, and similarly with a left child insertion or mid child.) A assigns its child to the new node and the new node assigns its parent to A. Then the new node assigns its child to B and B assigns its parent as the new node.

Deletion

Deletion is the process whereby a node is removed from the tree. Only certain nodes in a ternary tree can be removed unambiguously.

Node with zero or one child

Say that the node to delete is node A. If a node has no children (external node), deletion is accomplished by setting the child of A's parent to null and A's parent to null. If it has one child, set the parent of A's child to A's parent and set the child of A's parent to A's child.

Comparison with other trees

The picture below is a binary search tree that represents 12 two-letter words. All nodes on the left child have smaller values, while all nodes on the right child have greater values for all nodes. A search starts from the root. To find the word "ON", we compare it to "IN" and take the right branch. Every comparison could access each character of both words.

        in
      /    \
     be    of
    /  \  /  \
   as  by is  or
    \   \  \  / \
    at  he it on to 

Digital search tries to store strings character by character. The next picture is a tree that represents the same set of 12 words;

         _ _ _ _ _ _ _ _ _ _ _ _ _ 
        /     /    / \       \     \
       /     /    /   \       \     \
      a     b    h     i       o     t
     / \   / \   |   / | \    /|\    |
    s  t  e   y  e  n  s  t  f n r   o
   as at be  by he in is it of on or to

each input word is shown beneath the node that represents it. In a tree representing words of lower case letters, each node has 26-way branching. Searches are very fast: A search for "IS" starts at the root, takes the "I" branch, then the "S" branch, and ends at the desired node. At every node, one accesses an array element, tests for null, and takes a branch.

                    i
              /     |    \
             /      |     \
            b       s      o
         / |  \    / \    |  \
        a  e   h  n   t   n   t
        |   \  |         / \  |
        s    y e        f  r  o
         \
          t

The above picture is a balanced ternary search tree for the same set of 12 words. The low and high pointers are shown as angled lines, while equal pointers are shown as vertical lines. A search for the word "IS" starts at the root, proceeds down the equal child to the node with value "S", and stops there after two comparisons. A search for "AX" makes three comparisons to the first letter "A" and two comparisons to the second letter "X" before reporting that the word is not in the tree.[1]

Examples of ternary trees

See also

References

  1. ^ Jon Bentley and Bob Sedgewick (1998), Dr. Dobb's Journal
  2. ^ Price, H. Lee (2008). "The Pythagorean Tree: A New Species". arXiv:0809.4324 [math.HO].

Read other articles:

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Desember 2022. Mariam al-MansouriNama asalمريم حسن سالم المنصوريي[1]LahirJanuari 1979 (umur 45)Abu DhabiAlmamaterUniversitas Uni Emirat Arab[1] Khalifa bin Zayed Air CollegePekerjaanAU UEA Pilot tempurDikenal atasPi...

 

For other books, see Changeling (disambiguation) § Books. The Changelings AuthorJo SinclairCover artistRichard M. PowersCountryUnited StatesLanguageEnglishGenreBildungsroman, Jewish American literature,PublisherMcGraw HillPublication date1955Media typePrint (Paperback)Pages323 pp The Changelings is a novel by Jo Sinclair (Ruth Seid) first published in 1955 by McGraw Hill. Features tomboy protagonist Judith Vincent Vincent, a 12-year-old who is the newly deposed leader of a gan...

 

Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber: Jesús Manuel Corona – berita · surat kabar · buku · cendekiawan · JSTOR Jesús Manuel Corona Piala Dunia Antarklub FIFA 2012Informasi pribadiNama lengkap Jesús Manuel CoronaTanggal lahir 6 Januari 1993...

Kirati Keawsombat Mei 2016Informasi pribadiNama lengkap Kirati KeawsombatTanggal lahir 12 Januari 1987 (umur 37)Tempat lahir Nan, ThailandTinggi 1,80 m (5 ft 11 in)Posisi bermain PenyerangKarier junior Assumption Thonburi CollegeKarier senior*Tahun Tim Tampil (Gol)2007–2008 Army United 34 (9)2009 TOT FC 20 (4)2010–2012 Buriram PEA 38 (8)2012 Wuachon United 19 (7)2013–2016 PTT Rayong 49 (17)2015 → Chonburi (Pinjaman) 10 (6)2016 Khon Kaen United 9 (5)2017–2018 Nak...

 

Betty BlytheBlythe, c. 1920LahirElizabeth Blythe Slaughter(1893-09-01)1 September 1893Los Angeles, California, A.S.Meninggal7 April 1972(1972-04-07) (umur 78)Woodland Hills, Los Angeles, California, A.S.PekerjaanAktrisTahun aktif1916–1964Suami/istriPaul Scardon ​ ​(m. 1919; meninggal 1954)​ Betty Blythe (nee Elizabeth Blythe Slaughter;[1] 1 September 1893 – 7 April 1972) adalah seorang aktris Amerika yang ter...

 

Ligne Chūō-Sōbu Ligne de Mitaka à Chiba Carte de la ligne Une automotrice série E231-500 sur la ligne Chūō-Sōbu Pays Japon Villes desservies Tokyo, Chiba Historique Mise en service 1932 Caractéristiques techniques Longueur 60,2 km Écartement étroit (1 067 mm) Électrification 1500 V continu Nombre de voies Double voie Trafic Propriétaire JR East Exploitant(s) JR East modifier  La ligne Chūō-Sōbu (中央・総武緩行線, Chūō Sōbu Kankō-sen?) est une l...

Dahlonega redirects here. For other uses, see Dahlonega (disambiguation). City in Georgia, United StatesDahlonega, GeorgiaCityHistoric Lumpkin County Courthouse, which now houses the Dahlonega Gold Museum Historic Site FlagSealLogoNickname: Gold CityLocation in Lumpkin County and the state of GeorgiaCoordinates: 34°31′57″N 83°59′06″W / 34.53250°N 83.98500°W / 34.53250; -83.98500CountryUnited StatesStateGeorgiaCountyLumpkinGovernment • Mayor...

 

Il Pallone d'oro 2022 è stato consegnato il 17 ottobre 2022 a Parigi[1] ed è stato vinto da Karim Benzema, al primo successo nella storia del riconoscimento. Come nell'edizione precedente, sono stati assegnati il Pallone d'oro femminile, il Trofeo Kopa e il Trofeo Jašin, vinti rispettivamente da Alexia Putellas, Gavi e Thibaut Courtois. Sono stati assegnati anche il Premio Sócrates e il Trofeo Müller, andati rispettivamente a Sadio Mané e Robert Lewandowski. Il premio al miglior...

 

Building for gatherings of a Sufi brotherhood For other uses, see Khanqah (disambiguation). Part of a series on IslamSufismTomb of Abdul Qadir Gilani, Baghdad, Iraq Ideas Abdal Al-Insān al-Kāmil Baqaa Dervish Dhawq Fakir Fana Hal Haqiqa Ihsan Irfan Ishq Karamat Kashf Lataif Manzil Ma'rifa Maqam Murid Murshid Nafs Nūr Qalandar Qutb Silsila Sufi cosmology Sufi metaphysics Sufi philosophy Sufi poetry Sufi psychology Salik Tazkiah Wali Yaqeen Practices Anasheed Dhikr Haḍra Muraqabah Qawwali ...

Voce principale: Serie C 1945-1946. Serie C 1945-1946(Lega Nazionale Alta Italia) Competizione Serie C Sport Calcio Edizione 8ª Organizzatore FIGC - Lega Nazionale Alta Italia Luogo  Italia Partecipanti 110 Cronologia della competizione 1942-1943 1946-1947 Manuale La Serie C 1945-1946 fu un'edizione straordinaria del campionato italiano di calcio di Serie C. Per superare le notevoli difficoltà logistiche la F.I.G.C. fu obbligata a delegare alla neo-costituita Lega Nazionale Alta Itali...

 

Warren Hastings Warren Hastings (lahir 6 Desember 1732 di Churchill, Oxfordshire, Inggris - meninggal 22 Agustus 1818 di Daylesford, Oxfordshire pada umur 85 tahun) adalah seorang gubernur jenderal Britania Raya di India yang pertama.[1][2] Hastings adalah anak dari seorang pendeta Gereja di Inggris.[1] Sejak kecil ia telah ditinggal ayahnya dan diasuh serta diberi pendidikan oleh pamannya.[1] Hastings menempuh pendidikan formalnya di Sekolah Westminster di Lon...

 

Wayang kulitPertunjukan wayang kulit oleh DalangJenisSeni pertunjukanSeni pendahuluMasyarakat JawaBudaya awalIndonesiaAwal berkembangPeradaban Hindu-Budha Pertunjukan Wayang KulitWarisan Budaya Tak Benda UNESCOPertunjukan Wayang Kulit oleh dalang terkenal Indonesia Manteb Soedharsono, dengan lakon (cerita) Gathutkaca Winisuda, di Bentara Budaya Jakarta, Indonesia, pada 31 Juli 2010NegaraIndonesiaKriteriaSeni pertunjukan, keahlian tradisionalReferensi063KawasanAsia dan PasifikSejarah Inskripsi...

Masjid FierMasjid Agung FierXhamia e FieritXhamia e Madhe e FieritMasjid FierAgamaAfiliasiIslamLokasiMunisipalitasFierNegaraAlbaniaKoordinat40°43′34″N 19°33′25″E / 40.726104°N 19.557013°E / 40.726104; 19.557013Koordinat: 40°43′34″N 19°33′25″E / 40.726104°N 19.557013°E / 40.726104; 19.557013ArsitekturDidirikan2005SpesifikasiKubah1Menara2 Potret Masjid Fier dari pusat kota Masjid Agung Fier bahasa Albania: Xhamia e Madh...

 

Tudor Vladimirescu DivisionDivizia Tudor VladimirescuActive15 November 1943 (1943-11-15)[1]–15 August 1945 (1945-08-15)[2]Country Romania;[3] formation equipped and supplied by Soviet UnionBranch Red Army (2nd Ukrainian Front)TypeDivisionSize9,562 (February 1944)[2]EngagementsWorld War II Battles in Transylvania Battle of Debrecen Western Carpathian Offensive Battle honoursRenamed Tudor Vladimirescu-Debrețin Division after ...

 

French architect Auguste PerretPortrait of Auguste Perret (1932)Born(1874-02-12)12 February 1874Ixelles, BelgiumDied25 February 1954(1954-02-25) (aged 80)Paris, FranceNationalityFrenchOccupationArchitectAwardsAIA Gold Medal (1952)BuildingsThéâtre des Champs-ÉlyséesSt. Joseph's Church, Le HavreFrench Economic, Social and Environmental CouncilÉglise Notre-Dame du Raincy Auguste Perret (12 February 1874 – 25 February 1954) was a French architect and a pioneer of the architectural use...

CocktailLynchburg lemonadeCocktailA Lynchburg lemonadeat a restaurantTypeCocktailBase spirit Tennessee whiskey ServedOn the rocks: poured over iceStandard garnishLemon wedge, maraschino cherryStandard drinkware Collins glassCommonly used ingredients 1+1/4 oz Jack Daniel's 3/4 oz triple sec 2 oz sour mix lemon-lime PreparationShake first three ingredients with ice and strain into ice-filled glass. Top with the lemonade or lemon-lime. Add ice and stir. Garnish with lemon slices and cherries. ...

 

August Hermann Francke August Hermann Francke (1663 -1727) adalah teolog Jerman dan guru besar Universitas Halle selama 30 tahun.[1] Selama Francke di sana, universitas ini menjadi pusat dan lumbung Pietisme.[1][2] Ribuan pendeta dan penginjil dengan semangat pietisme (memfokuskan diri pada karya-karya sosial seperti panti asuhan, perawatan orang miskin, pendidikan sekolah-sekolah umum maupun keagamaan) merupakan lulusan universitas ini.[1] Francke adalah murid...

 

شعار مبادرة التجارة العادلة التجارة العادلة أو الاتجار الأدنوي[1] هي نظام مصمم لمساعدة المنتجين في البلدان النامية على تحقيق علاقات تجارية مستمرة ومنصفة. المشتركون في هذه الحركة التجارية يدفعون أسعار أعلى للمصدرين، وأيضاً للمنتجات التي تتبع تحسين المعايير الاجتماعي�...

Colonial American clergyman (d. 1679) For the American poet, see John Brooks Wheelwright. The ReverendJohn WheelwrightReverend John Wheelwright, c. 1677Bornc. 1592Saleby, Lincolnshire, EnglandDied15 November 1679Salisbury, MassachusettsResting placeColonial Burying Ground, SalisburyEducationSidney Sussex College, Cambridge, B.A. 1614/5; M.A. 1618OccupationClergymanSpouse(s)(1) Mary Storre(2) Mary HutchinsonChildren(1st wife): John, Thomas, William, Susannah;(2nd wife): Katherine, Mary, Elizab...

 

2020 single by Jack Harlow featuring Chris Brown Already Best FriendsSingle by Jack Harlow featuring Chris Brownfrom the album Thats What They All Say ReleasedMarch 30, 2021Genre R&B hip hop Length3:17Label Generation Now Warner Atlantic Songwriter(s) Jackman Harlow Christopher Maurice Brown Producer(s) JetsonMade Ye Ali Joe Hodges Rance Jack Harlow singles chronology Hot Boy Bling (2021) Already Best Friends (2021) Body (Remix) (2021) Chris Brown singles chronology Baby(2021) Alr...