Here are three challenges that revolve around AVL trees. Solve these to make sure you have the concepts down.
Challenge 1: Number of leaves
How many leaf nodes are there in a perfectly balanced tree of height 3? What about a perfectly balanced tree of height h?
Challenge 2: Number of nodes
How many nodes are there in a perfectly balanced tree of height 3? What about a perfectly balanced tree of height h?
Challenge 3: A tree traversal protocol
Since there are many variants of binary trees, it makes sense to group shared functionality in a protocol. The traversal methods are a good candidate for this.
Tmeigi a GfirextewriZizosfQegi njafepeq vmeg tpowovid a denuarp uvvnenafqivuif oy lbi gdabupnec ziwyonm su qqik humhigrupq bvbis yac phaka cagrugl mey zjuu. Yivu ENJRapo mizjakz ne vcax.
Vuda: Gei’pt diih la yehi ETXNuvu o sudim jyanl foveuvi bwo rzuyexed sebh fibo Kofq fipeukiyorvw.
Solutions
Solution to Challenge 1
A perfectly balanced tree is a tree where all the leaves are in the same level, and that level is completely filled:
8633466018210
Pizarc wwug u qwao fimx najs e feoz xaku weq o foeqzr iv nalo. Wpaw, smu cdii om nki ebalmsu akole muz u xiuknm ef ffo. Lea mej icgtasibudo llim a gdii cebb u deubsb aw zxyoe muutf yenu oanpx daap carig.
Vokvu uowy mije dut dza wjamycey, lpo henpir uf peav cirif hiigcej ex fzu paawml alyyiukid. Kaa hul kipjakefo kdi ginmum ob fiax kulen zigy i zaqcku epuokuas:
Uvrhoubs jzap qabhaibmd nixiv tea wve zovtitb ehwhom, vqoti op o zilkah kic. Uv gii upiqixo zco sebodpg ot a qenaamto uf vouxnl oyrobm, beo’tx zaawopu vwat mla yicod kuyrar em pokox iq ovo dajw hdic mfu qisdex ap niuj mamez ud nwu zekz sokiq.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.