[{"data":1,"prerenderedAt":3425},["ShallowReactive",2],{"tag-algorithms":3},[4,2208],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"date":11,"layout":12,"subtitle":10,"image":13,"optimized_image":13,"category":14,"tags":15,"author":19,"paginate":7,"body":20,"_type":2202,"_id":2203,"_source":2204,"_file":2205,"_stem":2206,"_extension":2207},"/posts/algorithms-binary-search-tree","posts",false,"","Algorithms - Binary Search Tree in kotlin","Brief review of binary search trees with kotlin examples","2020-12-06T11:00:00.000Z","post","/assets/img/uploads/rubiks-cube.jpg","algorithms",[16,17,18,14],"code","kotlin","binary-tree","jaimedearcos",{"type":21,"children":22,"toc":2196},"root",[23,50,68,80,88,95,109,272,284,290,295,347,683,689,708,954,960,965,1072,2179,2190],{"type":24,"tag":25,"props":26,"children":27},"element","blockquote",{},[28],{"type":24,"tag":29,"props":30,"children":31},"p",{},[32,39,41],{"type":24,"tag":33,"props":34,"children":35},"em",{},[36],{"type":37,"value":38},"text","\"A binary search tree (BST) is a rooted binary tree whose internal nodes each store a key greater than all the keys in\nthe node's left subtree and less than those in its right subtree.\"",{"type":37,"value":40}," -- ",{"type":24,"tag":42,"props":43,"children":47},"a",{"href":44,"rel":45},"https://en.wikipedia.org/wiki/Binary_search_tree",[46],"nofollow",[48],{"type":37,"value":49},"Wikipedia",{"type":24,"tag":29,"props":51,"children":52},{},[53,55,61,63],{"type":37,"value":54},"One of the biggest ",{"type":24,"tag":56,"props":57,"children":58},"strong",{},[59],{"type":37,"value":60},"advantages of Binary Search Trees",{"type":37,"value":62}," is the performance of lookup, addition and removal of data nodes, each\ncomparison skips the half of the remaining tree, so the operation usually is ",{"type":24,"tag":56,"props":64,"children":65},{},[66],{"type":37,"value":67},"O(log n)",{"type":24,"tag":29,"props":69,"children":70},{},[71,73,78],{"type":37,"value":72},"Here is ",{"type":24,"tag":56,"props":74,"children":75},{},[76],{"type":37,"value":77},"an example",{"type":37,"value":79}," of Binary Search Tree:",{"type":24,"tag":29,"props":81,"children":82},{},[83],{"type":24,"tag":84,"props":85,"children":87},"img",{"alt":8,"src":86},"/assets/img/uploads/binary-search-tree.jpg",[],{"type":24,"tag":89,"props":90,"children":92},"h2",{"id":91},"lets-code-a-binary-search-tree",[93],{"type":37,"value":94},"Let's code a binary search tree",{"type":24,"tag":29,"props":96,"children":97},{},[98,100,107],{"type":37,"value":99},"The fist step it's going to be the data structure. It's pretty similar to the one we code in the previous post about\n",{"type":24,"tag":42,"props":101,"children":104},{"href":102,"target":103},"/algorithms-working-with-trees/","_blank",[105],{"type":37,"value":106},"binary tree traversals",{"type":37,"value":108},".",{"type":24,"tag":110,"props":111,"children":114},"pre",{"className":112,"code":113,"language":17,"meta":8,"style":8},"language-kotlin shiki shiki-themes github-dark github-light","data class BinarySearchTreeNode(\n        var data:Int,\n        var left: BinarySearchTreeNode? = null,\n        var right: BinarySearchTreeNode? = null\n){\n   // ...\n}\n",[115],{"type":24,"tag":16,"props":116,"children":117},{"__ignoreMap":8},[118,147,176,214,244,253,263],{"type":24,"tag":119,"props":120,"children":123},"span",{"class":121,"line":122},"line",1,[124,130,135,141],{"type":24,"tag":119,"props":125,"children":127},{"style":126},"--shiki-default:#F97583;--shiki-light:#D73A49",[128],{"type":37,"value":129},"data",{"type":24,"tag":119,"props":131,"children":132},{"style":126},[133],{"type":37,"value":134}," class",{"type":24,"tag":119,"props":136,"children":138},{"style":137},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[139],{"type":37,"value":140}," BinarySearchTreeNode",{"type":24,"tag":119,"props":142,"children":144},{"style":143},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[145],{"type":37,"value":146},"(\n",{"type":24,"tag":119,"props":148,"children":150},{"class":121,"line":149},2,[151,156,161,166,171],{"type":24,"tag":119,"props":152,"children":153},{"style":126},[154],{"type":37,"value":155},"        var",{"type":24,"tag":119,"props":157,"children":158},{"style":126},[159],{"type":37,"value":160}," data",{"type":24,"tag":119,"props":162,"children":163},{"style":143},[164],{"type":37,"value":165},":",{"type":24,"tag":119,"props":167,"children":168},{"style":137},[169],{"type":37,"value":170},"Int",{"type":24,"tag":119,"props":172,"children":173},{"style":143},[174],{"type":37,"value":175},",\n",{"type":24,"tag":119,"props":177,"children":179},{"class":121,"line":178},3,[180,184,189,194,199,204,210],{"type":24,"tag":119,"props":181,"children":182},{"style":126},[183],{"type":37,"value":155},{"type":24,"tag":119,"props":185,"children":186},{"style":143},[187],{"type":37,"value":188}," left: ",{"type":24,"tag":119,"props":190,"children":191},{"style":137},[192],{"type":37,"value":193},"BinarySearchTreeNode",{"type":24,"tag":119,"props":195,"children":196},{"style":143},[197],{"type":37,"value":198},"? ",{"type":24,"tag":119,"props":200,"children":201},{"style":126},[202],{"type":37,"value":203},"=",{"type":24,"tag":119,"props":205,"children":207},{"style":206},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[208],{"type":37,"value":209}," null",{"type":24,"tag":119,"props":211,"children":212},{"style":143},[213],{"type":37,"value":175},{"type":24,"tag":119,"props":215,"children":217},{"class":121,"line":216},4,[218,222,227,231,235,239],{"type":24,"tag":119,"props":219,"children":220},{"style":126},[221],{"type":37,"value":155},{"type":24,"tag":119,"props":223,"children":224},{"style":143},[225],{"type":37,"value":226}," right: ",{"type":24,"tag":119,"props":228,"children":229},{"style":137},[230],{"type":37,"value":193},{"type":24,"tag":119,"props":232,"children":233},{"style":143},[234],{"type":37,"value":198},{"type":24,"tag":119,"props":236,"children":237},{"style":126},[238],{"type":37,"value":203},{"type":24,"tag":119,"props":240,"children":241},{"style":206},[242],{"type":37,"value":243}," null\n",{"type":24,"tag":119,"props":245,"children":247},{"class":121,"line":246},5,[248],{"type":24,"tag":119,"props":249,"children":250},{"style":143},[251],{"type":37,"value":252},"){\n",{"type":24,"tag":119,"props":254,"children":256},{"class":121,"line":255},6,[257],{"type":24,"tag":119,"props":258,"children":260},{"style":259},"--shiki-default:#6A737D;--shiki-light:#6A737D",[261],{"type":37,"value":262},"   // ...\n",{"type":24,"tag":119,"props":264,"children":266},{"class":121,"line":265},7,[267],{"type":24,"tag":119,"props":268,"children":269},{"style":143},[270],{"type":37,"value":271},"}\n",{"type":24,"tag":29,"props":273,"children":274},{},[275,277,282],{"type":37,"value":276},"As you can see is basically the same as simple binary trees, the main difference is going to be how we ",{"type":24,"tag":56,"props":278,"children":279},{},[280],{"type":37,"value":281},"insert, search\nand delete",{"type":37,"value":283}," values from the tree.",{"type":24,"tag":89,"props":285,"children":287},{"id":286},"insert-values-in-the-tree",[288],{"type":37,"value":289},"Insert values in the tree",{"type":24,"tag":29,"props":291,"children":292},{},[293],{"type":37,"value":294},"The insertion function is a simple recursive one, there are 4 cases:",{"type":24,"tag":296,"props":297,"children":298},"ul",{},[299,325],{"type":24,"tag":300,"props":301,"children":302},"li",{},[303,305,310,312],{"type":37,"value":304},"New item is ",{"type":24,"tag":56,"props":306,"children":307},{},[308],{"type":37,"value":309},"lower or equals",{"type":37,"value":311}," than the current node data:\n",{"type":24,"tag":296,"props":313,"children":314},{},[315,320],{"type":24,"tag":300,"props":316,"children":317},{},[318],{"type":37,"value":319},"If left exist --> insert the value in left child (recursion)",{"type":24,"tag":300,"props":321,"children":322},{},[323],{"type":37,"value":324},"Else, create a new left child with the value (finish condition)",{"type":24,"tag":300,"props":326,"children":327},{},[328,329,334,335],{"type":37,"value":304},{"type":24,"tag":56,"props":330,"children":331},{},[332],{"type":37,"value":333},"greater",{"type":37,"value":311},{"type":24,"tag":296,"props":336,"children":337},{},[338,342],{"type":24,"tag":300,"props":339,"children":340},{},[341],{"type":37,"value":319},{"type":24,"tag":300,"props":343,"children":344},{},[345],{"type":37,"value":346},"Else, create a new right child with the value (finish condition)",{"type":24,"tag":110,"props":348,"children":350},{"className":112,"code":349,"language":17,"meta":8,"style":8},"fun insert(value:Int){\n    if(value \u003C= data && left != null){\n        left!!.insert(value)\n    }else if (value \u003C= data){\n        left = BinarySearchTreeNode(value)\n    }else if(value> data && right != null){\n        right!!.insert(value)\n    }else{\n        right = BinarySearchTreeNode(value)\n    }\n}\n",[351],{"type":24,"tag":16,"props":352,"children":353},{"__ignoreMap":8},[354,389,437,472,511,539,588,620,637,666,675],{"type":24,"tag":119,"props":355,"children":356},{"class":121,"line":122},[357,362,367,372,377,381,385],{"type":24,"tag":119,"props":358,"children":359},{"style":126},[360],{"type":37,"value":361},"fun",{"type":24,"tag":119,"props":363,"children":364},{"style":137},[365],{"type":37,"value":366}," insert",{"type":24,"tag":119,"props":368,"children":369},{"style":143},[370],{"type":37,"value":371},"(",{"type":24,"tag":119,"props":373,"children":374},{"style":126},[375],{"type":37,"value":376},"value",{"type":24,"tag":119,"props":378,"children":379},{"style":143},[380],{"type":37,"value":165},{"type":24,"tag":119,"props":382,"children":383},{"style":137},[384],{"type":37,"value":170},{"type":24,"tag":119,"props":386,"children":387},{"style":143},[388],{"type":37,"value":252},{"type":24,"tag":119,"props":390,"children":391},{"class":121,"line":149},[392,397,401,405,410,414,419,424,429,433],{"type":24,"tag":119,"props":393,"children":394},{"style":126},[395],{"type":37,"value":396},"    if",{"type":24,"tag":119,"props":398,"children":399},{"style":143},[400],{"type":37,"value":371},{"type":24,"tag":119,"props":402,"children":403},{"style":126},[404],{"type":37,"value":376},{"type":24,"tag":119,"props":406,"children":407},{"style":126},[408],{"type":37,"value":409}," \u003C=",{"type":24,"tag":119,"props":411,"children":412},{"style":126},[413],{"type":37,"value":160},{"type":24,"tag":119,"props":415,"children":416},{"style":126},[417],{"type":37,"value":418}," &&",{"type":24,"tag":119,"props":420,"children":421},{"style":143},[422],{"type":37,"value":423}," left ",{"type":24,"tag":119,"props":425,"children":426},{"style":126},[427],{"type":37,"value":428},"!=",{"type":24,"tag":119,"props":430,"children":431},{"style":206},[432],{"type":37,"value":209},{"type":24,"tag":119,"props":434,"children":435},{"style":143},[436],{"type":37,"value":252},{"type":24,"tag":119,"props":438,"children":439},{"class":121,"line":178},[440,445,450,454,459,463,467],{"type":24,"tag":119,"props":441,"children":442},{"style":143},[443],{"type":37,"value":444},"        left",{"type":24,"tag":119,"props":446,"children":447},{"style":126},[448],{"type":37,"value":449},"!!",{"type":24,"tag":119,"props":451,"children":452},{"style":143},[453],{"type":37,"value":108},{"type":24,"tag":119,"props":455,"children":456},{"style":137},[457],{"type":37,"value":458},"insert",{"type":24,"tag":119,"props":460,"children":461},{"style":143},[462],{"type":37,"value":371},{"type":24,"tag":119,"props":464,"children":465},{"style":126},[466],{"type":37,"value":376},{"type":24,"tag":119,"props":468,"children":469},{"style":143},[470],{"type":37,"value":471},")\n",{"type":24,"tag":119,"props":473,"children":474},{"class":121,"line":216},[475,480,485,490,495,499,503,507],{"type":24,"tag":119,"props":476,"children":477},{"style":143},[478],{"type":37,"value":479},"    }",{"type":24,"tag":119,"props":481,"children":482},{"style":126},[483],{"type":37,"value":484},"else",{"type":24,"tag":119,"props":486,"children":487},{"style":126},[488],{"type":37,"value":489}," if",{"type":24,"tag":119,"props":491,"children":492},{"style":143},[493],{"type":37,"value":494}," (",{"type":24,"tag":119,"props":496,"children":497},{"style":126},[498],{"type":37,"value":376},{"type":24,"tag":119,"props":500,"children":501},{"style":126},[502],{"type":37,"value":409},{"type":24,"tag":119,"props":504,"children":505},{"style":126},[506],{"type":37,"value":160},{"type":24,"tag":119,"props":508,"children":509},{"style":143},[510],{"type":37,"value":252},{"type":24,"tag":119,"props":512,"children":513},{"class":121,"line":246},[514,519,523,527,531,535],{"type":24,"tag":119,"props":515,"children":516},{"style":143},[517],{"type":37,"value":518},"        left ",{"type":24,"tag":119,"props":520,"children":521},{"style":126},[522],{"type":37,"value":203},{"type":24,"tag":119,"props":524,"children":525},{"style":137},[526],{"type":37,"value":140},{"type":24,"tag":119,"props":528,"children":529},{"style":143},[530],{"type":37,"value":371},{"type":24,"tag":119,"props":532,"children":533},{"style":126},[534],{"type":37,"value":376},{"type":24,"tag":119,"props":536,"children":537},{"style":143},[538],{"type":37,"value":471},{"type":24,"tag":119,"props":540,"children":541},{"class":121,"line":255},[542,546,550,554,558,563,567,571,576,580,584],{"type":24,"tag":119,"props":543,"children":544},{"style":143},[545],{"type":37,"value":479},{"type":24,"tag":119,"props":547,"children":548},{"style":126},[549],{"type":37,"value":484},{"type":24,"tag":119,"props":551,"children":552},{"style":126},[553],{"type":37,"value":489},{"type":24,"tag":119,"props":555,"children":556},{"style":143},[557],{"type":37,"value":371},{"type":24,"tag":119,"props":559,"children":560},{"style":126},[561],{"type":37,"value":562},"value>",{"type":24,"tag":119,"props":564,"children":565},{"style":126},[566],{"type":37,"value":160},{"type":24,"tag":119,"props":568,"children":569},{"style":126},[570],{"type":37,"value":418},{"type":24,"tag":119,"props":572,"children":573},{"style":143},[574],{"type":37,"value":575}," right ",{"type":24,"tag":119,"props":577,"children":578},{"style":126},[579],{"type":37,"value":428},{"type":24,"tag":119,"props":581,"children":582},{"style":206},[583],{"type":37,"value":209},{"type":24,"tag":119,"props":585,"children":586},{"style":143},[587],{"type":37,"value":252},{"type":24,"tag":119,"props":589,"children":590},{"class":121,"line":265},[591,596,600,604,608,612,616],{"type":24,"tag":119,"props":592,"children":593},{"style":143},[594],{"type":37,"value":595},"        right",{"type":24,"tag":119,"props":597,"children":598},{"style":126},[599],{"type":37,"value":449},{"type":24,"tag":119,"props":601,"children":602},{"style":143},[603],{"type":37,"value":108},{"type":24,"tag":119,"props":605,"children":606},{"style":137},[607],{"type":37,"value":458},{"type":24,"tag":119,"props":609,"children":610},{"style":143},[611],{"type":37,"value":371},{"type":24,"tag":119,"props":613,"children":614},{"style":126},[615],{"type":37,"value":376},{"type":24,"tag":119,"props":617,"children":618},{"style":143},[619],{"type":37,"value":471},{"type":24,"tag":119,"props":621,"children":623},{"class":121,"line":622},8,[624,628,632],{"type":24,"tag":119,"props":625,"children":626},{"style":143},[627],{"type":37,"value":479},{"type":24,"tag":119,"props":629,"children":630},{"style":126},[631],{"type":37,"value":484},{"type":24,"tag":119,"props":633,"children":634},{"style":143},[635],{"type":37,"value":636},"{\n",{"type":24,"tag":119,"props":638,"children":640},{"class":121,"line":639},9,[641,646,650,654,658,662],{"type":24,"tag":119,"props":642,"children":643},{"style":143},[644],{"type":37,"value":645},"        right ",{"type":24,"tag":119,"props":647,"children":648},{"style":126},[649],{"type":37,"value":203},{"type":24,"tag":119,"props":651,"children":652},{"style":137},[653],{"type":37,"value":140},{"type":24,"tag":119,"props":655,"children":656},{"style":143},[657],{"type":37,"value":371},{"type":24,"tag":119,"props":659,"children":660},{"style":126},[661],{"type":37,"value":376},{"type":24,"tag":119,"props":663,"children":664},{"style":143},[665],{"type":37,"value":471},{"type":24,"tag":119,"props":667,"children":669},{"class":121,"line":668},10,[670],{"type":24,"tag":119,"props":671,"children":672},{"style":143},[673],{"type":37,"value":674},"    }\n",{"type":24,"tag":119,"props":676,"children":678},{"class":121,"line":677},11,[679],{"type":24,"tag":119,"props":680,"children":681},{"style":143},[682],{"type":37,"value":271},{"type":24,"tag":89,"props":684,"children":686},{"id":685},"searchcontains-value-in-the-tree",[687],{"type":37,"value":688},"Search/contains value in the tree",{"type":24,"tag":29,"props":690,"children":691},{},[692,694,698,700,706],{"type":37,"value":693},"In the following ",{"type":24,"tag":56,"props":695,"children":696},{},[697],{"type":37,"value":17},{"type":37,"value":699}," snippet we are going to implement the ",{"type":24,"tag":16,"props":701,"children":703},{"className":702},[],[704],{"type":37,"value":705},"contains",{"type":37,"value":707}," function, because our tree stores only Integer values.\nIf you want to store complex objects, is not difficult to modify the function to return the data of searched value instead\na boolean, but you need to store only comparable objects with proper implementation of equals function.",{"type":24,"tag":110,"props":709,"children":711},{"className":112,"code":710,"language":17,"meta":8,"style":8},"fun contains(value:Int) : Boolean{\n    if (value \u003C data && left !=null) {\n        return left!!.contains(value)\n    }\n    if(value > data && right!=null) {\n        return right!!.contains(value)\n    }\n    return value==data\n}\n",[712],{"type":24,"tag":16,"props":713,"children":714},{"__ignoreMap":8},[715,757,803,840,847,892,927,934,947],{"type":24,"tag":119,"props":716,"children":717},{"class":121,"line":122},[718,722,727,731,735,739,743,748,753],{"type":24,"tag":119,"props":719,"children":720},{"style":126},[721],{"type":37,"value":361},{"type":24,"tag":119,"props":723,"children":724},{"style":137},[725],{"type":37,"value":726}," contains",{"type":24,"tag":119,"props":728,"children":729},{"style":143},[730],{"type":37,"value":371},{"type":24,"tag":119,"props":732,"children":733},{"style":126},[734],{"type":37,"value":376},{"type":24,"tag":119,"props":736,"children":737},{"style":143},[738],{"type":37,"value":165},{"type":24,"tag":119,"props":740,"children":741},{"style":137},[742],{"type":37,"value":170},{"type":24,"tag":119,"props":744,"children":745},{"style":143},[746],{"type":37,"value":747},") : ",{"type":24,"tag":119,"props":749,"children":750},{"style":137},[751],{"type":37,"value":752},"Boolean",{"type":24,"tag":119,"props":754,"children":755},{"style":143},[756],{"type":37,"value":636},{"type":24,"tag":119,"props":758,"children":759},{"class":121,"line":149},[760,764,768,772,777,781,785,789,793,798],{"type":24,"tag":119,"props":761,"children":762},{"style":126},[763],{"type":37,"value":396},{"type":24,"tag":119,"props":765,"children":766},{"style":143},[767],{"type":37,"value":494},{"type":24,"tag":119,"props":769,"children":770},{"style":126},[771],{"type":37,"value":376},{"type":24,"tag":119,"props":773,"children":774},{"style":126},[775],{"type":37,"value":776}," \u003C",{"type":24,"tag":119,"props":778,"children":779},{"style":126},[780],{"type":37,"value":160},{"type":24,"tag":119,"props":782,"children":783},{"style":126},[784],{"type":37,"value":418},{"type":24,"tag":119,"props":786,"children":787},{"style":143},[788],{"type":37,"value":423},{"type":24,"tag":119,"props":790,"children":791},{"style":126},[792],{"type":37,"value":428},{"type":24,"tag":119,"props":794,"children":795},{"style":206},[796],{"type":37,"value":797},"null",{"type":24,"tag":119,"props":799,"children":800},{"style":143},[801],{"type":37,"value":802},") {\n",{"type":24,"tag":119,"props":804,"children":805},{"class":121,"line":178},[806,811,816,820,824,828,832,836],{"type":24,"tag":119,"props":807,"children":808},{"style":126},[809],{"type":37,"value":810},"        return",{"type":24,"tag":119,"props":812,"children":813},{"style":143},[814],{"type":37,"value":815}," left",{"type":24,"tag":119,"props":817,"children":818},{"style":126},[819],{"type":37,"value":449},{"type":24,"tag":119,"props":821,"children":822},{"style":143},[823],{"type":37,"value":108},{"type":24,"tag":119,"props":825,"children":826},{"style":137},[827],{"type":37,"value":705},{"type":24,"tag":119,"props":829,"children":830},{"style":143},[831],{"type":37,"value":371},{"type":24,"tag":119,"props":833,"children":834},{"style":126},[835],{"type":37,"value":376},{"type":24,"tag":119,"props":837,"children":838},{"style":143},[839],{"type":37,"value":471},{"type":24,"tag":119,"props":841,"children":842},{"class":121,"line":216},[843],{"type":24,"tag":119,"props":844,"children":845},{"style":143},[846],{"type":37,"value":674},{"type":24,"tag":119,"props":848,"children":849},{"class":121,"line":246},[850,854,858,862,867,871,875,880,884,888],{"type":24,"tag":119,"props":851,"children":852},{"style":126},[853],{"type":37,"value":396},{"type":24,"tag":119,"props":855,"children":856},{"style":143},[857],{"type":37,"value":371},{"type":24,"tag":119,"props":859,"children":860},{"style":126},[861],{"type":37,"value":376},{"type":24,"tag":119,"props":863,"children":864},{"style":126},[865],{"type":37,"value":866}," >",{"type":24,"tag":119,"props":868,"children":869},{"style":126},[870],{"type":37,"value":160},{"type":24,"tag":119,"props":872,"children":873},{"style":126},[874],{"type":37,"value":418},{"type":24,"tag":119,"props":876,"children":877},{"style":143},[878],{"type":37,"value":879}," right",{"type":24,"tag":119,"props":881,"children":882},{"style":126},[883],{"type":37,"value":428},{"type":24,"tag":119,"props":885,"children":886},{"style":206},[887],{"type":37,"value":797},{"type":24,"tag":119,"props":889,"children":890},{"style":143},[891],{"type":37,"value":802},{"type":24,"tag":119,"props":893,"children":894},{"class":121,"line":255},[895,899,903,907,911,915,919,923],{"type":24,"tag":119,"props":896,"children":897},{"style":126},[898],{"type":37,"value":810},{"type":24,"tag":119,"props":900,"children":901},{"style":143},[902],{"type":37,"value":879},{"type":24,"tag":119,"props":904,"children":905},{"style":126},[906],{"type":37,"value":449},{"type":24,"tag":119,"props":908,"children":909},{"style":143},[910],{"type":37,"value":108},{"type":24,"tag":119,"props":912,"children":913},{"style":137},[914],{"type":37,"value":705},{"type":24,"tag":119,"props":916,"children":917},{"style":143},[918],{"type":37,"value":371},{"type":24,"tag":119,"props":920,"children":921},{"style":126},[922],{"type":37,"value":376},{"type":24,"tag":119,"props":924,"children":925},{"style":143},[926],{"type":37,"value":471},{"type":24,"tag":119,"props":928,"children":929},{"class":121,"line":265},[930],{"type":24,"tag":119,"props":931,"children":932},{"style":143},[933],{"type":37,"value":674},{"type":24,"tag":119,"props":935,"children":936},{"class":121,"line":622},[937,942],{"type":24,"tag":119,"props":938,"children":939},{"style":126},[940],{"type":37,"value":941},"    return",{"type":24,"tag":119,"props":943,"children":944},{"style":126},[945],{"type":37,"value":946}," value==data\n",{"type":24,"tag":119,"props":948,"children":949},{"class":121,"line":639},[950],{"type":24,"tag":119,"props":951,"children":952},{"style":143},[953],{"type":37,"value":271},{"type":24,"tag":89,"props":955,"children":957},{"id":956},"removing-nodes-from-binary-search-tree",[958],{"type":37,"value":959},"Removing nodes from Binary Search Tree",{"type":24,"tag":29,"props":961,"children":962},{},[963],{"type":37,"value":964},"Probably the most complex operation because if we need to remove a node with children we should reorder the tree.\nWe need to consider the following 3 scenarios:",{"type":24,"tag":966,"props":967,"children":968},"ol",{},[969,1011,1047],{"type":24,"tag":300,"props":970,"children":971},{},[972,974,980,982],{"type":37,"value":973},"The removed value is ",{"type":24,"tag":16,"props":975,"children":977},{"className":976},[],[978],{"type":37,"value":979},"lower",{"type":37,"value":981}," than the current node:\n",{"type":24,"tag":296,"props":983,"children":984},{},[985,1002],{"type":24,"tag":300,"props":986,"children":987},{},[988,993,995,1000],{"type":24,"tag":56,"props":989,"children":990},{},[991],{"type":37,"value":992},"if left child exist",{"type":37,"value":994},", we use the ",{"type":24,"tag":56,"props":996,"children":997},{},[998],{"type":37,"value":999},"recursion",{"type":37,"value":1001}," to remove value from the left child",{"type":24,"tag":300,"props":1003,"children":1004},{},[1005,1009],{"type":24,"tag":56,"props":1006,"children":1007},{},[1008],{"type":37,"value":484},{"type":37,"value":1010},", value does not exist in tree, return false.",{"type":24,"tag":300,"props":1012,"children":1013},{},[1014,1016,1021,1022],{"type":37,"value":1015},"Removed value is ",{"type":24,"tag":16,"props":1017,"children":1019},{"className":1018},[],[1020],{"type":37,"value":333},{"type":37,"value":981},{"type":24,"tag":296,"props":1023,"children":1024},{},[1025,1039],{"type":24,"tag":300,"props":1026,"children":1027},{},[1028,1033,1034,1038],{"type":24,"tag":56,"props":1029,"children":1030},{},[1031],{"type":37,"value":1032},"if right child exist",{"type":37,"value":994},{"type":24,"tag":56,"props":1035,"children":1036},{},[1037],{"type":37,"value":999},{"type":37,"value":1001},{"type":24,"tag":300,"props":1040,"children":1041},{},[1042,1046],{"type":24,"tag":56,"props":1043,"children":1044},{},[1045],{"type":37,"value":484},{"type":37,"value":1010},{"type":24,"tag":300,"props":1048,"children":1049},{},[1050,1051,1057,1059],{"type":37,"value":1015},{"type":24,"tag":16,"props":1052,"children":1054},{"className":1053},[],[1055],{"type":37,"value":1056},"equals",{"type":37,"value":1058}," to the current node data:\n",{"type":24,"tag":296,"props":1060,"children":1061},{},[1062],{"type":24,"tag":300,"props":1063,"children":1064},{},[1065,1067],{"type":37,"value":1066},"Depending on the existing children we should remove or reorder ",{"type":24,"tag":33,"props":1068,"children":1069},{},[1070],{"type":37,"value":1071},"(see code comments)",{"type":24,"tag":110,"props":1073,"children":1075},{"className":112,"code":1074,"language":17,"meta":8,"style":8},"fun remove(value:Int, parent:BinarySearchTreeNode) : Boolean{\n    // Value lower than current node data\n    if (value\u003Cdata && left!=null){\n        return left!!.remove(value,this)\n    }else if(value\u003Cdata){\n        return false\n    // Value greater than current node data\n    }else if(value>data && right != null){\n        return right!!.remove(value,this)\n    }else if (value>data){\n        return false\n    // Value equals the greater node data\n    }else {\n        // No Children, current node is parents LEFT node\n        if (left == null && right==null && this == parent.left) {\n            parent.left = null\n        // No Children, current node is parents RIGHT node\n        }else if (left == null && right==null && this==parent.right){\n            parent.right = null\n        // ONLY LEFT child, current node is parents LEFT node\n        }else if(left!=null && right==null && this == parent.left){\n            parent.left = this.left\n        // ONLY LEFT child, current node is parents RIGHT node\n        }else if(left!=null && right== null && this == parent.right){\n            parent.right = this.left\n        // ONLY RIGHT child, current node is parents LEFT node\n        }else if (right!=null && left==null && this == parent.left) {\n            parent.left = this.right\n        // ONLY RIGHT child, current node is parents RIGHT node\n        }else if(right!=null && left==null && this == parent.right) {\n            parent.right = this.right\n        // BOTH Children exists, replace current data with min value from right \n        }else{\n            data = right!!.min()\n            right!!.remove(data,this)\n        }\n        return true\n    }\n}\n\nfun min() : Int = if (left==null) data else left!!.min()\n",[1076],{"type":24,"tag":16,"props":1077,"children":1078},{"__ignoreMap":8},[1079,1128,1136,1172,1218,1245,1257,1265,1309,1352,1379,1390,1399,1416,1425,1483,1500,1509,1571,1588,1597,1659,1680,1689,1750,1770,1779,1840,1861,1870,1932,1952,1961,1977,2013,2054,2063,2076,2084,2092,2102],{"type":24,"tag":119,"props":1080,"children":1081},{"class":121,"line":122},[1082,1086,1091,1095,1099,1103,1107,1112,1116,1120,1124],{"type":24,"tag":119,"props":1083,"children":1084},{"style":126},[1085],{"type":37,"value":361},{"type":24,"tag":119,"props":1087,"children":1088},{"style":137},[1089],{"type":37,"value":1090}," remove",{"type":24,"tag":119,"props":1092,"children":1093},{"style":143},[1094],{"type":37,"value":371},{"type":24,"tag":119,"props":1096,"children":1097},{"style":126},[1098],{"type":37,"value":376},{"type":24,"tag":119,"props":1100,"children":1101},{"style":143},[1102],{"type":37,"value":165},{"type":24,"tag":119,"props":1104,"children":1105},{"style":137},[1106],{"type":37,"value":170},{"type":24,"tag":119,"props":1108,"children":1109},{"style":143},[1110],{"type":37,"value":1111},", parent:",{"type":24,"tag":119,"props":1113,"children":1114},{"style":137},[1115],{"type":37,"value":193},{"type":24,"tag":119,"props":1117,"children":1118},{"style":143},[1119],{"type":37,"value":747},{"type":24,"tag":119,"props":1121,"children":1122},{"style":137},[1123],{"type":37,"value":752},{"type":24,"tag":119,"props":1125,"children":1126},{"style":143},[1127],{"type":37,"value":636},{"type":24,"tag":119,"props":1129,"children":1130},{"class":121,"line":149},[1131],{"type":24,"tag":119,"props":1132,"children":1133},{"style":259},[1134],{"type":37,"value":1135},"    // Value lower than current node data\n",{"type":24,"tag":119,"props":1137,"children":1138},{"class":121,"line":178},[1139,1143,1147,1152,1156,1160,1164,1168],{"type":24,"tag":119,"props":1140,"children":1141},{"style":126},[1142],{"type":37,"value":396},{"type":24,"tag":119,"props":1144,"children":1145},{"style":143},[1146],{"type":37,"value":494},{"type":24,"tag":119,"props":1148,"children":1149},{"style":126},[1150],{"type":37,"value":1151},"value\u003Cdata",{"type":24,"tag":119,"props":1153,"children":1154},{"style":126},[1155],{"type":37,"value":418},{"type":24,"tag":119,"props":1157,"children":1158},{"style":143},[1159],{"type":37,"value":815},{"type":24,"tag":119,"props":1161,"children":1162},{"style":126},[1163],{"type":37,"value":428},{"type":24,"tag":119,"props":1165,"children":1166},{"style":206},[1167],{"type":37,"value":797},{"type":24,"tag":119,"props":1169,"children":1170},{"style":143},[1171],{"type":37,"value":252},{"type":24,"tag":119,"props":1173,"children":1174},{"class":121,"line":216},[1175,1179,1183,1187,1191,1196,1200,1204,1209,1214],{"type":24,"tag":119,"props":1176,"children":1177},{"style":126},[1178],{"type":37,"value":810},{"type":24,"tag":119,"props":1180,"children":1181},{"style":143},[1182],{"type":37,"value":815},{"type":24,"tag":119,"props":1184,"children":1185},{"style":126},[1186],{"type":37,"value":449},{"type":24,"tag":119,"props":1188,"children":1189},{"style":143},[1190],{"type":37,"value":108},{"type":24,"tag":119,"props":1192,"children":1193},{"style":137},[1194],{"type":37,"value":1195},"remove",{"type":24,"tag":119,"props":1197,"children":1198},{"style":143},[1199],{"type":37,"value":371},{"type":24,"tag":119,"props":1201,"children":1202},{"style":126},[1203],{"type":37,"value":376},{"type":24,"tag":119,"props":1205,"children":1206},{"style":143},[1207],{"type":37,"value":1208},",",{"type":24,"tag":119,"props":1210,"children":1211},{"style":206},[1212],{"type":37,"value":1213},"this",{"type":24,"tag":119,"props":1215,"children":1216},{"style":143},[1217],{"type":37,"value":471},{"type":24,"tag":119,"props":1219,"children":1220},{"class":121,"line":246},[1221,1225,1229,1233,1237,1241],{"type":24,"tag":119,"props":1222,"children":1223},{"style":143},[1224],{"type":37,"value":479},{"type":24,"tag":119,"props":1226,"children":1227},{"style":126},[1228],{"type":37,"value":484},{"type":24,"tag":119,"props":1230,"children":1231},{"style":126},[1232],{"type":37,"value":489},{"type":24,"tag":119,"props":1234,"children":1235},{"style":143},[1236],{"type":37,"value":371},{"type":24,"tag":119,"props":1238,"children":1239},{"style":126},[1240],{"type":37,"value":1151},{"type":24,"tag":119,"props":1242,"children":1243},{"style":143},[1244],{"type":37,"value":252},{"type":24,"tag":119,"props":1246,"children":1247},{"class":121,"line":255},[1248,1252],{"type":24,"tag":119,"props":1249,"children":1250},{"style":126},[1251],{"type":37,"value":810},{"type":24,"tag":119,"props":1253,"children":1254},{"style":206},[1255],{"type":37,"value":1256}," false\n",{"type":24,"tag":119,"props":1258,"children":1259},{"class":121,"line":265},[1260],{"type":24,"tag":119,"props":1261,"children":1262},{"style":259},[1263],{"type":37,"value":1264},"    // Value greater than current node data\n",{"type":24,"tag":119,"props":1266,"children":1267},{"class":121,"line":622},[1268,1272,1276,1280,1284,1289,1293,1297,1301,1305],{"type":24,"tag":119,"props":1269,"children":1270},{"style":143},[1271],{"type":37,"value":479},{"type":24,"tag":119,"props":1273,"children":1274},{"style":126},[1275],{"type":37,"value":484},{"type":24,"tag":119,"props":1277,"children":1278},{"style":126},[1279],{"type":37,"value":489},{"type":24,"tag":119,"props":1281,"children":1282},{"style":143},[1283],{"type":37,"value":371},{"type":24,"tag":119,"props":1285,"children":1286},{"style":126},[1287],{"type":37,"value":1288},"value>data",{"type":24,"tag":119,"props":1290,"children":1291},{"style":126},[1292],{"type":37,"value":418},{"type":24,"tag":119,"props":1294,"children":1295},{"style":143},[1296],{"type":37,"value":575},{"type":24,"tag":119,"props":1298,"children":1299},{"style":126},[1300],{"type":37,"value":428},{"type":24,"tag":119,"props":1302,"children":1303},{"style":206},[1304],{"type":37,"value":209},{"type":24,"tag":119,"props":1306,"children":1307},{"style":143},[1308],{"type":37,"value":252},{"type":24,"tag":119,"props":1310,"children":1311},{"class":121,"line":639},[1312,1316,1320,1324,1328,1332,1336,1340,1344,1348],{"type":24,"tag":119,"props":1313,"children":1314},{"style":126},[1315],{"type":37,"value":810},{"type":24,"tag":119,"props":1317,"children":1318},{"style":143},[1319],{"type":37,"value":879},{"type":24,"tag":119,"props":1321,"children":1322},{"style":126},[1323],{"type":37,"value":449},{"type":24,"tag":119,"props":1325,"children":1326},{"style":143},[1327],{"type":37,"value":108},{"type":24,"tag":119,"props":1329,"children":1330},{"style":137},[1331],{"type":37,"value":1195},{"type":24,"tag":119,"props":1333,"children":1334},{"style":143},[1335],{"type":37,"value":371},{"type":24,"tag":119,"props":1337,"children":1338},{"style":126},[1339],{"type":37,"value":376},{"type":24,"tag":119,"props":1341,"children":1342},{"style":143},[1343],{"type":37,"value":1208},{"type":24,"tag":119,"props":1345,"children":1346},{"style":206},[1347],{"type":37,"value":1213},{"type":24,"tag":119,"props":1349,"children":1350},{"style":143},[1351],{"type":37,"value":471},{"type":24,"tag":119,"props":1353,"children":1354},{"class":121,"line":668},[1355,1359,1363,1367,1371,1375],{"type":24,"tag":119,"props":1356,"children":1357},{"style":143},[1358],{"type":37,"value":479},{"type":24,"tag":119,"props":1360,"children":1361},{"style":126},[1362],{"type":37,"value":484},{"type":24,"tag":119,"props":1364,"children":1365},{"style":126},[1366],{"type":37,"value":489},{"type":24,"tag":119,"props":1368,"children":1369},{"style":143},[1370],{"type":37,"value":494},{"type":24,"tag":119,"props":1372,"children":1373},{"style":126},[1374],{"type":37,"value":1288},{"type":24,"tag":119,"props":1376,"children":1377},{"style":143},[1378],{"type":37,"value":252},{"type":24,"tag":119,"props":1380,"children":1381},{"class":121,"line":677},[1382,1386],{"type":24,"tag":119,"props":1383,"children":1384},{"style":126},[1385],{"type":37,"value":810},{"type":24,"tag":119,"props":1387,"children":1388},{"style":206},[1389],{"type":37,"value":1256},{"type":24,"tag":119,"props":1391,"children":1393},{"class":121,"line":1392},12,[1394],{"type":24,"tag":119,"props":1395,"children":1396},{"style":259},[1397],{"type":37,"value":1398},"    // Value equals the greater node data\n",{"type":24,"tag":119,"props":1400,"children":1402},{"class":121,"line":1401},13,[1403,1407,1411],{"type":24,"tag":119,"props":1404,"children":1405},{"style":143},[1406],{"type":37,"value":479},{"type":24,"tag":119,"props":1408,"children":1409},{"style":126},[1410],{"type":37,"value":484},{"type":24,"tag":119,"props":1412,"children":1413},{"style":143},[1414],{"type":37,"value":1415}," {\n",{"type":24,"tag":119,"props":1417,"children":1419},{"class":121,"line":1418},14,[1420],{"type":24,"tag":119,"props":1421,"children":1422},{"style":259},[1423],{"type":37,"value":1424},"        // No Children, current node is parents LEFT node\n",{"type":24,"tag":119,"props":1426,"children":1428},{"class":121,"line":1427},15,[1429,1434,1439,1444,1448,1452,1456,1460,1464,1468,1473,1478],{"type":24,"tag":119,"props":1430,"children":1431},{"style":126},[1432],{"type":37,"value":1433},"        if",{"type":24,"tag":119,"props":1435,"children":1436},{"style":143},[1437],{"type":37,"value":1438}," (left ",{"type":24,"tag":119,"props":1440,"children":1441},{"style":126},[1442],{"type":37,"value":1443},"==",{"type":24,"tag":119,"props":1445,"children":1446},{"style":206},[1447],{"type":37,"value":209},{"type":24,"tag":119,"props":1449,"children":1450},{"style":126},[1451],{"type":37,"value":418},{"type":24,"tag":119,"props":1453,"children":1454},{"style":143},[1455],{"type":37,"value":879},{"type":24,"tag":119,"props":1457,"children":1458},{"style":126},[1459],{"type":37,"value":1443},{"type":24,"tag":119,"props":1461,"children":1462},{"style":206},[1463],{"type":37,"value":797},{"type":24,"tag":119,"props":1465,"children":1466},{"style":126},[1467],{"type":37,"value":418},{"type":24,"tag":119,"props":1469,"children":1470},{"style":206},[1471],{"type":37,"value":1472}," this",{"type":24,"tag":119,"props":1474,"children":1475},{"style":126},[1476],{"type":37,"value":1477}," ==",{"type":24,"tag":119,"props":1479,"children":1480},{"style":143},[1481],{"type":37,"value":1482}," parent.left) {\n",{"type":24,"tag":119,"props":1484,"children":1486},{"class":121,"line":1485},16,[1487,1492,1496],{"type":24,"tag":119,"props":1488,"children":1489},{"style":143},[1490],{"type":37,"value":1491},"            parent.left ",{"type":24,"tag":119,"props":1493,"children":1494},{"style":126},[1495],{"type":37,"value":203},{"type":24,"tag":119,"props":1497,"children":1498},{"style":206},[1499],{"type":37,"value":243},{"type":24,"tag":119,"props":1501,"children":1503},{"class":121,"line":1502},17,[1504],{"type":24,"tag":119,"props":1505,"children":1506},{"style":259},[1507],{"type":37,"value":1508},"        // No Children, current node is parents RIGHT node\n",{"type":24,"tag":119,"props":1510,"children":1512},{"class":121,"line":1511},18,[1513,1518,1522,1526,1530,1534,1538,1542,1546,1550,1554,1558,1562,1566],{"type":24,"tag":119,"props":1514,"children":1515},{"style":143},[1516],{"type":37,"value":1517},"        }",{"type":24,"tag":119,"props":1519,"children":1520},{"style":126},[1521],{"type":37,"value":484},{"type":24,"tag":119,"props":1523,"children":1524},{"style":126},[1525],{"type":37,"value":489},{"type":24,"tag":119,"props":1527,"children":1528},{"style":143},[1529],{"type":37,"value":1438},{"type":24,"tag":119,"props":1531,"children":1532},{"style":126},[1533],{"type":37,"value":1443},{"type":24,"tag":119,"props":1535,"children":1536},{"style":206},[1537],{"type":37,"value":209},{"type":24,"tag":119,"props":1539,"children":1540},{"style":126},[1541],{"type":37,"value":418},{"type":24,"tag":119,"props":1543,"children":1544},{"style":143},[1545],{"type":37,"value":879},{"type":24,"tag":119,"props":1547,"children":1548},{"style":126},[1549],{"type":37,"value":1443},{"type":24,"tag":119,"props":1551,"children":1552},{"style":206},[1553],{"type":37,"value":797},{"type":24,"tag":119,"props":1555,"children":1556},{"style":126},[1557],{"type":37,"value":418},{"type":24,"tag":119,"props":1559,"children":1560},{"style":206},[1561],{"type":37,"value":1472},{"type":24,"tag":119,"props":1563,"children":1564},{"style":126},[1565],{"type":37,"value":1443},{"type":24,"tag":119,"props":1567,"children":1568},{"style":143},[1569],{"type":37,"value":1570},"parent.right){\n",{"type":24,"tag":119,"props":1572,"children":1574},{"class":121,"line":1573},19,[1575,1580,1584],{"type":24,"tag":119,"props":1576,"children":1577},{"style":143},[1578],{"type":37,"value":1579},"            parent.right ",{"type":24,"tag":119,"props":1581,"children":1582},{"style":126},[1583],{"type":37,"value":203},{"type":24,"tag":119,"props":1585,"children":1586},{"style":206},[1587],{"type":37,"value":243},{"type":24,"tag":119,"props":1589,"children":1591},{"class":121,"line":1590},20,[1592],{"type":24,"tag":119,"props":1593,"children":1594},{"style":259},[1595],{"type":37,"value":1596},"        // ONLY LEFT child, current node is parents LEFT node\n",{"type":24,"tag":119,"props":1598,"children":1600},{"class":121,"line":1599},21,[1601,1605,1609,1613,1618,1622,1626,1630,1634,1638,1642,1646,1650,1654],{"type":24,"tag":119,"props":1602,"children":1603},{"style":143},[1604],{"type":37,"value":1517},{"type":24,"tag":119,"props":1606,"children":1607},{"style":126},[1608],{"type":37,"value":484},{"type":24,"tag":119,"props":1610,"children":1611},{"style":126},[1612],{"type":37,"value":489},{"type":24,"tag":119,"props":1614,"children":1615},{"style":143},[1616],{"type":37,"value":1617},"(left",{"type":24,"tag":119,"props":1619,"children":1620},{"style":126},[1621],{"type":37,"value":428},{"type":24,"tag":119,"props":1623,"children":1624},{"style":206},[1625],{"type":37,"value":797},{"type":24,"tag":119,"props":1627,"children":1628},{"style":126},[1629],{"type":37,"value":418},{"type":24,"tag":119,"props":1631,"children":1632},{"style":143},[1633],{"type":37,"value":879},{"type":24,"tag":119,"props":1635,"children":1636},{"style":126},[1637],{"type":37,"value":1443},{"type":24,"tag":119,"props":1639,"children":1640},{"style":206},[1641],{"type":37,"value":797},{"type":24,"tag":119,"props":1643,"children":1644},{"style":126},[1645],{"type":37,"value":418},{"type":24,"tag":119,"props":1647,"children":1648},{"style":206},[1649],{"type":37,"value":1472},{"type":24,"tag":119,"props":1651,"children":1652},{"style":126},[1653],{"type":37,"value":1477},{"type":24,"tag":119,"props":1655,"children":1656},{"style":143},[1657],{"type":37,"value":1658}," parent.left){\n",{"type":24,"tag":119,"props":1660,"children":1662},{"class":121,"line":1661},22,[1663,1667,1671,1675],{"type":24,"tag":119,"props":1664,"children":1665},{"style":143},[1666],{"type":37,"value":1491},{"type":24,"tag":119,"props":1668,"children":1669},{"style":126},[1670],{"type":37,"value":203},{"type":24,"tag":119,"props":1672,"children":1673},{"style":206},[1674],{"type":37,"value":1472},{"type":24,"tag":119,"props":1676,"children":1677},{"style":143},[1678],{"type":37,"value":1679},".left\n",{"type":24,"tag":119,"props":1681,"children":1683},{"class":121,"line":1682},23,[1684],{"type":24,"tag":119,"props":1685,"children":1686},{"style":259},[1687],{"type":37,"value":1688},"        // ONLY LEFT child, current node is parents RIGHT node\n",{"type":24,"tag":119,"props":1690,"children":1692},{"class":121,"line":1691},24,[1693,1697,1701,1705,1709,1713,1717,1721,1725,1729,1733,1737,1741,1745],{"type":24,"tag":119,"props":1694,"children":1695},{"style":143},[1696],{"type":37,"value":1517},{"type":24,"tag":119,"props":1698,"children":1699},{"style":126},[1700],{"type":37,"value":484},{"type":24,"tag":119,"props":1702,"children":1703},{"style":126},[1704],{"type":37,"value":489},{"type":24,"tag":119,"props":1706,"children":1707},{"style":143},[1708],{"type":37,"value":1617},{"type":24,"tag":119,"props":1710,"children":1711},{"style":126},[1712],{"type":37,"value":428},{"type":24,"tag":119,"props":1714,"children":1715},{"style":206},[1716],{"type":37,"value":797},{"type":24,"tag":119,"props":1718,"children":1719},{"style":126},[1720],{"type":37,"value":418},{"type":24,"tag":119,"props":1722,"children":1723},{"style":143},[1724],{"type":37,"value":879},{"type":24,"tag":119,"props":1726,"children":1727},{"style":126},[1728],{"type":37,"value":1443},{"type":24,"tag":119,"props":1730,"children":1731},{"style":206},[1732],{"type":37,"value":209},{"type":24,"tag":119,"props":1734,"children":1735},{"style":126},[1736],{"type":37,"value":418},{"type":24,"tag":119,"props":1738,"children":1739},{"style":206},[1740],{"type":37,"value":1472},{"type":24,"tag":119,"props":1742,"children":1743},{"style":126},[1744],{"type":37,"value":1477},{"type":24,"tag":119,"props":1746,"children":1747},{"style":143},[1748],{"type":37,"value":1749}," parent.right){\n",{"type":24,"tag":119,"props":1751,"children":1753},{"class":121,"line":1752},25,[1754,1758,1762,1766],{"type":24,"tag":119,"props":1755,"children":1756},{"style":143},[1757],{"type":37,"value":1579},{"type":24,"tag":119,"props":1759,"children":1760},{"style":126},[1761],{"type":37,"value":203},{"type":24,"tag":119,"props":1763,"children":1764},{"style":206},[1765],{"type":37,"value":1472},{"type":24,"tag":119,"props":1767,"children":1768},{"style":143},[1769],{"type":37,"value":1679},{"type":24,"tag":119,"props":1771,"children":1773},{"class":121,"line":1772},26,[1774],{"type":24,"tag":119,"props":1775,"children":1776},{"style":259},[1777],{"type":37,"value":1778},"        // ONLY RIGHT child, current node is parents LEFT node\n",{"type":24,"tag":119,"props":1780,"children":1782},{"class":121,"line":1781},27,[1783,1787,1791,1795,1800,1804,1808,1812,1816,1820,1824,1828,1832,1836],{"type":24,"tag":119,"props":1784,"children":1785},{"style":143},[1786],{"type":37,"value":1517},{"type":24,"tag":119,"props":1788,"children":1789},{"style":126},[1790],{"type":37,"value":484},{"type":24,"tag":119,"props":1792,"children":1793},{"style":126},[1794],{"type":37,"value":489},{"type":24,"tag":119,"props":1796,"children":1797},{"style":143},[1798],{"type":37,"value":1799}," (right",{"type":24,"tag":119,"props":1801,"children":1802},{"style":126},[1803],{"type":37,"value":428},{"type":24,"tag":119,"props":1805,"children":1806},{"style":206},[1807],{"type":37,"value":797},{"type":24,"tag":119,"props":1809,"children":1810},{"style":126},[1811],{"type":37,"value":418},{"type":24,"tag":119,"props":1813,"children":1814},{"style":143},[1815],{"type":37,"value":815},{"type":24,"tag":119,"props":1817,"children":1818},{"style":126},[1819],{"type":37,"value":1443},{"type":24,"tag":119,"props":1821,"children":1822},{"style":206},[1823],{"type":37,"value":797},{"type":24,"tag":119,"props":1825,"children":1826},{"style":126},[1827],{"type":37,"value":418},{"type":24,"tag":119,"props":1829,"children":1830},{"style":206},[1831],{"type":37,"value":1472},{"type":24,"tag":119,"props":1833,"children":1834},{"style":126},[1835],{"type":37,"value":1477},{"type":24,"tag":119,"props":1837,"children":1838},{"style":143},[1839],{"type":37,"value":1482},{"type":24,"tag":119,"props":1841,"children":1843},{"class":121,"line":1842},28,[1844,1848,1852,1856],{"type":24,"tag":119,"props":1845,"children":1846},{"style":143},[1847],{"type":37,"value":1491},{"type":24,"tag":119,"props":1849,"children":1850},{"style":126},[1851],{"type":37,"value":203},{"type":24,"tag":119,"props":1853,"children":1854},{"style":206},[1855],{"type":37,"value":1472},{"type":24,"tag":119,"props":1857,"children":1858},{"style":143},[1859],{"type":37,"value":1860},".right\n",{"type":24,"tag":119,"props":1862,"children":1864},{"class":121,"line":1863},29,[1865],{"type":24,"tag":119,"props":1866,"children":1867},{"style":259},[1868],{"type":37,"value":1869},"        // ONLY RIGHT child, current node is parents RIGHT node\n",{"type":24,"tag":119,"props":1871,"children":1873},{"class":121,"line":1872},30,[1874,1878,1882,1886,1891,1895,1899,1903,1907,1911,1915,1919,1923,1927],{"type":24,"tag":119,"props":1875,"children":1876},{"style":143},[1877],{"type":37,"value":1517},{"type":24,"tag":119,"props":1879,"children":1880},{"style":126},[1881],{"type":37,"value":484},{"type":24,"tag":119,"props":1883,"children":1884},{"style":126},[1885],{"type":37,"value":489},{"type":24,"tag":119,"props":1887,"children":1888},{"style":143},[1889],{"type":37,"value":1890},"(right",{"type":24,"tag":119,"props":1892,"children":1893},{"style":126},[1894],{"type":37,"value":428},{"type":24,"tag":119,"props":1896,"children":1897},{"style":206},[1898],{"type":37,"value":797},{"type":24,"tag":119,"props":1900,"children":1901},{"style":126},[1902],{"type":37,"value":418},{"type":24,"tag":119,"props":1904,"children":1905},{"style":143},[1906],{"type":37,"value":815},{"type":24,"tag":119,"props":1908,"children":1909},{"style":126},[1910],{"type":37,"value":1443},{"type":24,"tag":119,"props":1912,"children":1913},{"style":206},[1914],{"type":37,"value":797},{"type":24,"tag":119,"props":1916,"children":1917},{"style":126},[1918],{"type":37,"value":418},{"type":24,"tag":119,"props":1920,"children":1921},{"style":206},[1922],{"type":37,"value":1472},{"type":24,"tag":119,"props":1924,"children":1925},{"style":126},[1926],{"type":37,"value":1477},{"type":24,"tag":119,"props":1928,"children":1929},{"style":143},[1930],{"type":37,"value":1931}," parent.right) {\n",{"type":24,"tag":119,"props":1933,"children":1935},{"class":121,"line":1934},31,[1936,1940,1944,1948],{"type":24,"tag":119,"props":1937,"children":1938},{"style":143},[1939],{"type":37,"value":1579},{"type":24,"tag":119,"props":1941,"children":1942},{"style":126},[1943],{"type":37,"value":203},{"type":24,"tag":119,"props":1945,"children":1946},{"style":206},[1947],{"type":37,"value":1472},{"type":24,"tag":119,"props":1949,"children":1950},{"style":143},[1951],{"type":37,"value":1860},{"type":24,"tag":119,"props":1953,"children":1955},{"class":121,"line":1954},32,[1956],{"type":24,"tag":119,"props":1957,"children":1958},{"style":259},[1959],{"type":37,"value":1960},"        // BOTH Children exists, replace current data with min value from right \n",{"type":24,"tag":119,"props":1962,"children":1964},{"class":121,"line":1963},33,[1965,1969,1973],{"type":24,"tag":119,"props":1966,"children":1967},{"style":143},[1968],{"type":37,"value":1517},{"type":24,"tag":119,"props":1970,"children":1971},{"style":126},[1972],{"type":37,"value":484},{"type":24,"tag":119,"props":1974,"children":1975},{"style":143},[1976],{"type":37,"value":636},{"type":24,"tag":119,"props":1978,"children":1980},{"class":121,"line":1979},34,[1981,1986,1991,1995,1999,2003,2008],{"type":24,"tag":119,"props":1982,"children":1983},{"style":126},[1984],{"type":37,"value":1985},"            data",{"type":24,"tag":119,"props":1987,"children":1988},{"style":126},[1989],{"type":37,"value":1990}," =",{"type":24,"tag":119,"props":1992,"children":1993},{"style":143},[1994],{"type":37,"value":879},{"type":24,"tag":119,"props":1996,"children":1997},{"style":126},[1998],{"type":37,"value":449},{"type":24,"tag":119,"props":2000,"children":2001},{"style":143},[2002],{"type":37,"value":108},{"type":24,"tag":119,"props":2004,"children":2005},{"style":137},[2006],{"type":37,"value":2007},"min",{"type":24,"tag":119,"props":2009,"children":2010},{"style":143},[2011],{"type":37,"value":2012},"()\n",{"type":24,"tag":119,"props":2014,"children":2016},{"class":121,"line":2015},35,[2017,2022,2026,2030,2034,2038,2042,2046,2050],{"type":24,"tag":119,"props":2018,"children":2019},{"style":143},[2020],{"type":37,"value":2021},"            right",{"type":24,"tag":119,"props":2023,"children":2024},{"style":126},[2025],{"type":37,"value":449},{"type":24,"tag":119,"props":2027,"children":2028},{"style":143},[2029],{"type":37,"value":108},{"type":24,"tag":119,"props":2031,"children":2032},{"style":137},[2033],{"type":37,"value":1195},{"type":24,"tag":119,"props":2035,"children":2036},{"style":143},[2037],{"type":37,"value":371},{"type":24,"tag":119,"props":2039,"children":2040},{"style":126},[2041],{"type":37,"value":129},{"type":24,"tag":119,"props":2043,"children":2044},{"style":143},[2045],{"type":37,"value":1208},{"type":24,"tag":119,"props":2047,"children":2048},{"style":206},[2049],{"type":37,"value":1213},{"type":24,"tag":119,"props":2051,"children":2052},{"style":143},[2053],{"type":37,"value":471},{"type":24,"tag":119,"props":2055,"children":2057},{"class":121,"line":2056},36,[2058],{"type":24,"tag":119,"props":2059,"children":2060},{"style":143},[2061],{"type":37,"value":2062},"        }\n",{"type":24,"tag":119,"props":2064,"children":2066},{"class":121,"line":2065},37,[2067,2071],{"type":24,"tag":119,"props":2068,"children":2069},{"style":126},[2070],{"type":37,"value":810},{"type":24,"tag":119,"props":2072,"children":2073},{"style":206},[2074],{"type":37,"value":2075}," true\n",{"type":24,"tag":119,"props":2077,"children":2079},{"class":121,"line":2078},38,[2080],{"type":24,"tag":119,"props":2081,"children":2082},{"style":143},[2083],{"type":37,"value":674},{"type":24,"tag":119,"props":2085,"children":2087},{"class":121,"line":2086},39,[2088],{"type":24,"tag":119,"props":2089,"children":2090},{"style":143},[2091],{"type":37,"value":271},{"type":24,"tag":119,"props":2093,"children":2095},{"class":121,"line":2094},40,[2096],{"type":24,"tag":119,"props":2097,"children":2099},{"emptyLinePlaceholder":2098},true,[2100],{"type":37,"value":2101},"\n",{"type":24,"tag":119,"props":2103,"children":2105},{"class":121,"line":2104},41,[2106,2110,2115,2120,2124,2128,2132,2137,2141,2145,2150,2154,2159,2163,2167,2171,2175],{"type":24,"tag":119,"props":2107,"children":2108},{"style":126},[2109],{"type":37,"value":361},{"type":24,"tag":119,"props":2111,"children":2112},{"style":137},[2113],{"type":37,"value":2114}," min",{"type":24,"tag":119,"props":2116,"children":2117},{"style":143},[2118],{"type":37,"value":2119},"() : ",{"type":24,"tag":119,"props":2121,"children":2122},{"style":137},[2123],{"type":37,"value":170},{"type":24,"tag":119,"props":2125,"children":2126},{"style":126},[2127],{"type":37,"value":1990},{"type":24,"tag":119,"props":2129,"children":2130},{"style":126},[2131],{"type":37,"value":489},{"type":24,"tag":119,"props":2133,"children":2134},{"style":143},[2135],{"type":37,"value":2136}," (left",{"type":24,"tag":119,"props":2138,"children":2139},{"style":126},[2140],{"type":37,"value":1443},{"type":24,"tag":119,"props":2142,"children":2143},{"style":206},[2144],{"type":37,"value":797},{"type":24,"tag":119,"props":2146,"children":2147},{"style":143},[2148],{"type":37,"value":2149},") ",{"type":24,"tag":119,"props":2151,"children":2152},{"style":126},[2153],{"type":37,"value":129},{"type":24,"tag":119,"props":2155,"children":2156},{"style":126},[2157],{"type":37,"value":2158}," else",{"type":24,"tag":119,"props":2160,"children":2161},{"style":143},[2162],{"type":37,"value":815},{"type":24,"tag":119,"props":2164,"children":2165},{"style":126},[2166],{"type":37,"value":449},{"type":24,"tag":119,"props":2168,"children":2169},{"style":143},[2170],{"type":37,"value":108},{"type":24,"tag":119,"props":2172,"children":2173},{"style":137},[2174],{"type":37,"value":2007},{"type":24,"tag":119,"props":2176,"children":2177},{"style":143},[2178],{"type":37,"value":2012},{"type":24,"tag":29,"props":2180,"children":2181},{},[2182,2184],{"type":37,"value":2183},"You can find the complete code of this example in this\n",{"type":24,"tag":42,"props":2185,"children":2187},{"href":2186,"target":103},"https://github.com/JaimeDeArcos/kotlin-algorithms/blob/main/trees/src/main/kotlin/es/jaimedearcos/algorithms/tree/data/BinarySearchTreeNode.kt",[2188],{"type":37,"value":2189},"\nGitHub repository\n",{"type":24,"tag":2191,"props":2192,"children":2193},"style",{},[2194],{"type":37,"value":2195},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":8,"searchDepth":149,"depth":149,"links":2197},[2198,2199,2200,2201],{"id":91,"depth":149,"text":94},{"id":286,"depth":149,"text":289},{"id":685,"depth":149,"text":688},{"id":956,"depth":149,"text":959},"markdown","content:posts:algorithms-binary-search-tree.md","content","posts/algorithms-binary-search-tree.md","posts/algorithms-binary-search-tree","md",{"_path":2209,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":2210,"description":2211,"date":2212,"layout":12,"subtitle":2211,"image":13,"optimized_image":13,"category":14,"tags":2213,"author":19,"paginate":7,"body":2214,"_type":2202,"_id":3422,"_source":2204,"_file":3423,"_stem":3424,"_extension":2207},"/posts/algorithms-working-with-trees","Algorithms - Binary tree traversals in kotlin","A simple walkthrough of binary tree traversals algorithms with kotlin examples","2020-11-24T11:00:00.000Z",[16,17,18,14],{"type":21,"children":2215,"toc":3415},[2216,2222,2241,2246,2287,2293,2298,2362,2369,2379,2387,2506,2514,2681,2689,2841,2849,3003,3009,3016,3021,3052,3400,3411],{"type":24,"tag":89,"props":2217,"children":2219},{"id":2218},"traversals",[2220],{"type":37,"value":2221},"Traversals :",{"type":24,"tag":25,"props":2223,"children":2224},{},[2225],{"type":24,"tag":29,"props":2226,"children":2227},{},[2228,2233,2235],{"type":24,"tag":33,"props":2229,"children":2230},{},[2231],{"type":37,"value":2232},"\"Tree traversal refers to the process of visiting (checking and/or updating) each node in a tree data structure,\nexactly once. Such traversals are classified by the order in which the nodes are visited.\"",{"type":37,"value":2234}," -— ",{"type":24,"tag":42,"props":2236,"children":2239},{"href":2237,"rel":2238},"https://en.wikipedia.org/wiki/Tree_traversal",[46],[2240],{"type":37,"value":49},{"type":24,"tag":29,"props":2242,"children":2243},{},[2244],{"type":37,"value":2245},"There are 2 options:",{"type":24,"tag":296,"props":2247,"children":2248},{},[2249,2265],{"type":24,"tag":300,"props":2250,"children":2251},{},[2252,2257,2259],{"type":24,"tag":56,"props":2253,"children":2254},{},[2255],{"type":37,"value":2256},"DFS",{"type":37,"value":2258}," : Depth-First Search _“is an algorithm for traversing or searching tree data structure. One starts at the\nroot and explores as far as possible along each branch before backtracking.” -— ",{"type":24,"tag":42,"props":2260,"children":2263},{"href":2261,"rel":2262},"https://en.wikipedia.org/wiki/Depth-first_search",[46],[2264],{"type":37,"value":49},{"type":24,"tag":300,"props":2266,"children":2267},{},[2268,2273,2275,2280,2281],{"type":24,"tag":56,"props":2269,"children":2270},{},[2271],{"type":37,"value":2272},"BFS",{"type":37,"value":2274}," : Breadth-First Search ",{"type":24,"tag":33,"props":2276,"children":2277},{},[2278],{"type":37,"value":2279},"“is an algorithm for traversing or searching tree data structure. It starts at the tree root and explores the\nneighbor nodes first, before moving to the next level neighbors.\"",{"type":37,"value":2234},{"type":24,"tag":42,"props":2282,"children":2285},{"href":2283,"rel":2284},"https://en.wikipedia.org/wiki/Breadth-first_search",[46],[2286],{"type":37,"value":49},{"type":24,"tag":89,"props":2288,"children":2290},{"id":2289},"dfs-depth-first-search",[2291],{"type":37,"value":2292},"DFS - Depth-First Search",{"type":24,"tag":29,"props":2294,"children":2295},{},[2296],{"type":37,"value":2297},"DFS algorithms start from the root and goes deep as possible until they find a leaf before backtracking and exploring another\npath. The main 3 DFS types are:",{"type":24,"tag":296,"props":2299,"children":2300},{},[2301,2322,2342],{"type":24,"tag":300,"props":2302,"children":2303},{},[2304,2309,2311,2316,2318],{"type":24,"tag":56,"props":2305,"children":2306},{},[2307],{"type":37,"value":2308},"Pre-Order",{"type":37,"value":2310},": ",{"type":24,"tag":33,"props":2312,"children":2313},{},[2314],{"type":37,"value":2315},"(NLR)",{"type":37,"value":2317}," process node data, left child and finally right child\n",{"type":24,"tag":84,"props":2319,"children":2321},{"alt":8,"src":2320},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/pre-order.gif",[],{"type":24,"tag":300,"props":2323,"children":2324},{},[2325,2330,2331,2336,2338],{"type":24,"tag":56,"props":2326,"children":2327},{},[2328],{"type":37,"value":2329},"In-Order",{"type":37,"value":2310},{"type":24,"tag":33,"props":2332,"children":2333},{},[2334],{"type":37,"value":2335},"(LNR)",{"type":37,"value":2337}," process left child, node data and finally right child\n",{"type":24,"tag":84,"props":2339,"children":2341},{"alt":8,"src":2340},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/in-order.gif",[],{"type":24,"tag":300,"props":2343,"children":2344},{},[2345,2350,2351,2356,2358],{"type":24,"tag":56,"props":2346,"children":2347},{},[2348],{"type":37,"value":2349},"Post-Order",{"type":37,"value":2310},{"type":24,"tag":33,"props":2352,"children":2353},{},[2354],{"type":37,"value":2355},"(LRN)",{"type":37,"value":2357}," process left child, right child and finally node data\n",{"type":24,"tag":84,"props":2359,"children":2361},{"alt":8,"src":2360},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/post-order.gif",[],{"type":24,"tag":2363,"props":2364,"children":2366},"h3",{"id":2365},"kotlin-examples",[2367],{"type":37,"value":2368},"Kotlin Examples:",{"type":24,"tag":29,"props":2370,"children":2371},{},[2372,2374,2378],{"type":37,"value":2373},"Usually the DFS algorithms are ease to implement with ",{"type":24,"tag":56,"props":2375,"children":2376},{},[2377],{"type":37,"value":999},{"type":37,"value":108},{"type":24,"tag":29,"props":2380,"children":2381},{},[2382],{"type":24,"tag":56,"props":2383,"children":2384},{},[2385],{"type":37,"value":2386},"Binary tree",{"type":24,"tag":110,"props":2388,"children":2390},{"className":112,"code":2389,"language":17,"meta":8,"style":8},"data class BinaryTreeNode(\n        val data:Int,\n        val left:BinaryTreeNode? = null,\n        val right:BinaryTreeNode? = null\n)\n",[2391],{"type":24,"tag":16,"props":2392,"children":2393},{"__ignoreMap":8},[2394,2414,2438,2471,2499],{"type":24,"tag":119,"props":2395,"children":2396},{"class":121,"line":122},[2397,2401,2405,2410],{"type":24,"tag":119,"props":2398,"children":2399},{"style":126},[2400],{"type":37,"value":129},{"type":24,"tag":119,"props":2402,"children":2403},{"style":126},[2404],{"type":37,"value":134},{"type":24,"tag":119,"props":2406,"children":2407},{"style":137},[2408],{"type":37,"value":2409}," BinaryTreeNode",{"type":24,"tag":119,"props":2411,"children":2412},{"style":143},[2413],{"type":37,"value":146},{"type":24,"tag":119,"props":2415,"children":2416},{"class":121,"line":149},[2417,2422,2426,2430,2434],{"type":24,"tag":119,"props":2418,"children":2419},{"style":126},[2420],{"type":37,"value":2421},"        val",{"type":24,"tag":119,"props":2423,"children":2424},{"style":126},[2425],{"type":37,"value":160},{"type":24,"tag":119,"props":2427,"children":2428},{"style":143},[2429],{"type":37,"value":165},{"type":24,"tag":119,"props":2431,"children":2432},{"style":137},[2433],{"type":37,"value":170},{"type":24,"tag":119,"props":2435,"children":2436},{"style":143},[2437],{"type":37,"value":175},{"type":24,"tag":119,"props":2439,"children":2440},{"class":121,"line":178},[2441,2445,2450,2455,2459,2463,2467],{"type":24,"tag":119,"props":2442,"children":2443},{"style":126},[2444],{"type":37,"value":2421},{"type":24,"tag":119,"props":2446,"children":2447},{"style":143},[2448],{"type":37,"value":2449}," left:",{"type":24,"tag":119,"props":2451,"children":2452},{"style":137},[2453],{"type":37,"value":2454},"BinaryTreeNode",{"type":24,"tag":119,"props":2456,"children":2457},{"style":143},[2458],{"type":37,"value":198},{"type":24,"tag":119,"props":2460,"children":2461},{"style":126},[2462],{"type":37,"value":203},{"type":24,"tag":119,"props":2464,"children":2465},{"style":206},[2466],{"type":37,"value":209},{"type":24,"tag":119,"props":2468,"children":2469},{"style":143},[2470],{"type":37,"value":175},{"type":24,"tag":119,"props":2472,"children":2473},{"class":121,"line":216},[2474,2478,2483,2487,2491,2495],{"type":24,"tag":119,"props":2475,"children":2476},{"style":126},[2477],{"type":37,"value":2421},{"type":24,"tag":119,"props":2479,"children":2480},{"style":143},[2481],{"type":37,"value":2482}," right:",{"type":24,"tag":119,"props":2484,"children":2485},{"style":137},[2486],{"type":37,"value":2454},{"type":24,"tag":119,"props":2488,"children":2489},{"style":143},[2490],{"type":37,"value":198},{"type":24,"tag":119,"props":2492,"children":2493},{"style":126},[2494],{"type":37,"value":203},{"type":24,"tag":119,"props":2496,"children":2497},{"style":206},[2498],{"type":37,"value":243},{"type":24,"tag":119,"props":2500,"children":2501},{"class":121,"line":246},[2502],{"type":24,"tag":119,"props":2503,"children":2504},{"style":143},[2505],{"type":37,"value":471},{"type":24,"tag":29,"props":2507,"children":2508},{},[2509],{"type":24,"tag":56,"props":2510,"children":2511},{},[2512],{"type":37,"value":2513},"Preorder traversal",{"type":24,"tag":110,"props":2515,"children":2517},{"className":112,"code":2516,"language":17,"meta":8,"style":8},"fun preOrderTraversal(node: BinaryTreeNode?, \n                      operation: (BinaryTreeNode) -> Unit){\n    if (node == null) return;\n    // Visit node\n    operation.invoke(node)\n    // Traverse left\n    preOrderTraversal(node.left,operation);\n    // Traverse right\n    preOrderTraversal(node.right,operation);\n}\n",[2518],{"type":24,"tag":16,"props":2519,"children":2520},{"__ignoreMap":8},[2521,2547,2573,2607,2615,2633,2641,2654,2662,2674],{"type":24,"tag":119,"props":2522,"children":2523},{"class":121,"line":122},[2524,2528,2533,2538,2542],{"type":24,"tag":119,"props":2525,"children":2526},{"style":126},[2527],{"type":37,"value":361},{"type":24,"tag":119,"props":2529,"children":2530},{"style":137},[2531],{"type":37,"value":2532}," preOrderTraversal",{"type":24,"tag":119,"props":2534,"children":2535},{"style":143},[2536],{"type":37,"value":2537},"(node: ",{"type":24,"tag":119,"props":2539,"children":2540},{"style":137},[2541],{"type":37,"value":2454},{"type":24,"tag":119,"props":2543,"children":2544},{"style":143},[2545],{"type":37,"value":2546},"?, \n",{"type":24,"tag":119,"props":2548,"children":2549},{"class":121,"line":149},[2550,2555,2559,2564,2569],{"type":24,"tag":119,"props":2551,"children":2552},{"style":143},[2553],{"type":37,"value":2554},"                      operation: (",{"type":24,"tag":119,"props":2556,"children":2557},{"style":137},[2558],{"type":37,"value":2454},{"type":24,"tag":119,"props":2560,"children":2561},{"style":143},[2562],{"type":37,"value":2563},") -> ",{"type":24,"tag":119,"props":2565,"children":2566},{"style":137},[2567],{"type":37,"value":2568},"Unit",{"type":24,"tag":119,"props":2570,"children":2571},{"style":143},[2572],{"type":37,"value":252},{"type":24,"tag":119,"props":2574,"children":2575},{"class":121,"line":178},[2576,2580,2585,2589,2593,2597,2602],{"type":24,"tag":119,"props":2577,"children":2578},{"style":126},[2579],{"type":37,"value":396},{"type":24,"tag":119,"props":2581,"children":2582},{"style":143},[2583],{"type":37,"value":2584}," (node ",{"type":24,"tag":119,"props":2586,"children":2587},{"style":126},[2588],{"type":37,"value":1443},{"type":24,"tag":119,"props":2590,"children":2591},{"style":206},[2592],{"type":37,"value":209},{"type":24,"tag":119,"props":2594,"children":2595},{"style":143},[2596],{"type":37,"value":2149},{"type":24,"tag":119,"props":2598,"children":2599},{"style":126},[2600],{"type":37,"value":2601},"return",{"type":24,"tag":119,"props":2603,"children":2604},{"style":143},[2605],{"type":37,"value":2606},";\n",{"type":24,"tag":119,"props":2608,"children":2609},{"class":121,"line":216},[2610],{"type":24,"tag":119,"props":2611,"children":2612},{"style":259},[2613],{"type":37,"value":2614},"    // Visit node\n",{"type":24,"tag":119,"props":2616,"children":2617},{"class":121,"line":246},[2618,2623,2628],{"type":24,"tag":119,"props":2619,"children":2620},{"style":143},[2621],{"type":37,"value":2622},"    operation.",{"type":24,"tag":119,"props":2624,"children":2625},{"style":137},[2626],{"type":37,"value":2627},"invoke",{"type":24,"tag":119,"props":2629,"children":2630},{"style":143},[2631],{"type":37,"value":2632},"(node)\n",{"type":24,"tag":119,"props":2634,"children":2635},{"class":121,"line":255},[2636],{"type":24,"tag":119,"props":2637,"children":2638},{"style":259},[2639],{"type":37,"value":2640},"    // Traverse left\n",{"type":24,"tag":119,"props":2642,"children":2643},{"class":121,"line":265},[2644,2649],{"type":24,"tag":119,"props":2645,"children":2646},{"style":137},[2647],{"type":37,"value":2648},"    preOrderTraversal",{"type":24,"tag":119,"props":2650,"children":2651},{"style":143},[2652],{"type":37,"value":2653},"(node.left,operation);\n",{"type":24,"tag":119,"props":2655,"children":2656},{"class":121,"line":622},[2657],{"type":24,"tag":119,"props":2658,"children":2659},{"style":259},[2660],{"type":37,"value":2661},"    // Traverse right\n",{"type":24,"tag":119,"props":2663,"children":2664},{"class":121,"line":639},[2665,2669],{"type":24,"tag":119,"props":2666,"children":2667},{"style":137},[2668],{"type":37,"value":2648},{"type":24,"tag":119,"props":2670,"children":2671},{"style":143},[2672],{"type":37,"value":2673},"(node.right,operation);\n",{"type":24,"tag":119,"props":2675,"children":2676},{"class":121,"line":668},[2677],{"type":24,"tag":119,"props":2678,"children":2679},{"style":143},[2680],{"type":37,"value":271},{"type":24,"tag":29,"props":2682,"children":2683},{},[2684],{"type":24,"tag":56,"props":2685,"children":2686},{},[2687],{"type":37,"value":2688},"InOrder traversal",{"type":24,"tag":110,"props":2690,"children":2692},{"className":112,"code":2691,"language":17,"meta":8,"style":8},"fun inOrderTraversal(node: BinaryTreeNode?, \n                     operation: (BinaryTreeNode) -> Unit){\n    if (node == null) return;\n    // Traverse left\n    inOrderTraversal(node.left,operation);\n    // Visit node\n    operation.invoke(node)\n    // Traverse right\n    inOrderTraversal(node.right,operation);\n}\n",[2693],{"type":24,"tag":16,"props":2694,"children":2695},{"__ignoreMap":8},[2696,2720,2744,2775,2782,2794,2801,2816,2823,2834],{"type":24,"tag":119,"props":2697,"children":2698},{"class":121,"line":122},[2699,2703,2708,2712,2716],{"type":24,"tag":119,"props":2700,"children":2701},{"style":126},[2702],{"type":37,"value":361},{"type":24,"tag":119,"props":2704,"children":2705},{"style":137},[2706],{"type":37,"value":2707}," inOrderTraversal",{"type":24,"tag":119,"props":2709,"children":2710},{"style":143},[2711],{"type":37,"value":2537},{"type":24,"tag":119,"props":2713,"children":2714},{"style":137},[2715],{"type":37,"value":2454},{"type":24,"tag":119,"props":2717,"children":2718},{"style":143},[2719],{"type":37,"value":2546},{"type":24,"tag":119,"props":2721,"children":2722},{"class":121,"line":149},[2723,2728,2732,2736,2740],{"type":24,"tag":119,"props":2724,"children":2725},{"style":143},[2726],{"type":37,"value":2727},"                     operation: (",{"type":24,"tag":119,"props":2729,"children":2730},{"style":137},[2731],{"type":37,"value":2454},{"type":24,"tag":119,"props":2733,"children":2734},{"style":143},[2735],{"type":37,"value":2563},{"type":24,"tag":119,"props":2737,"children":2738},{"style":137},[2739],{"type":37,"value":2568},{"type":24,"tag":119,"props":2741,"children":2742},{"style":143},[2743],{"type":37,"value":252},{"type":24,"tag":119,"props":2745,"children":2746},{"class":121,"line":178},[2747,2751,2755,2759,2763,2767,2771],{"type":24,"tag":119,"props":2748,"children":2749},{"style":126},[2750],{"type":37,"value":396},{"type":24,"tag":119,"props":2752,"children":2753},{"style":143},[2754],{"type":37,"value":2584},{"type":24,"tag":119,"props":2756,"children":2757},{"style":126},[2758],{"type":37,"value":1443},{"type":24,"tag":119,"props":2760,"children":2761},{"style":206},[2762],{"type":37,"value":209},{"type":24,"tag":119,"props":2764,"children":2765},{"style":143},[2766],{"type":37,"value":2149},{"type":24,"tag":119,"props":2768,"children":2769},{"style":126},[2770],{"type":37,"value":2601},{"type":24,"tag":119,"props":2772,"children":2773},{"style":143},[2774],{"type":37,"value":2606},{"type":24,"tag":119,"props":2776,"children":2777},{"class":121,"line":216},[2778],{"type":24,"tag":119,"props":2779,"children":2780},{"style":259},[2781],{"type":37,"value":2640},{"type":24,"tag":119,"props":2783,"children":2784},{"class":121,"line":246},[2785,2790],{"type":24,"tag":119,"props":2786,"children":2787},{"style":137},[2788],{"type":37,"value":2789},"    inOrderTraversal",{"type":24,"tag":119,"props":2791,"children":2792},{"style":143},[2793],{"type":37,"value":2653},{"type":24,"tag":119,"props":2795,"children":2796},{"class":121,"line":255},[2797],{"type":24,"tag":119,"props":2798,"children":2799},{"style":259},[2800],{"type":37,"value":2614},{"type":24,"tag":119,"props":2802,"children":2803},{"class":121,"line":265},[2804,2808,2812],{"type":24,"tag":119,"props":2805,"children":2806},{"style":143},[2807],{"type":37,"value":2622},{"type":24,"tag":119,"props":2809,"children":2810},{"style":137},[2811],{"type":37,"value":2627},{"type":24,"tag":119,"props":2813,"children":2814},{"style":143},[2815],{"type":37,"value":2632},{"type":24,"tag":119,"props":2817,"children":2818},{"class":121,"line":622},[2819],{"type":24,"tag":119,"props":2820,"children":2821},{"style":259},[2822],{"type":37,"value":2661},{"type":24,"tag":119,"props":2824,"children":2825},{"class":121,"line":639},[2826,2830],{"type":24,"tag":119,"props":2827,"children":2828},{"style":137},[2829],{"type":37,"value":2789},{"type":24,"tag":119,"props":2831,"children":2832},{"style":143},[2833],{"type":37,"value":2673},{"type":24,"tag":119,"props":2835,"children":2836},{"class":121,"line":668},[2837],{"type":24,"tag":119,"props":2838,"children":2839},{"style":143},[2840],{"type":37,"value":271},{"type":24,"tag":29,"props":2842,"children":2843},{},[2844],{"type":24,"tag":56,"props":2845,"children":2846},{},[2847],{"type":37,"value":2848},"PostOrder traversal",{"type":24,"tag":110,"props":2850,"children":2852},{"className":112,"code":2851,"language":17,"meta":8,"style":8},"fun postOrderTraversal(node: BinaryTreeNode?, \n                       operation: (BinaryTreeNode) -> Unit){\n    if (node == null) return;\n    // Traverse left\n    postOrderTraversal(node.left,operation)\n    // Traverse right\n    postOrderTraversal(node.right,operation)\n    // Visit node\n    operation.invoke(node)\n}\n",[2853],{"type":24,"tag":16,"props":2854,"children":2855},{"__ignoreMap":8},[2856,2880,2904,2935,2942,2955,2962,2974,2981,2996],{"type":24,"tag":119,"props":2857,"children":2858},{"class":121,"line":122},[2859,2863,2868,2872,2876],{"type":24,"tag":119,"props":2860,"children":2861},{"style":126},[2862],{"type":37,"value":361},{"type":24,"tag":119,"props":2864,"children":2865},{"style":137},[2866],{"type":37,"value":2867}," postOrderTraversal",{"type":24,"tag":119,"props":2869,"children":2870},{"style":143},[2871],{"type":37,"value":2537},{"type":24,"tag":119,"props":2873,"children":2874},{"style":137},[2875],{"type":37,"value":2454},{"type":24,"tag":119,"props":2877,"children":2878},{"style":143},[2879],{"type":37,"value":2546},{"type":24,"tag":119,"props":2881,"children":2882},{"class":121,"line":149},[2883,2888,2892,2896,2900],{"type":24,"tag":119,"props":2884,"children":2885},{"style":143},[2886],{"type":37,"value":2887},"                       operation: (",{"type":24,"tag":119,"props":2889,"children":2890},{"style":137},[2891],{"type":37,"value":2454},{"type":24,"tag":119,"props":2893,"children":2894},{"style":143},[2895],{"type":37,"value":2563},{"type":24,"tag":119,"props":2897,"children":2898},{"style":137},[2899],{"type":37,"value":2568},{"type":24,"tag":119,"props":2901,"children":2902},{"style":143},[2903],{"type":37,"value":252},{"type":24,"tag":119,"props":2905,"children":2906},{"class":121,"line":178},[2907,2911,2915,2919,2923,2927,2931],{"type":24,"tag":119,"props":2908,"children":2909},{"style":126},[2910],{"type":37,"value":396},{"type":24,"tag":119,"props":2912,"children":2913},{"style":143},[2914],{"type":37,"value":2584},{"type":24,"tag":119,"props":2916,"children":2917},{"style":126},[2918],{"type":37,"value":1443},{"type":24,"tag":119,"props":2920,"children":2921},{"style":206},[2922],{"type":37,"value":209},{"type":24,"tag":119,"props":2924,"children":2925},{"style":143},[2926],{"type":37,"value":2149},{"type":24,"tag":119,"props":2928,"children":2929},{"style":126},[2930],{"type":37,"value":2601},{"type":24,"tag":119,"props":2932,"children":2933},{"style":143},[2934],{"type":37,"value":2606},{"type":24,"tag":119,"props":2936,"children":2937},{"class":121,"line":216},[2938],{"type":24,"tag":119,"props":2939,"children":2940},{"style":259},[2941],{"type":37,"value":2640},{"type":24,"tag":119,"props":2943,"children":2944},{"class":121,"line":246},[2945,2950],{"type":24,"tag":119,"props":2946,"children":2947},{"style":137},[2948],{"type":37,"value":2949},"    postOrderTraversal",{"type":24,"tag":119,"props":2951,"children":2952},{"style":143},[2953],{"type":37,"value":2954},"(node.left,operation)\n",{"type":24,"tag":119,"props":2956,"children":2957},{"class":121,"line":255},[2958],{"type":24,"tag":119,"props":2959,"children":2960},{"style":259},[2961],{"type":37,"value":2661},{"type":24,"tag":119,"props":2963,"children":2964},{"class":121,"line":265},[2965,2969],{"type":24,"tag":119,"props":2966,"children":2967},{"style":137},[2968],{"type":37,"value":2949},{"type":24,"tag":119,"props":2970,"children":2971},{"style":143},[2972],{"type":37,"value":2973},"(node.right,operation)\n",{"type":24,"tag":119,"props":2975,"children":2976},{"class":121,"line":622},[2977],{"type":24,"tag":119,"props":2978,"children":2979},{"style":259},[2980],{"type":37,"value":2614},{"type":24,"tag":119,"props":2982,"children":2983},{"class":121,"line":639},[2984,2988,2992],{"type":24,"tag":119,"props":2985,"children":2986},{"style":143},[2987],{"type":37,"value":2622},{"type":24,"tag":119,"props":2989,"children":2990},{"style":137},[2991],{"type":37,"value":2627},{"type":24,"tag":119,"props":2993,"children":2994},{"style":143},[2995],{"type":37,"value":2632},{"type":24,"tag":119,"props":2997,"children":2998},{"class":121,"line":668},[2999],{"type":24,"tag":119,"props":3000,"children":3001},{"style":143},[3002],{"type":37,"value":271},{"type":24,"tag":89,"props":3004,"children":3006},{"id":3005},"bfs-breadth-first-search",[3007],{"type":37,"value":3008},"BFS - Breadth-First Search",{"type":24,"tag":29,"props":3010,"children":3011},{},[3012],{"type":24,"tag":84,"props":3013,"children":3015},{"alt":8,"src":3014},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/bfs.gif",[],{"type":24,"tag":29,"props":3017,"children":3018},{},[3019],{"type":37,"value":3020},"For BFS algorithm we are going to use a queue:",{"type":24,"tag":296,"props":3022,"children":3023},{},[3024,3029],{"type":24,"tag":300,"props":3025,"children":3026},{},[3027],{"type":37,"value":3028},"Push root node to the queue",{"type":24,"tag":300,"props":3030,"children":3031},{},[3032,3034],{"type":37,"value":3033},"While queue is not empty:",{"type":24,"tag":296,"props":3035,"children":3036},{},[3037,3042,3047],{"type":24,"tag":300,"props":3038,"children":3039},{},[3040],{"type":37,"value":3041},"Poll element from queue and process data",{"type":24,"tag":300,"props":3043,"children":3044},{},[3045],{"type":37,"value":3046},"If left child exist, add to the queue",{"type":24,"tag":300,"props":3048,"children":3049},{},[3050],{"type":37,"value":3051},"If right child exist, add to the queue",{"type":24,"tag":110,"props":3053,"children":3055},{"className":112,"code":3054,"language":17,"meta":8,"style":8},"   fun bfs(node: BinaryTreeNode, operation: (BinaryTreeNode) -> Unit){\n\n        val queue = LinkedList\u003CBinaryTreeNode>() as Queue\u003CBinaryTreeNode>\n        queue.offer(node)\n        var current : BinaryTreeNode\n\n        while(!queue.isEmpty()){\n            current = queue.poll()\n            operation.invoke(current)\n\n            if (current.left != null){\n                queue.offer(current.left)\n            }\n            if (current.right != null){\n                queue.offer(current.right)\n            }\n        }\n    }\n",[3056],{"type":24,"tag":16,"props":3057,"children":3058},{"__ignoreMap":8},[3059,3101,3108,3166,3183,3200,3207,3239,3265,3282,3289,3314,3331,3339,3363,3379,3386,3393],{"type":24,"tag":119,"props":3060,"children":3061},{"class":121,"line":122},[3062,3067,3072,3076,3080,3085,3089,3093,3097],{"type":24,"tag":119,"props":3063,"children":3064},{"style":126},[3065],{"type":37,"value":3066},"   fun",{"type":24,"tag":119,"props":3068,"children":3069},{"style":137},[3070],{"type":37,"value":3071}," bfs",{"type":24,"tag":119,"props":3073,"children":3074},{"style":143},[3075],{"type":37,"value":2537},{"type":24,"tag":119,"props":3077,"children":3078},{"style":137},[3079],{"type":37,"value":2454},{"type":24,"tag":119,"props":3081,"children":3082},{"style":143},[3083],{"type":37,"value":3084},", operation: (",{"type":24,"tag":119,"props":3086,"children":3087},{"style":137},[3088],{"type":37,"value":2454},{"type":24,"tag":119,"props":3090,"children":3091},{"style":143},[3092],{"type":37,"value":2563},{"type":24,"tag":119,"props":3094,"children":3095},{"style":137},[3096],{"type":37,"value":2568},{"type":24,"tag":119,"props":3098,"children":3099},{"style":143},[3100],{"type":37,"value":252},{"type":24,"tag":119,"props":3102,"children":3103},{"class":121,"line":149},[3104],{"type":24,"tag":119,"props":3105,"children":3106},{"emptyLinePlaceholder":2098},[3107],{"type":37,"value":2101},{"type":24,"tag":119,"props":3109,"children":3110},{"class":121,"line":178},[3111,3115,3120,3124,3129,3134,3138,3143,3148,3153,3157,3161],{"type":24,"tag":119,"props":3112,"children":3113},{"style":126},[3114],{"type":37,"value":2421},{"type":24,"tag":119,"props":3116,"children":3117},{"style":143},[3118],{"type":37,"value":3119}," queue ",{"type":24,"tag":119,"props":3121,"children":3122},{"style":126},[3123],{"type":37,"value":203},{"type":24,"tag":119,"props":3125,"children":3126},{"style":137},[3127],{"type":37,"value":3128}," LinkedList",{"type":24,"tag":119,"props":3130,"children":3131},{"style":143},[3132],{"type":37,"value":3133},"\u003C",{"type":24,"tag":119,"props":3135,"children":3136},{"style":137},[3137],{"type":37,"value":2454},{"type":24,"tag":119,"props":3139,"children":3140},{"style":143},[3141],{"type":37,"value":3142},">() ",{"type":24,"tag":119,"props":3144,"children":3145},{"style":126},[3146],{"type":37,"value":3147},"as",{"type":24,"tag":119,"props":3149,"children":3150},{"style":143},[3151],{"type":37,"value":3152}," Queue",{"type":24,"tag":119,"props":3154,"children":3155},{"style":126},[3156],{"type":37,"value":3133},{"type":24,"tag":119,"props":3158,"children":3159},{"style":143},[3160],{"type":37,"value":2454},{"type":24,"tag":119,"props":3162,"children":3163},{"style":126},[3164],{"type":37,"value":3165},">\n",{"type":24,"tag":119,"props":3167,"children":3168},{"class":121,"line":216},[3169,3174,3179],{"type":24,"tag":119,"props":3170,"children":3171},{"style":143},[3172],{"type":37,"value":3173},"        queue.",{"type":24,"tag":119,"props":3175,"children":3176},{"style":137},[3177],{"type":37,"value":3178},"offer",{"type":24,"tag":119,"props":3180,"children":3181},{"style":143},[3182],{"type":37,"value":2632},{"type":24,"tag":119,"props":3184,"children":3185},{"class":121,"line":246},[3186,3190,3195],{"type":24,"tag":119,"props":3187,"children":3188},{"style":126},[3189],{"type":37,"value":155},{"type":24,"tag":119,"props":3191,"children":3192},{"style":143},[3193],{"type":37,"value":3194}," current : ",{"type":24,"tag":119,"props":3196,"children":3197},{"style":137},[3198],{"type":37,"value":3199},"BinaryTreeNode\n",{"type":24,"tag":119,"props":3201,"children":3202},{"class":121,"line":255},[3203],{"type":24,"tag":119,"props":3204,"children":3205},{"emptyLinePlaceholder":2098},[3206],{"type":37,"value":2101},{"type":24,"tag":119,"props":3208,"children":3209},{"class":121,"line":265},[3210,3215,3219,3224,3229,3234],{"type":24,"tag":119,"props":3211,"children":3212},{"style":126},[3213],{"type":37,"value":3214},"        while",{"type":24,"tag":119,"props":3216,"children":3217},{"style":143},[3218],{"type":37,"value":371},{"type":24,"tag":119,"props":3220,"children":3221},{"style":126},[3222],{"type":37,"value":3223},"!",{"type":24,"tag":119,"props":3225,"children":3226},{"style":143},[3227],{"type":37,"value":3228},"queue.",{"type":24,"tag":119,"props":3230,"children":3231},{"style":137},[3232],{"type":37,"value":3233},"isEmpty",{"type":24,"tag":119,"props":3235,"children":3236},{"style":143},[3237],{"type":37,"value":3238},"()){\n",{"type":24,"tag":119,"props":3240,"children":3241},{"class":121,"line":622},[3242,3247,3251,3256,3261],{"type":24,"tag":119,"props":3243,"children":3244},{"style":143},[3245],{"type":37,"value":3246},"            current ",{"type":24,"tag":119,"props":3248,"children":3249},{"style":126},[3250],{"type":37,"value":203},{"type":24,"tag":119,"props":3252,"children":3253},{"style":143},[3254],{"type":37,"value":3255}," queue.",{"type":24,"tag":119,"props":3257,"children":3258},{"style":137},[3259],{"type":37,"value":3260},"poll",{"type":24,"tag":119,"props":3262,"children":3263},{"style":143},[3264],{"type":37,"value":2012},{"type":24,"tag":119,"props":3266,"children":3267},{"class":121,"line":639},[3268,3273,3277],{"type":24,"tag":119,"props":3269,"children":3270},{"style":143},[3271],{"type":37,"value":3272},"            operation.",{"type":24,"tag":119,"props":3274,"children":3275},{"style":137},[3276],{"type":37,"value":2627},{"type":24,"tag":119,"props":3278,"children":3279},{"style":143},[3280],{"type":37,"value":3281},"(current)\n",{"type":24,"tag":119,"props":3283,"children":3284},{"class":121,"line":668},[3285],{"type":24,"tag":119,"props":3286,"children":3287},{"emptyLinePlaceholder":2098},[3288],{"type":37,"value":2101},{"type":24,"tag":119,"props":3290,"children":3291},{"class":121,"line":677},[3292,3297,3302,3306,3310],{"type":24,"tag":119,"props":3293,"children":3294},{"style":126},[3295],{"type":37,"value":3296},"            if",{"type":24,"tag":119,"props":3298,"children":3299},{"style":143},[3300],{"type":37,"value":3301}," (current.left ",{"type":24,"tag":119,"props":3303,"children":3304},{"style":126},[3305],{"type":37,"value":428},{"type":24,"tag":119,"props":3307,"children":3308},{"style":206},[3309],{"type":37,"value":209},{"type":24,"tag":119,"props":3311,"children":3312},{"style":143},[3313],{"type":37,"value":252},{"type":24,"tag":119,"props":3315,"children":3316},{"class":121,"line":1392},[3317,3322,3326],{"type":24,"tag":119,"props":3318,"children":3319},{"style":143},[3320],{"type":37,"value":3321},"                queue.",{"type":24,"tag":119,"props":3323,"children":3324},{"style":137},[3325],{"type":37,"value":3178},{"type":24,"tag":119,"props":3327,"children":3328},{"style":143},[3329],{"type":37,"value":3330},"(current.left)\n",{"type":24,"tag":119,"props":3332,"children":3333},{"class":121,"line":1401},[3334],{"type":24,"tag":119,"props":3335,"children":3336},{"style":143},[3337],{"type":37,"value":3338},"            }\n",{"type":24,"tag":119,"props":3340,"children":3341},{"class":121,"line":1418},[3342,3346,3351,3355,3359],{"type":24,"tag":119,"props":3343,"children":3344},{"style":126},[3345],{"type":37,"value":3296},{"type":24,"tag":119,"props":3347,"children":3348},{"style":143},[3349],{"type":37,"value":3350}," (current.right ",{"type":24,"tag":119,"props":3352,"children":3353},{"style":126},[3354],{"type":37,"value":428},{"type":24,"tag":119,"props":3356,"children":3357},{"style":206},[3358],{"type":37,"value":209},{"type":24,"tag":119,"props":3360,"children":3361},{"style":143},[3362],{"type":37,"value":252},{"type":24,"tag":119,"props":3364,"children":3365},{"class":121,"line":1427},[3366,3370,3374],{"type":24,"tag":119,"props":3367,"children":3368},{"style":143},[3369],{"type":37,"value":3321},{"type":24,"tag":119,"props":3371,"children":3372},{"style":137},[3373],{"type":37,"value":3178},{"type":24,"tag":119,"props":3375,"children":3376},{"style":143},[3377],{"type":37,"value":3378},"(current.right)\n",{"type":24,"tag":119,"props":3380,"children":3381},{"class":121,"line":1485},[3382],{"type":24,"tag":119,"props":3383,"children":3384},{"style":143},[3385],{"type":37,"value":3338},{"type":24,"tag":119,"props":3387,"children":3388},{"class":121,"line":1502},[3389],{"type":24,"tag":119,"props":3390,"children":3391},{"style":143},[3392],{"type":37,"value":2062},{"type":24,"tag":119,"props":3394,"children":3395},{"class":121,"line":1511},[3396],{"type":24,"tag":119,"props":3397,"children":3398},{"style":143},[3399],{"type":37,"value":674},{"type":24,"tag":29,"props":3401,"children":3402},{},[3403,3405],{"type":37,"value":3404},"You can find the complete code of this example in this ",{"type":24,"tag":42,"props":3406,"children":3408},{"href":3407,"target":103},"https://github.com/JaimeDeArcos/kotlin-algorithms/tree/main/trees/src/main/kotlin/es/jaimedearcos/algorithms/tree",[3409],{"type":37,"value":3410},"GitHub repository",{"type":24,"tag":2191,"props":3412,"children":3413},{},[3414],{"type":37,"value":2195},{"title":8,"searchDepth":149,"depth":149,"links":3416},[3417,3418,3421],{"id":2218,"depth":149,"text":2221},{"id":2289,"depth":149,"text":2292,"children":3419},[3420],{"id":2365,"depth":178,"text":2368},{"id":3005,"depth":149,"text":3008},"content:posts:algorithms-working-with-trees.md","posts/algorithms-working-with-trees.md","posts/algorithms-working-with-trees",1790510064591]