[{"data":1,"prerenderedAt":4632},["ShallowReactive",2],{"post-how-to-create-a-twitter-bot":3,"rel-how-to-create-a-twitter-bot":1197,"sib-how-to-create-a-twitter-bot":4556},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"layout":11,"subtitle":9,"image":12,"optimized_image":12,"category":13,"tags":14,"author":18,"paginate":6,"body":19,"_type":1191,"_id":1192,"_source":1193,"_file":1194,"_stem":1195,"_extension":1196},"/posts/how-to-create-a-twitter-bot","posts",false,"","How to create a Twitter bot","Step by step creation of a twitter bot","2020-12-06T11:00:00.000Z","post","/assets/img/uploads/twitter.jpg","algorithms",[15,16,17],"bots","twitter","python","jaimedearcos",{"type":20,"children":21,"toc":1180},"root",[22,31,44,57,65,72,78,90,163,175,387,392,411,417,422,432,564,570,594,600,733,739,744,764,1130,1141,1145,1151,1171,1174],{"type":23,"tag":24,"props":25,"children":27},"element","h2",{"id":26},"_1-request-your-developer-account-create-your-first-app",[28],{"type":29,"value":30},"text","1. Request your developer account & create your first app",{"type":23,"tag":32,"props":33,"children":34},"p",{},[35,37],{"type":29,"value":36},"The first step of building twitter bots is to request access to developer features, this can be done easily\nin ",{"type":23,"tag":38,"props":39,"children":42},"a",{"href":40,"target":41},"developer.twitter.com","_blank",[43],{"type":29,"value":40},{"type":23,"tag":32,"props":45,"children":46},{},[47,49,55],{"type":29,"value":48},"Once you have fill the form to request access, you can log in the ",{"type":23,"tag":50,"props":51,"children":52},"strong",{},[53],{"type":29,"value":54},"twitter console",{"type":29,"value":56}," to retrieve the access keys:",{"type":23,"tag":32,"props":58,"children":59},{},[60],{"type":23,"tag":61,"props":62,"children":64},"img",{"alt":7,"src":63},"/assets/img/uploads/twitter-dashboard.png",[],{"type":23,"tag":32,"props":66,"children":67},{},[68],{"type":23,"tag":61,"props":69,"children":71},{"alt":7,"src":70},"/assets/img/uploads/twitter-tokens.png",[],{"type":23,"tag":24,"props":73,"children":75},{"id":74},"_2-set-up-dev-environment",[76],{"type":29,"value":77},"2. Set-up dev environment",{"type":23,"tag":32,"props":79,"children":80},{},[81,83,88],{"type":29,"value":82},"We are going to use ",{"type":23,"tag":50,"props":84,"children":85},{},[86],{"type":29,"value":87},"Tweepy",{"type":29,"value":89},", a python library to facilitate the communication with twitter API. To create the python\nenvironment and install Tweepy we need to execute the following commands:",{"type":23,"tag":91,"props":92,"children":96},"pre",{"className":93,"code":94,"language":95,"meta":7,"style":7},"language-bash shiki shiki-themes github-dark github-light","python3 -m venv venv\nsource ./venv/bin/activate\npip install tweepy\n","bash",[97],{"type":23,"tag":98,"props":99,"children":100},"code",{"__ignoreMap":7},[101,130,144],{"type":23,"tag":102,"props":103,"children":106},"span",{"class":104,"line":105},"line",1,[107,113,119,125],{"type":23,"tag":102,"props":108,"children":110},{"style":109},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[111],{"type":29,"value":112},"python3",{"type":23,"tag":102,"props":114,"children":116},{"style":115},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[117],{"type":29,"value":118}," -m",{"type":23,"tag":102,"props":120,"children":122},{"style":121},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[123],{"type":29,"value":124}," venv",{"type":23,"tag":102,"props":126,"children":127},{"style":121},[128],{"type":29,"value":129}," venv\n",{"type":23,"tag":102,"props":131,"children":133},{"class":104,"line":132},2,[134,139],{"type":23,"tag":102,"props":135,"children":136},{"style":115},[137],{"type":29,"value":138},"source",{"type":23,"tag":102,"props":140,"children":141},{"style":121},[142],{"type":29,"value":143}," ./venv/bin/activate\n",{"type":23,"tag":102,"props":145,"children":147},{"class":104,"line":146},3,[148,153,158],{"type":23,"tag":102,"props":149,"children":150},{"style":109},[151],{"type":29,"value":152},"pip",{"type":23,"tag":102,"props":154,"children":155},{"style":121},[156],{"type":29,"value":157}," install",{"type":23,"tag":102,"props":159,"children":160},{"style":121},[161],{"type":29,"value":162}," tweepy\n",{"type":23,"tag":32,"props":164,"children":165},{},[166,168,173],{"type":29,"value":167},"After that we need to create our first python script to verify keys and environment (",{"type":23,"tag":50,"props":169,"children":170},{},[171],{"type":29,"value":172},"test-credentials.py",{"type":29,"value":174},")",{"type":23,"tag":91,"props":176,"children":179},{"className":177,"code":178,"language":17,"meta":7,"style":7},"language-python shiki shiki-themes github-dark github-light","import tweepy\n\n# Authentication\nauth = tweepy.OAuthHandler(\"CONSUMER_API_KEY\", \"CONSUMER_API_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"ACCESS_TOKEN_SECRET\")\napi = tweepy.API(auth)\n\ntry:\n    api.verify_credentials()\n    print(\"Authentication OK\")\nexcept:\n    print(\"Error during authentication\")\n",[180],{"type":23,"tag":98,"props":181,"children":182},{"__ignoreMap":7},[183,197,206,215,254,281,299,307,321,330,353,366],{"type":23,"tag":102,"props":184,"children":185},{"class":104,"line":105},[186,192],{"type":23,"tag":102,"props":187,"children":189},{"style":188},"--shiki-default:#F97583;--shiki-light:#D73A49",[190],{"type":29,"value":191},"import",{"type":23,"tag":102,"props":193,"children":195},{"style":194},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[196],{"type":29,"value":162},{"type":23,"tag":102,"props":198,"children":199},{"class":104,"line":132},[200],{"type":23,"tag":102,"props":201,"children":203},{"emptyLinePlaceholder":202},true,[204],{"type":29,"value":205},"\n",{"type":23,"tag":102,"props":207,"children":208},{"class":104,"line":146},[209],{"type":23,"tag":102,"props":210,"children":212},{"style":211},"--shiki-default:#6A737D;--shiki-light:#6A737D",[213],{"type":29,"value":214},"# Authentication\n",{"type":23,"tag":102,"props":216,"children":218},{"class":104,"line":217},4,[219,224,229,234,239,244,249],{"type":23,"tag":102,"props":220,"children":221},{"style":194},[222],{"type":29,"value":223},"auth ",{"type":23,"tag":102,"props":225,"children":226},{"style":188},[227],{"type":29,"value":228},"=",{"type":23,"tag":102,"props":230,"children":231},{"style":194},[232],{"type":29,"value":233}," tweepy.OAuthHandler(",{"type":23,"tag":102,"props":235,"children":236},{"style":121},[237],{"type":29,"value":238},"\"CONSUMER_API_KEY\"",{"type":23,"tag":102,"props":240,"children":241},{"style":194},[242],{"type":29,"value":243},", ",{"type":23,"tag":102,"props":245,"children":246},{"style":121},[247],{"type":29,"value":248},"\"CONSUMER_API_SECRET\"",{"type":23,"tag":102,"props":250,"children":251},{"style":194},[252],{"type":29,"value":253},")\n",{"type":23,"tag":102,"props":255,"children":257},{"class":104,"line":256},5,[258,263,268,272,277],{"type":23,"tag":102,"props":259,"children":260},{"style":194},[261],{"type":29,"value":262},"auth.set_access_token(",{"type":23,"tag":102,"props":264,"children":265},{"style":121},[266],{"type":29,"value":267},"\"ACCESS_TOKEN\"",{"type":23,"tag":102,"props":269,"children":270},{"style":194},[271],{"type":29,"value":243},{"type":23,"tag":102,"props":273,"children":274},{"style":121},[275],{"type":29,"value":276},"\"ACCESS_TOKEN_SECRET\"",{"type":23,"tag":102,"props":278,"children":279},{"style":194},[280],{"type":29,"value":253},{"type":23,"tag":102,"props":282,"children":284},{"class":104,"line":283},6,[285,290,294],{"type":23,"tag":102,"props":286,"children":287},{"style":194},[288],{"type":29,"value":289},"api ",{"type":23,"tag":102,"props":291,"children":292},{"style":188},[293],{"type":29,"value":228},{"type":23,"tag":102,"props":295,"children":296},{"style":194},[297],{"type":29,"value":298}," tweepy.API(auth)\n",{"type":23,"tag":102,"props":300,"children":302},{"class":104,"line":301},7,[303],{"type":23,"tag":102,"props":304,"children":305},{"emptyLinePlaceholder":202},[306],{"type":29,"value":205},{"type":23,"tag":102,"props":308,"children":310},{"class":104,"line":309},8,[311,316],{"type":23,"tag":102,"props":312,"children":313},{"style":188},[314],{"type":29,"value":315},"try",{"type":23,"tag":102,"props":317,"children":318},{"style":194},[319],{"type":29,"value":320},":\n",{"type":23,"tag":102,"props":322,"children":324},{"class":104,"line":323},9,[325],{"type":23,"tag":102,"props":326,"children":327},{"style":194},[328],{"type":29,"value":329},"    api.verify_credentials()\n",{"type":23,"tag":102,"props":331,"children":333},{"class":104,"line":332},10,[334,339,344,349],{"type":23,"tag":102,"props":335,"children":336},{"style":115},[337],{"type":29,"value":338},"    print",{"type":23,"tag":102,"props":340,"children":341},{"style":194},[342],{"type":29,"value":343},"(",{"type":23,"tag":102,"props":345,"children":346},{"style":121},[347],{"type":29,"value":348},"\"Authentication OK\"",{"type":23,"tag":102,"props":350,"children":351},{"style":194},[352],{"type":29,"value":253},{"type":23,"tag":102,"props":354,"children":356},{"class":104,"line":355},11,[357,362],{"type":23,"tag":102,"props":358,"children":359},{"style":188},[360],{"type":29,"value":361},"except",{"type":23,"tag":102,"props":363,"children":364},{"style":194},[365],{"type":29,"value":320},{"type":23,"tag":102,"props":367,"children":369},{"class":104,"line":368},12,[370,374,378,383],{"type":23,"tag":102,"props":371,"children":372},{"style":115},[373],{"type":29,"value":338},{"type":23,"tag":102,"props":375,"children":376},{"style":194},[377],{"type":29,"value":343},{"type":23,"tag":102,"props":379,"children":380},{"style":121},[381],{"type":29,"value":382},"\"Error during authentication\"",{"type":23,"tag":102,"props":384,"children":385},{"style":194},[386],{"type":29,"value":253},{"type":23,"tag":32,"props":388,"children":389},{},[390],{"type":29,"value":391},"Run the script by executing:",{"type":23,"tag":91,"props":393,"children":395},{"className":93,"code":394,"language":95,"meta":7,"style":7},"python test-credentials.py  \n",[396],{"type":23,"tag":98,"props":397,"children":398},{"__ignoreMap":7},[399],{"type":23,"tag":102,"props":400,"children":401},{"class":104,"line":105},[402,406],{"type":23,"tag":102,"props":403,"children":404},{"style":109},[405],{"type":29,"value":17},{"type":23,"tag":102,"props":407,"children":408},{"style":121},[409],{"type":29,"value":410}," test-credentials.py\n",{"type":23,"tag":24,"props":412,"children":414},{"id":413},"_3-playing-with-the-api",[415],{"type":29,"value":416},"3. Playing with the API",{"type":23,"tag":32,"props":418,"children":419},{},[420],{"type":29,"value":421},"Tweepy provides a really simple way to retrieve/create twitter information.",{"type":23,"tag":423,"props":424,"children":426},"h3",{"id":425},"retrieve-your-timeline",[427],{"type":23,"tag":50,"props":428,"children":429},{},[430],{"type":29,"value":431},"Retrieve your timeline",{"type":23,"tag":91,"props":433,"children":435},{"className":177,"code":434,"language":17,"meta":7,"style":7},"# ...\n\n# Retrieve timeline\ntimeline = api.home_timeline()\nfor tweet in timeline:\n    print(f\"{tweet.user.name} said {tweet.text}\")\n",[436],{"type":23,"tag":98,"props":437,"children":438},{"__ignoreMap":7},[439,447,454,462,479,502],{"type":23,"tag":102,"props":440,"children":441},{"class":104,"line":105},[442],{"type":23,"tag":102,"props":443,"children":444},{"style":211},[445],{"type":29,"value":446},"# ...\n",{"type":23,"tag":102,"props":448,"children":449},{"class":104,"line":132},[450],{"type":23,"tag":102,"props":451,"children":452},{"emptyLinePlaceholder":202},[453],{"type":29,"value":205},{"type":23,"tag":102,"props":455,"children":456},{"class":104,"line":146},[457],{"type":23,"tag":102,"props":458,"children":459},{"style":211},[460],{"type":29,"value":461},"# Retrieve timeline\n",{"type":23,"tag":102,"props":463,"children":464},{"class":104,"line":217},[465,470,474],{"type":23,"tag":102,"props":466,"children":467},{"style":194},[468],{"type":29,"value":469},"timeline ",{"type":23,"tag":102,"props":471,"children":472},{"style":188},[473],{"type":29,"value":228},{"type":23,"tag":102,"props":475,"children":476},{"style":194},[477],{"type":29,"value":478}," api.home_timeline()\n",{"type":23,"tag":102,"props":480,"children":481},{"class":104,"line":256},[482,487,492,497],{"type":23,"tag":102,"props":483,"children":484},{"style":188},[485],{"type":29,"value":486},"for",{"type":23,"tag":102,"props":488,"children":489},{"style":194},[490],{"type":29,"value":491}," tweet ",{"type":23,"tag":102,"props":493,"children":494},{"style":188},[495],{"type":29,"value":496},"in",{"type":23,"tag":102,"props":498,"children":499},{"style":194},[500],{"type":29,"value":501}," timeline:\n",{"type":23,"tag":102,"props":503,"children":504},{"class":104,"line":283},[505,509,513,518,523,528,533,538,543,547,552,556,560],{"type":23,"tag":102,"props":506,"children":507},{"style":115},[508],{"type":29,"value":338},{"type":23,"tag":102,"props":510,"children":511},{"style":194},[512],{"type":29,"value":343},{"type":23,"tag":102,"props":514,"children":515},{"style":188},[516],{"type":29,"value":517},"f",{"type":23,"tag":102,"props":519,"children":520},{"style":121},[521],{"type":29,"value":522},"\"",{"type":23,"tag":102,"props":524,"children":525},{"style":115},[526],{"type":29,"value":527},"{",{"type":23,"tag":102,"props":529,"children":530},{"style":194},[531],{"type":29,"value":532},"tweet.user.name",{"type":23,"tag":102,"props":534,"children":535},{"style":115},[536],{"type":29,"value":537},"}",{"type":23,"tag":102,"props":539,"children":540},{"style":121},[541],{"type":29,"value":542}," said ",{"type":23,"tag":102,"props":544,"children":545},{"style":115},[546],{"type":29,"value":527},{"type":23,"tag":102,"props":548,"children":549},{"style":194},[550],{"type":29,"value":551},"tweet.text",{"type":23,"tag":102,"props":553,"children":554},{"style":115},[555],{"type":29,"value":537},{"type":23,"tag":102,"props":557,"children":558},{"style":121},[559],{"type":29,"value":522},{"type":23,"tag":102,"props":561,"children":562},{"style":194},[563],{"type":29,"value":253},{"type":23,"tag":423,"props":565,"children":567},{"id":566},"publish-a-new-tweet",[568],{"type":29,"value":569},"Publish a new tweet",{"type":23,"tag":91,"props":571,"children":573},{"className":177,"code":572,"language":17,"meta":7,"style":7},"api.update_status(\"Hello World from Tweepy\")\n",[574],{"type":23,"tag":98,"props":575,"children":576},{"__ignoreMap":7},[577],{"type":23,"tag":102,"props":578,"children":579},{"class":104,"line":105},[580,585,590],{"type":23,"tag":102,"props":581,"children":582},{"style":194},[583],{"type":29,"value":584},"api.update_status(",{"type":23,"tag":102,"props":586,"children":587},{"style":121},[588],{"type":29,"value":589},"\"Hello World from Tweepy\"",{"type":23,"tag":102,"props":591,"children":592},{"style":194},[593],{"type":29,"value":253},{"type":23,"tag":423,"props":595,"children":597},{"id":596},"retrieve-info-of-any-user",[598],{"type":29,"value":599},"Retrieve info of any user",{"type":23,"tag":91,"props":601,"children":603},{"className":177,"code":602,"language":17,"meta":7,"style":7},"user = api.get_user(\"JaimeDeArcos\")\n\nprint(\"User details:\")\nprint(user)\n\nprint(\"Last 20 Followers:\")\nfor follower in user.followers():\n    print(follower.name)\n",[604],{"type":23,"tag":98,"props":605,"children":606},{"__ignoreMap":7},[607,633,640,661,673,680,700,721],{"type":23,"tag":102,"props":608,"children":609},{"class":104,"line":105},[610,615,619,624,629],{"type":23,"tag":102,"props":611,"children":612},{"style":194},[613],{"type":29,"value":614},"user ",{"type":23,"tag":102,"props":616,"children":617},{"style":188},[618],{"type":29,"value":228},{"type":23,"tag":102,"props":620,"children":621},{"style":194},[622],{"type":29,"value":623}," api.get_user(",{"type":23,"tag":102,"props":625,"children":626},{"style":121},[627],{"type":29,"value":628},"\"JaimeDeArcos\"",{"type":23,"tag":102,"props":630,"children":631},{"style":194},[632],{"type":29,"value":253},{"type":23,"tag":102,"props":634,"children":635},{"class":104,"line":132},[636],{"type":23,"tag":102,"props":637,"children":638},{"emptyLinePlaceholder":202},[639],{"type":29,"value":205},{"type":23,"tag":102,"props":641,"children":642},{"class":104,"line":146},[643,648,652,657],{"type":23,"tag":102,"props":644,"children":645},{"style":115},[646],{"type":29,"value":647},"print",{"type":23,"tag":102,"props":649,"children":650},{"style":194},[651],{"type":29,"value":343},{"type":23,"tag":102,"props":653,"children":654},{"style":121},[655],{"type":29,"value":656},"\"User details:\"",{"type":23,"tag":102,"props":658,"children":659},{"style":194},[660],{"type":29,"value":253},{"type":23,"tag":102,"props":662,"children":663},{"class":104,"line":217},[664,668],{"type":23,"tag":102,"props":665,"children":666},{"style":115},[667],{"type":29,"value":647},{"type":23,"tag":102,"props":669,"children":670},{"style":194},[671],{"type":29,"value":672},"(user)\n",{"type":23,"tag":102,"props":674,"children":675},{"class":104,"line":256},[676],{"type":23,"tag":102,"props":677,"children":678},{"emptyLinePlaceholder":202},[679],{"type":29,"value":205},{"type":23,"tag":102,"props":681,"children":682},{"class":104,"line":283},[683,687,691,696],{"type":23,"tag":102,"props":684,"children":685},{"style":115},[686],{"type":29,"value":647},{"type":23,"tag":102,"props":688,"children":689},{"style":194},[690],{"type":29,"value":343},{"type":23,"tag":102,"props":692,"children":693},{"style":121},[694],{"type":29,"value":695},"\"Last 20 Followers:\"",{"type":23,"tag":102,"props":697,"children":698},{"style":194},[699],{"type":29,"value":253},{"type":23,"tag":102,"props":701,"children":702},{"class":104,"line":301},[703,707,712,716],{"type":23,"tag":102,"props":704,"children":705},{"style":188},[706],{"type":29,"value":486},{"type":23,"tag":102,"props":708,"children":709},{"style":194},[710],{"type":29,"value":711}," follower ",{"type":23,"tag":102,"props":713,"children":714},{"style":188},[715],{"type":29,"value":496},{"type":23,"tag":102,"props":717,"children":718},{"style":194},[719],{"type":29,"value":720}," user.followers():\n",{"type":23,"tag":102,"props":722,"children":723},{"class":104,"line":309},[724,728],{"type":23,"tag":102,"props":725,"children":726},{"style":115},[727],{"type":29,"value":338},{"type":23,"tag":102,"props":729,"children":730},{"style":194},[731],{"type":29,"value":732},"(follower.name)\n",{"type":23,"tag":24,"props":734,"children":736},{"id":735},"creating-your-first-bot-follow-anyone-who-follows-you",[737],{"type":29,"value":738},"Creating your first bot - Follow anyone who follows you",{"type":23,"tag":32,"props":740,"children":741},{},[742],{"type":29,"value":743},"In this example we are going to create a bot which:",{"type":23,"tag":745,"props":746,"children":747},"ul",{},[748,754,759],{"type":23,"tag":749,"props":750,"children":751},"li",{},[752],{"type":29,"value":753},"Retrieve the list of your followers",{"type":23,"tag":749,"props":755,"children":756},{},[757],{"type":29,"value":758},"Check if you're already following them",{"type":23,"tag":749,"props":760,"children":761},{},[762],{"type":29,"value":763},"If not, start following",{"type":23,"tag":91,"props":765,"children":767},{"className":177,"code":766,"language":17,"meta":7,"style":7},"import tweepy, time\n\n# Authentication\nauth = tweepy.OAuthHandler(\"CONSUMER_API_KEY\", \"CONSUMER_API_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"ACCESS_TOKEN_SECRET\")\napi = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)\n\n# Verify authentication\ntry:\n    api.verify_credentials()\n    print(\"Authentication OK\")\nexcept:\n    print(\"Error during authentication\")\n\nwhile True:\n    # Retrieve followers\n    for follower in tweepy.Cursor(api.followers).items():\n        if not follower.following:\n            print(\"New Follower -> {}\".format(follower.name))\n            follower.follow()\n    # Sleep for 2 minutes \n    time.sleep(120)\n\n",[768],{"type":23,"tag":98,"props":769,"children":770},{"__ignoreMap":7},[771,783,790,797,828,851,903,910,918,929,936,955,966,986,994,1012,1021,1043,1062,1094,1103,1112],{"type":23,"tag":102,"props":772,"children":773},{"class":104,"line":105},[774,778],{"type":23,"tag":102,"props":775,"children":776},{"style":188},[777],{"type":29,"value":191},{"type":23,"tag":102,"props":779,"children":780},{"style":194},[781],{"type":29,"value":782}," tweepy, time\n",{"type":23,"tag":102,"props":784,"children":785},{"class":104,"line":132},[786],{"type":23,"tag":102,"props":787,"children":788},{"emptyLinePlaceholder":202},[789],{"type":29,"value":205},{"type":23,"tag":102,"props":791,"children":792},{"class":104,"line":146},[793],{"type":23,"tag":102,"props":794,"children":795},{"style":211},[796],{"type":29,"value":214},{"type":23,"tag":102,"props":798,"children":799},{"class":104,"line":217},[800,804,808,812,816,820,824],{"type":23,"tag":102,"props":801,"children":802},{"style":194},[803],{"type":29,"value":223},{"type":23,"tag":102,"props":805,"children":806},{"style":188},[807],{"type":29,"value":228},{"type":23,"tag":102,"props":809,"children":810},{"style":194},[811],{"type":29,"value":233},{"type":23,"tag":102,"props":813,"children":814},{"style":121},[815],{"type":29,"value":238},{"type":23,"tag":102,"props":817,"children":818},{"style":194},[819],{"type":29,"value":243},{"type":23,"tag":102,"props":821,"children":822},{"style":121},[823],{"type":29,"value":248},{"type":23,"tag":102,"props":825,"children":826},{"style":194},[827],{"type":29,"value":253},{"type":23,"tag":102,"props":829,"children":830},{"class":104,"line":256},[831,835,839,843,847],{"type":23,"tag":102,"props":832,"children":833},{"style":194},[834],{"type":29,"value":262},{"type":23,"tag":102,"props":836,"children":837},{"style":121},[838],{"type":29,"value":267},{"type":23,"tag":102,"props":840,"children":841},{"style":194},[842],{"type":29,"value":243},{"type":23,"tag":102,"props":844,"children":845},{"style":121},[846],{"type":29,"value":276},{"type":23,"tag":102,"props":848,"children":849},{"style":194},[850],{"type":29,"value":253},{"type":23,"tag":102,"props":852,"children":853},{"class":104,"line":283},[854,858,862,867,873,877,882,886,891,895,899],{"type":23,"tag":102,"props":855,"children":856},{"style":194},[857],{"type":29,"value":289},{"type":23,"tag":102,"props":859,"children":860},{"style":188},[861],{"type":29,"value":228},{"type":23,"tag":102,"props":863,"children":864},{"style":194},[865],{"type":29,"value":866}," tweepy.API(auth, ",{"type":23,"tag":102,"props":868,"children":870},{"style":869},"--shiki-default:#FFAB70;--shiki-light:#E36209",[871],{"type":29,"value":872},"wait_on_rate_limit",{"type":23,"tag":102,"props":874,"children":875},{"style":188},[876],{"type":29,"value":228},{"type":23,"tag":102,"props":878,"children":879},{"style":115},[880],{"type":29,"value":881},"True",{"type":23,"tag":102,"props":883,"children":884},{"style":194},[885],{"type":29,"value":243},{"type":23,"tag":102,"props":887,"children":888},{"style":869},[889],{"type":29,"value":890},"wait_on_rate_limit_notify",{"type":23,"tag":102,"props":892,"children":893},{"style":188},[894],{"type":29,"value":228},{"type":23,"tag":102,"props":896,"children":897},{"style":115},[898],{"type":29,"value":881},{"type":23,"tag":102,"props":900,"children":901},{"style":194},[902],{"type":29,"value":253},{"type":23,"tag":102,"props":904,"children":905},{"class":104,"line":301},[906],{"type":23,"tag":102,"props":907,"children":908},{"emptyLinePlaceholder":202},[909],{"type":29,"value":205},{"type":23,"tag":102,"props":911,"children":912},{"class":104,"line":309},[913],{"type":23,"tag":102,"props":914,"children":915},{"style":211},[916],{"type":29,"value":917},"# Verify authentication\n",{"type":23,"tag":102,"props":919,"children":920},{"class":104,"line":323},[921,925],{"type":23,"tag":102,"props":922,"children":923},{"style":188},[924],{"type":29,"value":315},{"type":23,"tag":102,"props":926,"children":927},{"style":194},[928],{"type":29,"value":320},{"type":23,"tag":102,"props":930,"children":931},{"class":104,"line":332},[932],{"type":23,"tag":102,"props":933,"children":934},{"style":194},[935],{"type":29,"value":329},{"type":23,"tag":102,"props":937,"children":938},{"class":104,"line":355},[939,943,947,951],{"type":23,"tag":102,"props":940,"children":941},{"style":115},[942],{"type":29,"value":338},{"type":23,"tag":102,"props":944,"children":945},{"style":194},[946],{"type":29,"value":343},{"type":23,"tag":102,"props":948,"children":949},{"style":121},[950],{"type":29,"value":348},{"type":23,"tag":102,"props":952,"children":953},{"style":194},[954],{"type":29,"value":253},{"type":23,"tag":102,"props":956,"children":957},{"class":104,"line":368},[958,962],{"type":23,"tag":102,"props":959,"children":960},{"style":188},[961],{"type":29,"value":361},{"type":23,"tag":102,"props":963,"children":964},{"style":194},[965],{"type":29,"value":320},{"type":23,"tag":102,"props":967,"children":969},{"class":104,"line":968},13,[970,974,978,982],{"type":23,"tag":102,"props":971,"children":972},{"style":115},[973],{"type":29,"value":338},{"type":23,"tag":102,"props":975,"children":976},{"style":194},[977],{"type":29,"value":343},{"type":23,"tag":102,"props":979,"children":980},{"style":121},[981],{"type":29,"value":382},{"type":23,"tag":102,"props":983,"children":984},{"style":194},[985],{"type":29,"value":253},{"type":23,"tag":102,"props":987,"children":989},{"class":104,"line":988},14,[990],{"type":23,"tag":102,"props":991,"children":992},{"emptyLinePlaceholder":202},[993],{"type":29,"value":205},{"type":23,"tag":102,"props":995,"children":997},{"class":104,"line":996},15,[998,1003,1008],{"type":23,"tag":102,"props":999,"children":1000},{"style":188},[1001],{"type":29,"value":1002},"while",{"type":23,"tag":102,"props":1004,"children":1005},{"style":115},[1006],{"type":29,"value":1007}," True",{"type":23,"tag":102,"props":1009,"children":1010},{"style":194},[1011],{"type":29,"value":320},{"type":23,"tag":102,"props":1013,"children":1015},{"class":104,"line":1014},16,[1016],{"type":23,"tag":102,"props":1017,"children":1018},{"style":211},[1019],{"type":29,"value":1020},"    # Retrieve followers\n",{"type":23,"tag":102,"props":1022,"children":1024},{"class":104,"line":1023},17,[1025,1030,1034,1038],{"type":23,"tag":102,"props":1026,"children":1027},{"style":188},[1028],{"type":29,"value":1029},"    for",{"type":23,"tag":102,"props":1031,"children":1032},{"style":194},[1033],{"type":29,"value":711},{"type":23,"tag":102,"props":1035,"children":1036},{"style":188},[1037],{"type":29,"value":496},{"type":23,"tag":102,"props":1039,"children":1040},{"style":194},[1041],{"type":29,"value":1042}," tweepy.Cursor(api.followers).items():\n",{"type":23,"tag":102,"props":1044,"children":1046},{"class":104,"line":1045},18,[1047,1052,1057],{"type":23,"tag":102,"props":1048,"children":1049},{"style":188},[1050],{"type":29,"value":1051},"        if",{"type":23,"tag":102,"props":1053,"children":1054},{"style":188},[1055],{"type":29,"value":1056}," not",{"type":23,"tag":102,"props":1058,"children":1059},{"style":194},[1060],{"type":29,"value":1061}," follower.following:\n",{"type":23,"tag":102,"props":1063,"children":1065},{"class":104,"line":1064},19,[1066,1071,1075,1080,1085,1089],{"type":23,"tag":102,"props":1067,"children":1068},{"style":115},[1069],{"type":29,"value":1070},"            print",{"type":23,"tag":102,"props":1072,"children":1073},{"style":194},[1074],{"type":29,"value":343},{"type":23,"tag":102,"props":1076,"children":1077},{"style":121},[1078],{"type":29,"value":1079},"\"New Follower -> ",{"type":23,"tag":102,"props":1081,"children":1082},{"style":115},[1083],{"type":29,"value":1084},"{}",{"type":23,"tag":102,"props":1086,"children":1087},{"style":121},[1088],{"type":29,"value":522},{"type":23,"tag":102,"props":1090,"children":1091},{"style":194},[1092],{"type":29,"value":1093},".format(follower.name))\n",{"type":23,"tag":102,"props":1095,"children":1097},{"class":104,"line":1096},20,[1098],{"type":23,"tag":102,"props":1099,"children":1100},{"style":194},[1101],{"type":29,"value":1102},"            follower.follow()\n",{"type":23,"tag":102,"props":1104,"children":1106},{"class":104,"line":1105},21,[1107],{"type":23,"tag":102,"props":1108,"children":1109},{"style":211},[1110],{"type":29,"value":1111},"    # Sleep for 2 minutes \n",{"type":23,"tag":102,"props":1113,"children":1115},{"class":104,"line":1114},22,[1116,1121,1126],{"type":23,"tag":102,"props":1117,"children":1118},{"style":194},[1119],{"type":29,"value":1120},"    time.sleep(",{"type":23,"tag":102,"props":1122,"children":1123},{"style":115},[1124],{"type":29,"value":1125},"120",{"type":23,"tag":102,"props":1127,"children":1128},{"style":194},[1129],{"type":29,"value":253},{"type":23,"tag":32,"props":1131,"children":1132},{},[1133,1135],{"type":29,"value":1134},"Simple, right? now you can improve the script with whatever use case you need. This script could be running locally or\nmaybe you would deploy it on any provider of your choice ",{"type":23,"tag":1136,"props":1137,"children":1138},"em",{},[1139],{"type":29,"value":1140},"(AWS, Azure, google cloud...)",{"type":23,"tag":1142,"props":1143,"children":1144},"hr",{},[],{"type":23,"tag":24,"props":1146,"children":1148},{"id":1147},"references-links",[1149],{"type":29,"value":1150},"References & links",{"type":23,"tag":745,"props":1152,"children":1153},{},[1154,1161],{"type":23,"tag":749,"props":1155,"children":1156},{},[1157],{"type":23,"tag":38,"props":1158,"children":1159},{"href":40},[1160],{"type":29,"value":40},{"type":23,"tag":749,"props":1162,"children":1163},{},[1164],{"type":23,"tag":38,"props":1165,"children":1169},{"href":1166,"rel":1167},"https://www.tweepy.org/",[1168],"nofollow",[1170],{"type":29,"value":87},{"type":23,"tag":1142,"props":1172,"children":1173},{},[],{"type":23,"tag":1175,"props":1176,"children":1177},"style",{},[1178],{"type":29,"value":1179},"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":7,"searchDepth":132,"depth":132,"links":1181},[1182,1183,1184,1189,1190],{"id":26,"depth":132,"text":30},{"id":74,"depth":132,"text":77},{"id":413,"depth":132,"text":416,"children":1185},[1186,1187,1188],{"id":425,"depth":146,"text":431},{"id":566,"depth":146,"text":569},{"id":596,"depth":146,"text":599},{"id":735,"depth":132,"text":738},{"id":1147,"depth":132,"text":1150},"markdown","content:posts:how-to-create-a-twitter-bot.md","content","posts/how-to-create-a-twitter-bot.md","posts/how-to-create-a-twitter-bot","md",[1198,3340],{"_path":1199,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":1200,"description":1201,"date":10,"layout":11,"subtitle":1201,"image":1202,"optimized_image":1202,"category":13,"tags":1203,"author":18,"paginate":6,"body":1206,"_type":1191,"_id":3337,"_source":1193,"_file":3338,"_stem":3339,"_extension":1196},"/posts/algorithms-binary-search-tree","Algorithms - Binary Search Tree in kotlin","Brief review of binary search trees with kotlin examples","/assets/img/uploads/rubiks-cube.jpg",[98,1204,1205,13],"kotlin","binary-tree",{"type":20,"children":1207,"toc":3331},[1208,1229,1246,1258,1265,1271,1284,1431,1443,1449,1454,1504,1834,1840,1859,2105,2111,2116,2223,3316,3327],{"type":23,"tag":1209,"props":1210,"children":1211},"blockquote",{},[1212],{"type":23,"tag":32,"props":1213,"children":1214},{},[1215,1220,1222],{"type":23,"tag":1136,"props":1216,"children":1217},{},[1218],{"type":29,"value":1219},"\"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":29,"value":1221}," -- ",{"type":23,"tag":38,"props":1223,"children":1226},{"href":1224,"rel":1225},"https://en.wikipedia.org/wiki/Binary_search_tree",[1168],[1227],{"type":29,"value":1228},"Wikipedia",{"type":23,"tag":32,"props":1230,"children":1231},{},[1232,1234,1239,1241],{"type":29,"value":1233},"One of the biggest ",{"type":23,"tag":50,"props":1235,"children":1236},{},[1237],{"type":29,"value":1238},"advantages of Binary Search Trees",{"type":29,"value":1240}," 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":23,"tag":50,"props":1242,"children":1243},{},[1244],{"type":29,"value":1245},"O(log n)",{"type":23,"tag":32,"props":1247,"children":1248},{},[1249,1251,1256],{"type":29,"value":1250},"Here is ",{"type":23,"tag":50,"props":1252,"children":1253},{},[1254],{"type":29,"value":1255},"an example",{"type":29,"value":1257}," of Binary Search Tree:",{"type":23,"tag":32,"props":1259,"children":1260},{},[1261],{"type":23,"tag":61,"props":1262,"children":1264},{"alt":7,"src":1263},"/assets/img/uploads/binary-search-tree.jpg",[],{"type":23,"tag":24,"props":1266,"children":1268},{"id":1267},"lets-code-a-binary-search-tree",[1269],{"type":29,"value":1270},"Let's code a binary search tree",{"type":23,"tag":32,"props":1272,"children":1273},{},[1274,1276,1282],{"type":29,"value":1275},"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":23,"tag":38,"props":1277,"children":1279},{"href":1278,"target":41},"/algorithms-working-with-trees/",[1280],{"type":29,"value":1281},"binary tree traversals",{"type":29,"value":1283},".",{"type":23,"tag":91,"props":1285,"children":1288},{"className":1286,"code":1287,"language":1204,"meta":7,"style":7},"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",[1289],{"type":23,"tag":98,"props":1290,"children":1291},{"__ignoreMap":7},[1292,1315,1343,1378,1407,1415,1423],{"type":23,"tag":102,"props":1293,"children":1294},{"class":104,"line":105},[1295,1300,1305,1310],{"type":23,"tag":102,"props":1296,"children":1297},{"style":188},[1298],{"type":29,"value":1299},"data",{"type":23,"tag":102,"props":1301,"children":1302},{"style":188},[1303],{"type":29,"value":1304}," class",{"type":23,"tag":102,"props":1306,"children":1307},{"style":109},[1308],{"type":29,"value":1309}," BinarySearchTreeNode",{"type":23,"tag":102,"props":1311,"children":1312},{"style":194},[1313],{"type":29,"value":1314},"(\n",{"type":23,"tag":102,"props":1316,"children":1317},{"class":104,"line":132},[1318,1323,1328,1333,1338],{"type":23,"tag":102,"props":1319,"children":1320},{"style":188},[1321],{"type":29,"value":1322},"        var",{"type":23,"tag":102,"props":1324,"children":1325},{"style":188},[1326],{"type":29,"value":1327}," data",{"type":23,"tag":102,"props":1329,"children":1330},{"style":194},[1331],{"type":29,"value":1332},":",{"type":23,"tag":102,"props":1334,"children":1335},{"style":109},[1336],{"type":29,"value":1337},"Int",{"type":23,"tag":102,"props":1339,"children":1340},{"style":194},[1341],{"type":29,"value":1342},",\n",{"type":23,"tag":102,"props":1344,"children":1345},{"class":104,"line":146},[1346,1350,1355,1360,1365,1369,1374],{"type":23,"tag":102,"props":1347,"children":1348},{"style":188},[1349],{"type":29,"value":1322},{"type":23,"tag":102,"props":1351,"children":1352},{"style":194},[1353],{"type":29,"value":1354}," left: ",{"type":23,"tag":102,"props":1356,"children":1357},{"style":109},[1358],{"type":29,"value":1359},"BinarySearchTreeNode",{"type":23,"tag":102,"props":1361,"children":1362},{"style":194},[1363],{"type":29,"value":1364},"? ",{"type":23,"tag":102,"props":1366,"children":1367},{"style":188},[1368],{"type":29,"value":228},{"type":23,"tag":102,"props":1370,"children":1371},{"style":115},[1372],{"type":29,"value":1373}," null",{"type":23,"tag":102,"props":1375,"children":1376},{"style":194},[1377],{"type":29,"value":1342},{"type":23,"tag":102,"props":1379,"children":1380},{"class":104,"line":217},[1381,1385,1390,1394,1398,1402],{"type":23,"tag":102,"props":1382,"children":1383},{"style":188},[1384],{"type":29,"value":1322},{"type":23,"tag":102,"props":1386,"children":1387},{"style":194},[1388],{"type":29,"value":1389}," right: ",{"type":23,"tag":102,"props":1391,"children":1392},{"style":109},[1393],{"type":29,"value":1359},{"type":23,"tag":102,"props":1395,"children":1396},{"style":194},[1397],{"type":29,"value":1364},{"type":23,"tag":102,"props":1399,"children":1400},{"style":188},[1401],{"type":29,"value":228},{"type":23,"tag":102,"props":1403,"children":1404},{"style":115},[1405],{"type":29,"value":1406}," null\n",{"type":23,"tag":102,"props":1408,"children":1409},{"class":104,"line":256},[1410],{"type":23,"tag":102,"props":1411,"children":1412},{"style":194},[1413],{"type":29,"value":1414},"){\n",{"type":23,"tag":102,"props":1416,"children":1417},{"class":104,"line":283},[1418],{"type":23,"tag":102,"props":1419,"children":1420},{"style":211},[1421],{"type":29,"value":1422},"   // ...\n",{"type":23,"tag":102,"props":1424,"children":1425},{"class":104,"line":301},[1426],{"type":23,"tag":102,"props":1427,"children":1428},{"style":194},[1429],{"type":29,"value":1430},"}\n",{"type":23,"tag":32,"props":1432,"children":1433},{},[1434,1436,1441],{"type":29,"value":1435},"As you can see is basically the same as simple binary trees, the main difference is going to be how we ",{"type":23,"tag":50,"props":1437,"children":1438},{},[1439],{"type":29,"value":1440},"insert, search\nand delete",{"type":29,"value":1442}," values from the tree.",{"type":23,"tag":24,"props":1444,"children":1446},{"id":1445},"insert-values-in-the-tree",[1447],{"type":29,"value":1448},"Insert values in the tree",{"type":23,"tag":32,"props":1450,"children":1451},{},[1452],{"type":29,"value":1453},"The insertion function is a simple recursive one, there are 4 cases:",{"type":23,"tag":745,"props":1455,"children":1456},{},[1457,1482],{"type":23,"tag":749,"props":1458,"children":1459},{},[1460,1462,1467,1469],{"type":29,"value":1461},"New item is ",{"type":23,"tag":50,"props":1463,"children":1464},{},[1465],{"type":29,"value":1466},"lower or equals",{"type":29,"value":1468}," than the current node data:\n",{"type":23,"tag":745,"props":1470,"children":1471},{},[1472,1477],{"type":23,"tag":749,"props":1473,"children":1474},{},[1475],{"type":29,"value":1476},"If left exist --> insert the value in left child (recursion)",{"type":23,"tag":749,"props":1478,"children":1479},{},[1480],{"type":29,"value":1481},"Else, create a new left child with the value (finish condition)",{"type":23,"tag":749,"props":1483,"children":1484},{},[1485,1486,1491,1492],{"type":29,"value":1461},{"type":23,"tag":50,"props":1487,"children":1488},{},[1489],{"type":29,"value":1490},"greater",{"type":29,"value":1468},{"type":23,"tag":745,"props":1493,"children":1494},{},[1495,1499],{"type":23,"tag":749,"props":1496,"children":1497},{},[1498],{"type":29,"value":1476},{"type":23,"tag":749,"props":1500,"children":1501},{},[1502],{"type":29,"value":1503},"Else, create a new right child with the value (finish condition)",{"type":23,"tag":91,"props":1505,"children":1507},{"className":1286,"code":1506,"language":1204,"meta":7,"style":7},"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",[1508],{"type":23,"tag":98,"props":1509,"children":1510},{"__ignoreMap":7},[1511,1545,1593,1627,1666,1694,1743,1775,1791,1819,1827],{"type":23,"tag":102,"props":1512,"children":1513},{"class":104,"line":105},[1514,1519,1524,1528,1533,1537,1541],{"type":23,"tag":102,"props":1515,"children":1516},{"style":188},[1517],{"type":29,"value":1518},"fun",{"type":23,"tag":102,"props":1520,"children":1521},{"style":109},[1522],{"type":29,"value":1523}," insert",{"type":23,"tag":102,"props":1525,"children":1526},{"style":194},[1527],{"type":29,"value":343},{"type":23,"tag":102,"props":1529,"children":1530},{"style":188},[1531],{"type":29,"value":1532},"value",{"type":23,"tag":102,"props":1534,"children":1535},{"style":194},[1536],{"type":29,"value":1332},{"type":23,"tag":102,"props":1538,"children":1539},{"style":109},[1540],{"type":29,"value":1337},{"type":23,"tag":102,"props":1542,"children":1543},{"style":194},[1544],{"type":29,"value":1414},{"type":23,"tag":102,"props":1546,"children":1547},{"class":104,"line":132},[1548,1553,1557,1561,1566,1570,1575,1580,1585,1589],{"type":23,"tag":102,"props":1549,"children":1550},{"style":188},[1551],{"type":29,"value":1552},"    if",{"type":23,"tag":102,"props":1554,"children":1555},{"style":194},[1556],{"type":29,"value":343},{"type":23,"tag":102,"props":1558,"children":1559},{"style":188},[1560],{"type":29,"value":1532},{"type":23,"tag":102,"props":1562,"children":1563},{"style":188},[1564],{"type":29,"value":1565}," \u003C=",{"type":23,"tag":102,"props":1567,"children":1568},{"style":188},[1569],{"type":29,"value":1327},{"type":23,"tag":102,"props":1571,"children":1572},{"style":188},[1573],{"type":29,"value":1574}," &&",{"type":23,"tag":102,"props":1576,"children":1577},{"style":194},[1578],{"type":29,"value":1579}," left ",{"type":23,"tag":102,"props":1581,"children":1582},{"style":188},[1583],{"type":29,"value":1584},"!=",{"type":23,"tag":102,"props":1586,"children":1587},{"style":115},[1588],{"type":29,"value":1373},{"type":23,"tag":102,"props":1590,"children":1591},{"style":194},[1592],{"type":29,"value":1414},{"type":23,"tag":102,"props":1594,"children":1595},{"class":104,"line":146},[1596,1601,1606,1610,1615,1619,1623],{"type":23,"tag":102,"props":1597,"children":1598},{"style":194},[1599],{"type":29,"value":1600},"        left",{"type":23,"tag":102,"props":1602,"children":1603},{"style":188},[1604],{"type":29,"value":1605},"!!",{"type":23,"tag":102,"props":1607,"children":1608},{"style":194},[1609],{"type":29,"value":1283},{"type":23,"tag":102,"props":1611,"children":1612},{"style":109},[1613],{"type":29,"value":1614},"insert",{"type":23,"tag":102,"props":1616,"children":1617},{"style":194},[1618],{"type":29,"value":343},{"type":23,"tag":102,"props":1620,"children":1621},{"style":188},[1622],{"type":29,"value":1532},{"type":23,"tag":102,"props":1624,"children":1625},{"style":194},[1626],{"type":29,"value":253},{"type":23,"tag":102,"props":1628,"children":1629},{"class":104,"line":217},[1630,1635,1640,1645,1650,1654,1658,1662],{"type":23,"tag":102,"props":1631,"children":1632},{"style":194},[1633],{"type":29,"value":1634},"    }",{"type":23,"tag":102,"props":1636,"children":1637},{"style":188},[1638],{"type":29,"value":1639},"else",{"type":23,"tag":102,"props":1641,"children":1642},{"style":188},[1643],{"type":29,"value":1644}," if",{"type":23,"tag":102,"props":1646,"children":1647},{"style":194},[1648],{"type":29,"value":1649}," (",{"type":23,"tag":102,"props":1651,"children":1652},{"style":188},[1653],{"type":29,"value":1532},{"type":23,"tag":102,"props":1655,"children":1656},{"style":188},[1657],{"type":29,"value":1565},{"type":23,"tag":102,"props":1659,"children":1660},{"style":188},[1661],{"type":29,"value":1327},{"type":23,"tag":102,"props":1663,"children":1664},{"style":194},[1665],{"type":29,"value":1414},{"type":23,"tag":102,"props":1667,"children":1668},{"class":104,"line":256},[1669,1674,1678,1682,1686,1690],{"type":23,"tag":102,"props":1670,"children":1671},{"style":194},[1672],{"type":29,"value":1673},"        left ",{"type":23,"tag":102,"props":1675,"children":1676},{"style":188},[1677],{"type":29,"value":228},{"type":23,"tag":102,"props":1679,"children":1680},{"style":109},[1681],{"type":29,"value":1309},{"type":23,"tag":102,"props":1683,"children":1684},{"style":194},[1685],{"type":29,"value":343},{"type":23,"tag":102,"props":1687,"children":1688},{"style":188},[1689],{"type":29,"value":1532},{"type":23,"tag":102,"props":1691,"children":1692},{"style":194},[1693],{"type":29,"value":253},{"type":23,"tag":102,"props":1695,"children":1696},{"class":104,"line":283},[1697,1701,1705,1709,1713,1718,1722,1726,1731,1735,1739],{"type":23,"tag":102,"props":1698,"children":1699},{"style":194},[1700],{"type":29,"value":1634},{"type":23,"tag":102,"props":1702,"children":1703},{"style":188},[1704],{"type":29,"value":1639},{"type":23,"tag":102,"props":1706,"children":1707},{"style":188},[1708],{"type":29,"value":1644},{"type":23,"tag":102,"props":1710,"children":1711},{"style":194},[1712],{"type":29,"value":343},{"type":23,"tag":102,"props":1714,"children":1715},{"style":188},[1716],{"type":29,"value":1717},"value>",{"type":23,"tag":102,"props":1719,"children":1720},{"style":188},[1721],{"type":29,"value":1327},{"type":23,"tag":102,"props":1723,"children":1724},{"style":188},[1725],{"type":29,"value":1574},{"type":23,"tag":102,"props":1727,"children":1728},{"style":194},[1729],{"type":29,"value":1730}," right ",{"type":23,"tag":102,"props":1732,"children":1733},{"style":188},[1734],{"type":29,"value":1584},{"type":23,"tag":102,"props":1736,"children":1737},{"style":115},[1738],{"type":29,"value":1373},{"type":23,"tag":102,"props":1740,"children":1741},{"style":194},[1742],{"type":29,"value":1414},{"type":23,"tag":102,"props":1744,"children":1745},{"class":104,"line":301},[1746,1751,1755,1759,1763,1767,1771],{"type":23,"tag":102,"props":1747,"children":1748},{"style":194},[1749],{"type":29,"value":1750},"        right",{"type":23,"tag":102,"props":1752,"children":1753},{"style":188},[1754],{"type":29,"value":1605},{"type":23,"tag":102,"props":1756,"children":1757},{"style":194},[1758],{"type":29,"value":1283},{"type":23,"tag":102,"props":1760,"children":1761},{"style":109},[1762],{"type":29,"value":1614},{"type":23,"tag":102,"props":1764,"children":1765},{"style":194},[1766],{"type":29,"value":343},{"type":23,"tag":102,"props":1768,"children":1769},{"style":188},[1770],{"type":29,"value":1532},{"type":23,"tag":102,"props":1772,"children":1773},{"style":194},[1774],{"type":29,"value":253},{"type":23,"tag":102,"props":1776,"children":1777},{"class":104,"line":309},[1778,1782,1786],{"type":23,"tag":102,"props":1779,"children":1780},{"style":194},[1781],{"type":29,"value":1634},{"type":23,"tag":102,"props":1783,"children":1784},{"style":188},[1785],{"type":29,"value":1639},{"type":23,"tag":102,"props":1787,"children":1788},{"style":194},[1789],{"type":29,"value":1790},"{\n",{"type":23,"tag":102,"props":1792,"children":1793},{"class":104,"line":323},[1794,1799,1803,1807,1811,1815],{"type":23,"tag":102,"props":1795,"children":1796},{"style":194},[1797],{"type":29,"value":1798},"        right ",{"type":23,"tag":102,"props":1800,"children":1801},{"style":188},[1802],{"type":29,"value":228},{"type":23,"tag":102,"props":1804,"children":1805},{"style":109},[1806],{"type":29,"value":1309},{"type":23,"tag":102,"props":1808,"children":1809},{"style":194},[1810],{"type":29,"value":343},{"type":23,"tag":102,"props":1812,"children":1813},{"style":188},[1814],{"type":29,"value":1532},{"type":23,"tag":102,"props":1816,"children":1817},{"style":194},[1818],{"type":29,"value":253},{"type":23,"tag":102,"props":1820,"children":1821},{"class":104,"line":332},[1822],{"type":23,"tag":102,"props":1823,"children":1824},{"style":194},[1825],{"type":29,"value":1826},"    }\n",{"type":23,"tag":102,"props":1828,"children":1829},{"class":104,"line":355},[1830],{"type":23,"tag":102,"props":1831,"children":1832},{"style":194},[1833],{"type":29,"value":1430},{"type":23,"tag":24,"props":1835,"children":1837},{"id":1836},"searchcontains-value-in-the-tree",[1838],{"type":29,"value":1839},"Search/contains value in the tree",{"type":23,"tag":32,"props":1841,"children":1842},{},[1843,1845,1849,1851,1857],{"type":29,"value":1844},"In the following ",{"type":23,"tag":50,"props":1846,"children":1847},{},[1848],{"type":29,"value":1204},{"type":29,"value":1850}," snippet we are going to implement the ",{"type":23,"tag":98,"props":1852,"children":1854},{"className":1853},[],[1855],{"type":29,"value":1856},"contains",{"type":29,"value":1858}," 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":23,"tag":91,"props":1860,"children":1862},{"className":1286,"code":1861,"language":1204,"meta":7,"style":7},"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",[1863],{"type":23,"tag":98,"props":1864,"children":1865},{"__ignoreMap":7},[1866,1908,1954,1991,1998,2043,2078,2085,2098],{"type":23,"tag":102,"props":1867,"children":1868},{"class":104,"line":105},[1869,1873,1878,1882,1886,1890,1894,1899,1904],{"type":23,"tag":102,"props":1870,"children":1871},{"style":188},[1872],{"type":29,"value":1518},{"type":23,"tag":102,"props":1874,"children":1875},{"style":109},[1876],{"type":29,"value":1877}," contains",{"type":23,"tag":102,"props":1879,"children":1880},{"style":194},[1881],{"type":29,"value":343},{"type":23,"tag":102,"props":1883,"children":1884},{"style":188},[1885],{"type":29,"value":1532},{"type":23,"tag":102,"props":1887,"children":1888},{"style":194},[1889],{"type":29,"value":1332},{"type":23,"tag":102,"props":1891,"children":1892},{"style":109},[1893],{"type":29,"value":1337},{"type":23,"tag":102,"props":1895,"children":1896},{"style":194},[1897],{"type":29,"value":1898},") : ",{"type":23,"tag":102,"props":1900,"children":1901},{"style":109},[1902],{"type":29,"value":1903},"Boolean",{"type":23,"tag":102,"props":1905,"children":1906},{"style":194},[1907],{"type":29,"value":1790},{"type":23,"tag":102,"props":1909,"children":1910},{"class":104,"line":132},[1911,1915,1919,1923,1928,1932,1936,1940,1944,1949],{"type":23,"tag":102,"props":1912,"children":1913},{"style":188},[1914],{"type":29,"value":1552},{"type":23,"tag":102,"props":1916,"children":1917},{"style":194},[1918],{"type":29,"value":1649},{"type":23,"tag":102,"props":1920,"children":1921},{"style":188},[1922],{"type":29,"value":1532},{"type":23,"tag":102,"props":1924,"children":1925},{"style":188},[1926],{"type":29,"value":1927}," \u003C",{"type":23,"tag":102,"props":1929,"children":1930},{"style":188},[1931],{"type":29,"value":1327},{"type":23,"tag":102,"props":1933,"children":1934},{"style":188},[1935],{"type":29,"value":1574},{"type":23,"tag":102,"props":1937,"children":1938},{"style":194},[1939],{"type":29,"value":1579},{"type":23,"tag":102,"props":1941,"children":1942},{"style":188},[1943],{"type":29,"value":1584},{"type":23,"tag":102,"props":1945,"children":1946},{"style":115},[1947],{"type":29,"value":1948},"null",{"type":23,"tag":102,"props":1950,"children":1951},{"style":194},[1952],{"type":29,"value":1953},") {\n",{"type":23,"tag":102,"props":1955,"children":1956},{"class":104,"line":146},[1957,1962,1967,1971,1975,1979,1983,1987],{"type":23,"tag":102,"props":1958,"children":1959},{"style":188},[1960],{"type":29,"value":1961},"        return",{"type":23,"tag":102,"props":1963,"children":1964},{"style":194},[1965],{"type":29,"value":1966}," left",{"type":23,"tag":102,"props":1968,"children":1969},{"style":188},[1970],{"type":29,"value":1605},{"type":23,"tag":102,"props":1972,"children":1973},{"style":194},[1974],{"type":29,"value":1283},{"type":23,"tag":102,"props":1976,"children":1977},{"style":109},[1978],{"type":29,"value":1856},{"type":23,"tag":102,"props":1980,"children":1981},{"style":194},[1982],{"type":29,"value":343},{"type":23,"tag":102,"props":1984,"children":1985},{"style":188},[1986],{"type":29,"value":1532},{"type":23,"tag":102,"props":1988,"children":1989},{"style":194},[1990],{"type":29,"value":253},{"type":23,"tag":102,"props":1992,"children":1993},{"class":104,"line":217},[1994],{"type":23,"tag":102,"props":1995,"children":1996},{"style":194},[1997],{"type":29,"value":1826},{"type":23,"tag":102,"props":1999,"children":2000},{"class":104,"line":256},[2001,2005,2009,2013,2018,2022,2026,2031,2035,2039],{"type":23,"tag":102,"props":2002,"children":2003},{"style":188},[2004],{"type":29,"value":1552},{"type":23,"tag":102,"props":2006,"children":2007},{"style":194},[2008],{"type":29,"value":343},{"type":23,"tag":102,"props":2010,"children":2011},{"style":188},[2012],{"type":29,"value":1532},{"type":23,"tag":102,"props":2014,"children":2015},{"style":188},[2016],{"type":29,"value":2017}," >",{"type":23,"tag":102,"props":2019,"children":2020},{"style":188},[2021],{"type":29,"value":1327},{"type":23,"tag":102,"props":2023,"children":2024},{"style":188},[2025],{"type":29,"value":1574},{"type":23,"tag":102,"props":2027,"children":2028},{"style":194},[2029],{"type":29,"value":2030}," right",{"type":23,"tag":102,"props":2032,"children":2033},{"style":188},[2034],{"type":29,"value":1584},{"type":23,"tag":102,"props":2036,"children":2037},{"style":115},[2038],{"type":29,"value":1948},{"type":23,"tag":102,"props":2040,"children":2041},{"style":194},[2042],{"type":29,"value":1953},{"type":23,"tag":102,"props":2044,"children":2045},{"class":104,"line":283},[2046,2050,2054,2058,2062,2066,2070,2074],{"type":23,"tag":102,"props":2047,"children":2048},{"style":188},[2049],{"type":29,"value":1961},{"type":23,"tag":102,"props":2051,"children":2052},{"style":194},[2053],{"type":29,"value":2030},{"type":23,"tag":102,"props":2055,"children":2056},{"style":188},[2057],{"type":29,"value":1605},{"type":23,"tag":102,"props":2059,"children":2060},{"style":194},[2061],{"type":29,"value":1283},{"type":23,"tag":102,"props":2063,"children":2064},{"style":109},[2065],{"type":29,"value":1856},{"type":23,"tag":102,"props":2067,"children":2068},{"style":194},[2069],{"type":29,"value":343},{"type":23,"tag":102,"props":2071,"children":2072},{"style":188},[2073],{"type":29,"value":1532},{"type":23,"tag":102,"props":2075,"children":2076},{"style":194},[2077],{"type":29,"value":253},{"type":23,"tag":102,"props":2079,"children":2080},{"class":104,"line":301},[2081],{"type":23,"tag":102,"props":2082,"children":2083},{"style":194},[2084],{"type":29,"value":1826},{"type":23,"tag":102,"props":2086,"children":2087},{"class":104,"line":309},[2088,2093],{"type":23,"tag":102,"props":2089,"children":2090},{"style":188},[2091],{"type":29,"value":2092},"    return",{"type":23,"tag":102,"props":2094,"children":2095},{"style":188},[2096],{"type":29,"value":2097}," value==data\n",{"type":23,"tag":102,"props":2099,"children":2100},{"class":104,"line":323},[2101],{"type":23,"tag":102,"props":2102,"children":2103},{"style":194},[2104],{"type":29,"value":1430},{"type":23,"tag":24,"props":2106,"children":2108},{"id":2107},"removing-nodes-from-binary-search-tree",[2109],{"type":29,"value":2110},"Removing nodes from Binary Search Tree",{"type":23,"tag":32,"props":2112,"children":2113},{},[2114],{"type":29,"value":2115},"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":23,"tag":2117,"props":2118,"children":2119},"ol",{},[2120,2162,2198],{"type":23,"tag":749,"props":2121,"children":2122},{},[2123,2125,2131,2133],{"type":29,"value":2124},"The removed value is ",{"type":23,"tag":98,"props":2126,"children":2128},{"className":2127},[],[2129],{"type":29,"value":2130},"lower",{"type":29,"value":2132}," than the current node:\n",{"type":23,"tag":745,"props":2134,"children":2135},{},[2136,2153],{"type":23,"tag":749,"props":2137,"children":2138},{},[2139,2144,2146,2151],{"type":23,"tag":50,"props":2140,"children":2141},{},[2142],{"type":29,"value":2143},"if left child exist",{"type":29,"value":2145},", we use the ",{"type":23,"tag":50,"props":2147,"children":2148},{},[2149],{"type":29,"value":2150},"recursion",{"type":29,"value":2152}," to remove value from the left child",{"type":23,"tag":749,"props":2154,"children":2155},{},[2156,2160],{"type":23,"tag":50,"props":2157,"children":2158},{},[2159],{"type":29,"value":1639},{"type":29,"value":2161},", value does not exist in tree, return false.",{"type":23,"tag":749,"props":2163,"children":2164},{},[2165,2167,2172,2173],{"type":29,"value":2166},"Removed value is ",{"type":23,"tag":98,"props":2168,"children":2170},{"className":2169},[],[2171],{"type":29,"value":1490},{"type":29,"value":2132},{"type":23,"tag":745,"props":2174,"children":2175},{},[2176,2190],{"type":23,"tag":749,"props":2177,"children":2178},{},[2179,2184,2185,2189],{"type":23,"tag":50,"props":2180,"children":2181},{},[2182],{"type":29,"value":2183},"if right child exist",{"type":29,"value":2145},{"type":23,"tag":50,"props":2186,"children":2187},{},[2188],{"type":29,"value":2150},{"type":29,"value":2152},{"type":23,"tag":749,"props":2191,"children":2192},{},[2193,2197],{"type":23,"tag":50,"props":2194,"children":2195},{},[2196],{"type":29,"value":1639},{"type":29,"value":2161},{"type":23,"tag":749,"props":2199,"children":2200},{},[2201,2202,2208,2210],{"type":29,"value":2166},{"type":23,"tag":98,"props":2203,"children":2205},{"className":2204},[],[2206],{"type":29,"value":2207},"equals",{"type":29,"value":2209}," to the current node data:\n",{"type":23,"tag":745,"props":2211,"children":2212},{},[2213],{"type":23,"tag":749,"props":2214,"children":2215},{},[2216,2218],{"type":29,"value":2217},"Depending on the existing children we should remove or reorder ",{"type":23,"tag":1136,"props":2219,"children":2220},{},[2221],{"type":29,"value":2222},"(see code comments)",{"type":23,"tag":91,"props":2224,"children":2226},{"className":1286,"code":2225,"language":1204,"meta":7,"style":7},"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",[2227],{"type":23,"tag":98,"props":2228,"children":2229},{"__ignoreMap":7},[2230,2279,2287,2323,2369,2396,2408,2416,2460,2503,2530,2541,2549,2565,2573,2629,2645,2653,2714,2730,2738,2799,2819,2828,2889,2909,2918,2979,3000,3009,3071,3091,3100,3116,3152,3193,3202,3215,3223,3231,3239],{"type":23,"tag":102,"props":2231,"children":2232},{"class":104,"line":105},[2233,2237,2242,2246,2250,2254,2258,2263,2267,2271,2275],{"type":23,"tag":102,"props":2234,"children":2235},{"style":188},[2236],{"type":29,"value":1518},{"type":23,"tag":102,"props":2238,"children":2239},{"style":109},[2240],{"type":29,"value":2241}," remove",{"type":23,"tag":102,"props":2243,"children":2244},{"style":194},[2245],{"type":29,"value":343},{"type":23,"tag":102,"props":2247,"children":2248},{"style":188},[2249],{"type":29,"value":1532},{"type":23,"tag":102,"props":2251,"children":2252},{"style":194},[2253],{"type":29,"value":1332},{"type":23,"tag":102,"props":2255,"children":2256},{"style":109},[2257],{"type":29,"value":1337},{"type":23,"tag":102,"props":2259,"children":2260},{"style":194},[2261],{"type":29,"value":2262},", parent:",{"type":23,"tag":102,"props":2264,"children":2265},{"style":109},[2266],{"type":29,"value":1359},{"type":23,"tag":102,"props":2268,"children":2269},{"style":194},[2270],{"type":29,"value":1898},{"type":23,"tag":102,"props":2272,"children":2273},{"style":109},[2274],{"type":29,"value":1903},{"type":23,"tag":102,"props":2276,"children":2277},{"style":194},[2278],{"type":29,"value":1790},{"type":23,"tag":102,"props":2280,"children":2281},{"class":104,"line":132},[2282],{"type":23,"tag":102,"props":2283,"children":2284},{"style":211},[2285],{"type":29,"value":2286},"    // Value lower than current node data\n",{"type":23,"tag":102,"props":2288,"children":2289},{"class":104,"line":146},[2290,2294,2298,2303,2307,2311,2315,2319],{"type":23,"tag":102,"props":2291,"children":2292},{"style":188},[2293],{"type":29,"value":1552},{"type":23,"tag":102,"props":2295,"children":2296},{"style":194},[2297],{"type":29,"value":1649},{"type":23,"tag":102,"props":2299,"children":2300},{"style":188},[2301],{"type":29,"value":2302},"value\u003Cdata",{"type":23,"tag":102,"props":2304,"children":2305},{"style":188},[2306],{"type":29,"value":1574},{"type":23,"tag":102,"props":2308,"children":2309},{"style":194},[2310],{"type":29,"value":1966},{"type":23,"tag":102,"props":2312,"children":2313},{"style":188},[2314],{"type":29,"value":1584},{"type":23,"tag":102,"props":2316,"children":2317},{"style":115},[2318],{"type":29,"value":1948},{"type":23,"tag":102,"props":2320,"children":2321},{"style":194},[2322],{"type":29,"value":1414},{"type":23,"tag":102,"props":2324,"children":2325},{"class":104,"line":217},[2326,2330,2334,2338,2342,2347,2351,2355,2360,2365],{"type":23,"tag":102,"props":2327,"children":2328},{"style":188},[2329],{"type":29,"value":1961},{"type":23,"tag":102,"props":2331,"children":2332},{"style":194},[2333],{"type":29,"value":1966},{"type":23,"tag":102,"props":2335,"children":2336},{"style":188},[2337],{"type":29,"value":1605},{"type":23,"tag":102,"props":2339,"children":2340},{"style":194},[2341],{"type":29,"value":1283},{"type":23,"tag":102,"props":2343,"children":2344},{"style":109},[2345],{"type":29,"value":2346},"remove",{"type":23,"tag":102,"props":2348,"children":2349},{"style":194},[2350],{"type":29,"value":343},{"type":23,"tag":102,"props":2352,"children":2353},{"style":188},[2354],{"type":29,"value":1532},{"type":23,"tag":102,"props":2356,"children":2357},{"style":194},[2358],{"type":29,"value":2359},",",{"type":23,"tag":102,"props":2361,"children":2362},{"style":115},[2363],{"type":29,"value":2364},"this",{"type":23,"tag":102,"props":2366,"children":2367},{"style":194},[2368],{"type":29,"value":253},{"type":23,"tag":102,"props":2370,"children":2371},{"class":104,"line":256},[2372,2376,2380,2384,2388,2392],{"type":23,"tag":102,"props":2373,"children":2374},{"style":194},[2375],{"type":29,"value":1634},{"type":23,"tag":102,"props":2377,"children":2378},{"style":188},[2379],{"type":29,"value":1639},{"type":23,"tag":102,"props":2381,"children":2382},{"style":188},[2383],{"type":29,"value":1644},{"type":23,"tag":102,"props":2385,"children":2386},{"style":194},[2387],{"type":29,"value":343},{"type":23,"tag":102,"props":2389,"children":2390},{"style":188},[2391],{"type":29,"value":2302},{"type":23,"tag":102,"props":2393,"children":2394},{"style":194},[2395],{"type":29,"value":1414},{"type":23,"tag":102,"props":2397,"children":2398},{"class":104,"line":283},[2399,2403],{"type":23,"tag":102,"props":2400,"children":2401},{"style":188},[2402],{"type":29,"value":1961},{"type":23,"tag":102,"props":2404,"children":2405},{"style":115},[2406],{"type":29,"value":2407}," false\n",{"type":23,"tag":102,"props":2409,"children":2410},{"class":104,"line":301},[2411],{"type":23,"tag":102,"props":2412,"children":2413},{"style":211},[2414],{"type":29,"value":2415},"    // Value greater than current node data\n",{"type":23,"tag":102,"props":2417,"children":2418},{"class":104,"line":309},[2419,2423,2427,2431,2435,2440,2444,2448,2452,2456],{"type":23,"tag":102,"props":2420,"children":2421},{"style":194},[2422],{"type":29,"value":1634},{"type":23,"tag":102,"props":2424,"children":2425},{"style":188},[2426],{"type":29,"value":1639},{"type":23,"tag":102,"props":2428,"children":2429},{"style":188},[2430],{"type":29,"value":1644},{"type":23,"tag":102,"props":2432,"children":2433},{"style":194},[2434],{"type":29,"value":343},{"type":23,"tag":102,"props":2436,"children":2437},{"style":188},[2438],{"type":29,"value":2439},"value>data",{"type":23,"tag":102,"props":2441,"children":2442},{"style":188},[2443],{"type":29,"value":1574},{"type":23,"tag":102,"props":2445,"children":2446},{"style":194},[2447],{"type":29,"value":1730},{"type":23,"tag":102,"props":2449,"children":2450},{"style":188},[2451],{"type":29,"value":1584},{"type":23,"tag":102,"props":2453,"children":2454},{"style":115},[2455],{"type":29,"value":1373},{"type":23,"tag":102,"props":2457,"children":2458},{"style":194},[2459],{"type":29,"value":1414},{"type":23,"tag":102,"props":2461,"children":2462},{"class":104,"line":323},[2463,2467,2471,2475,2479,2483,2487,2491,2495,2499],{"type":23,"tag":102,"props":2464,"children":2465},{"style":188},[2466],{"type":29,"value":1961},{"type":23,"tag":102,"props":2468,"children":2469},{"style":194},[2470],{"type":29,"value":2030},{"type":23,"tag":102,"props":2472,"children":2473},{"style":188},[2474],{"type":29,"value":1605},{"type":23,"tag":102,"props":2476,"children":2477},{"style":194},[2478],{"type":29,"value":1283},{"type":23,"tag":102,"props":2480,"children":2481},{"style":109},[2482],{"type":29,"value":2346},{"type":23,"tag":102,"props":2484,"children":2485},{"style":194},[2486],{"type":29,"value":343},{"type":23,"tag":102,"props":2488,"children":2489},{"style":188},[2490],{"type":29,"value":1532},{"type":23,"tag":102,"props":2492,"children":2493},{"style":194},[2494],{"type":29,"value":2359},{"type":23,"tag":102,"props":2496,"children":2497},{"style":115},[2498],{"type":29,"value":2364},{"type":23,"tag":102,"props":2500,"children":2501},{"style":194},[2502],{"type":29,"value":253},{"type":23,"tag":102,"props":2504,"children":2505},{"class":104,"line":332},[2506,2510,2514,2518,2522,2526],{"type":23,"tag":102,"props":2507,"children":2508},{"style":194},[2509],{"type":29,"value":1634},{"type":23,"tag":102,"props":2511,"children":2512},{"style":188},[2513],{"type":29,"value":1639},{"type":23,"tag":102,"props":2515,"children":2516},{"style":188},[2517],{"type":29,"value":1644},{"type":23,"tag":102,"props":2519,"children":2520},{"style":194},[2521],{"type":29,"value":1649},{"type":23,"tag":102,"props":2523,"children":2524},{"style":188},[2525],{"type":29,"value":2439},{"type":23,"tag":102,"props":2527,"children":2528},{"style":194},[2529],{"type":29,"value":1414},{"type":23,"tag":102,"props":2531,"children":2532},{"class":104,"line":355},[2533,2537],{"type":23,"tag":102,"props":2534,"children":2535},{"style":188},[2536],{"type":29,"value":1961},{"type":23,"tag":102,"props":2538,"children":2539},{"style":115},[2540],{"type":29,"value":2407},{"type":23,"tag":102,"props":2542,"children":2543},{"class":104,"line":368},[2544],{"type":23,"tag":102,"props":2545,"children":2546},{"style":211},[2547],{"type":29,"value":2548},"    // Value equals the greater node data\n",{"type":23,"tag":102,"props":2550,"children":2551},{"class":104,"line":968},[2552,2556,2560],{"type":23,"tag":102,"props":2553,"children":2554},{"style":194},[2555],{"type":29,"value":1634},{"type":23,"tag":102,"props":2557,"children":2558},{"style":188},[2559],{"type":29,"value":1639},{"type":23,"tag":102,"props":2561,"children":2562},{"style":194},[2563],{"type":29,"value":2564}," {\n",{"type":23,"tag":102,"props":2566,"children":2567},{"class":104,"line":988},[2568],{"type":23,"tag":102,"props":2569,"children":2570},{"style":211},[2571],{"type":29,"value":2572},"        // No Children, current node is parents LEFT node\n",{"type":23,"tag":102,"props":2574,"children":2575},{"class":104,"line":996},[2576,2580,2585,2590,2594,2598,2602,2606,2610,2614,2619,2624],{"type":23,"tag":102,"props":2577,"children":2578},{"style":188},[2579],{"type":29,"value":1051},{"type":23,"tag":102,"props":2581,"children":2582},{"style":194},[2583],{"type":29,"value":2584}," (left ",{"type":23,"tag":102,"props":2586,"children":2587},{"style":188},[2588],{"type":29,"value":2589},"==",{"type":23,"tag":102,"props":2591,"children":2592},{"style":115},[2593],{"type":29,"value":1373},{"type":23,"tag":102,"props":2595,"children":2596},{"style":188},[2597],{"type":29,"value":1574},{"type":23,"tag":102,"props":2599,"children":2600},{"style":194},[2601],{"type":29,"value":2030},{"type":23,"tag":102,"props":2603,"children":2604},{"style":188},[2605],{"type":29,"value":2589},{"type":23,"tag":102,"props":2607,"children":2608},{"style":115},[2609],{"type":29,"value":1948},{"type":23,"tag":102,"props":2611,"children":2612},{"style":188},[2613],{"type":29,"value":1574},{"type":23,"tag":102,"props":2615,"children":2616},{"style":115},[2617],{"type":29,"value":2618}," this",{"type":23,"tag":102,"props":2620,"children":2621},{"style":188},[2622],{"type":29,"value":2623}," ==",{"type":23,"tag":102,"props":2625,"children":2626},{"style":194},[2627],{"type":29,"value":2628}," parent.left) {\n",{"type":23,"tag":102,"props":2630,"children":2631},{"class":104,"line":1014},[2632,2637,2641],{"type":23,"tag":102,"props":2633,"children":2634},{"style":194},[2635],{"type":29,"value":2636},"            parent.left ",{"type":23,"tag":102,"props":2638,"children":2639},{"style":188},[2640],{"type":29,"value":228},{"type":23,"tag":102,"props":2642,"children":2643},{"style":115},[2644],{"type":29,"value":1406},{"type":23,"tag":102,"props":2646,"children":2647},{"class":104,"line":1023},[2648],{"type":23,"tag":102,"props":2649,"children":2650},{"style":211},[2651],{"type":29,"value":2652},"        // No Children, current node is parents RIGHT node\n",{"type":23,"tag":102,"props":2654,"children":2655},{"class":104,"line":1045},[2656,2661,2665,2669,2673,2677,2681,2685,2689,2693,2697,2701,2705,2709],{"type":23,"tag":102,"props":2657,"children":2658},{"style":194},[2659],{"type":29,"value":2660},"        }",{"type":23,"tag":102,"props":2662,"children":2663},{"style":188},[2664],{"type":29,"value":1639},{"type":23,"tag":102,"props":2666,"children":2667},{"style":188},[2668],{"type":29,"value":1644},{"type":23,"tag":102,"props":2670,"children":2671},{"style":194},[2672],{"type":29,"value":2584},{"type":23,"tag":102,"props":2674,"children":2675},{"style":188},[2676],{"type":29,"value":2589},{"type":23,"tag":102,"props":2678,"children":2679},{"style":115},[2680],{"type":29,"value":1373},{"type":23,"tag":102,"props":2682,"children":2683},{"style":188},[2684],{"type":29,"value":1574},{"type":23,"tag":102,"props":2686,"children":2687},{"style":194},[2688],{"type":29,"value":2030},{"type":23,"tag":102,"props":2690,"children":2691},{"style":188},[2692],{"type":29,"value":2589},{"type":23,"tag":102,"props":2694,"children":2695},{"style":115},[2696],{"type":29,"value":1948},{"type":23,"tag":102,"props":2698,"children":2699},{"style":188},[2700],{"type":29,"value":1574},{"type":23,"tag":102,"props":2702,"children":2703},{"style":115},[2704],{"type":29,"value":2618},{"type":23,"tag":102,"props":2706,"children":2707},{"style":188},[2708],{"type":29,"value":2589},{"type":23,"tag":102,"props":2710,"children":2711},{"style":194},[2712],{"type":29,"value":2713},"parent.right){\n",{"type":23,"tag":102,"props":2715,"children":2716},{"class":104,"line":1064},[2717,2722,2726],{"type":23,"tag":102,"props":2718,"children":2719},{"style":194},[2720],{"type":29,"value":2721},"            parent.right ",{"type":23,"tag":102,"props":2723,"children":2724},{"style":188},[2725],{"type":29,"value":228},{"type":23,"tag":102,"props":2727,"children":2728},{"style":115},[2729],{"type":29,"value":1406},{"type":23,"tag":102,"props":2731,"children":2732},{"class":104,"line":1096},[2733],{"type":23,"tag":102,"props":2734,"children":2735},{"style":211},[2736],{"type":29,"value":2737},"        // ONLY LEFT child, current node is parents LEFT node\n",{"type":23,"tag":102,"props":2739,"children":2740},{"class":104,"line":1105},[2741,2745,2749,2753,2758,2762,2766,2770,2774,2778,2782,2786,2790,2794],{"type":23,"tag":102,"props":2742,"children":2743},{"style":194},[2744],{"type":29,"value":2660},{"type":23,"tag":102,"props":2746,"children":2747},{"style":188},[2748],{"type":29,"value":1639},{"type":23,"tag":102,"props":2750,"children":2751},{"style":188},[2752],{"type":29,"value":1644},{"type":23,"tag":102,"props":2754,"children":2755},{"style":194},[2756],{"type":29,"value":2757},"(left",{"type":23,"tag":102,"props":2759,"children":2760},{"style":188},[2761],{"type":29,"value":1584},{"type":23,"tag":102,"props":2763,"children":2764},{"style":115},[2765],{"type":29,"value":1948},{"type":23,"tag":102,"props":2767,"children":2768},{"style":188},[2769],{"type":29,"value":1574},{"type":23,"tag":102,"props":2771,"children":2772},{"style":194},[2773],{"type":29,"value":2030},{"type":23,"tag":102,"props":2775,"children":2776},{"style":188},[2777],{"type":29,"value":2589},{"type":23,"tag":102,"props":2779,"children":2780},{"style":115},[2781],{"type":29,"value":1948},{"type":23,"tag":102,"props":2783,"children":2784},{"style":188},[2785],{"type":29,"value":1574},{"type":23,"tag":102,"props":2787,"children":2788},{"style":115},[2789],{"type":29,"value":2618},{"type":23,"tag":102,"props":2791,"children":2792},{"style":188},[2793],{"type":29,"value":2623},{"type":23,"tag":102,"props":2795,"children":2796},{"style":194},[2797],{"type":29,"value":2798}," parent.left){\n",{"type":23,"tag":102,"props":2800,"children":2801},{"class":104,"line":1114},[2802,2806,2810,2814],{"type":23,"tag":102,"props":2803,"children":2804},{"style":194},[2805],{"type":29,"value":2636},{"type":23,"tag":102,"props":2807,"children":2808},{"style":188},[2809],{"type":29,"value":228},{"type":23,"tag":102,"props":2811,"children":2812},{"style":115},[2813],{"type":29,"value":2618},{"type":23,"tag":102,"props":2815,"children":2816},{"style":194},[2817],{"type":29,"value":2818},".left\n",{"type":23,"tag":102,"props":2820,"children":2822},{"class":104,"line":2821},23,[2823],{"type":23,"tag":102,"props":2824,"children":2825},{"style":211},[2826],{"type":29,"value":2827},"        // ONLY LEFT child, current node is parents RIGHT node\n",{"type":23,"tag":102,"props":2829,"children":2831},{"class":104,"line":2830},24,[2832,2836,2840,2844,2848,2852,2856,2860,2864,2868,2872,2876,2880,2884],{"type":23,"tag":102,"props":2833,"children":2834},{"style":194},[2835],{"type":29,"value":2660},{"type":23,"tag":102,"props":2837,"children":2838},{"style":188},[2839],{"type":29,"value":1639},{"type":23,"tag":102,"props":2841,"children":2842},{"style":188},[2843],{"type":29,"value":1644},{"type":23,"tag":102,"props":2845,"children":2846},{"style":194},[2847],{"type":29,"value":2757},{"type":23,"tag":102,"props":2849,"children":2850},{"style":188},[2851],{"type":29,"value":1584},{"type":23,"tag":102,"props":2853,"children":2854},{"style":115},[2855],{"type":29,"value":1948},{"type":23,"tag":102,"props":2857,"children":2858},{"style":188},[2859],{"type":29,"value":1574},{"type":23,"tag":102,"props":2861,"children":2862},{"style":194},[2863],{"type":29,"value":2030},{"type":23,"tag":102,"props":2865,"children":2866},{"style":188},[2867],{"type":29,"value":2589},{"type":23,"tag":102,"props":2869,"children":2870},{"style":115},[2871],{"type":29,"value":1373},{"type":23,"tag":102,"props":2873,"children":2874},{"style":188},[2875],{"type":29,"value":1574},{"type":23,"tag":102,"props":2877,"children":2878},{"style":115},[2879],{"type":29,"value":2618},{"type":23,"tag":102,"props":2881,"children":2882},{"style":188},[2883],{"type":29,"value":2623},{"type":23,"tag":102,"props":2885,"children":2886},{"style":194},[2887],{"type":29,"value":2888}," parent.right){\n",{"type":23,"tag":102,"props":2890,"children":2892},{"class":104,"line":2891},25,[2893,2897,2901,2905],{"type":23,"tag":102,"props":2894,"children":2895},{"style":194},[2896],{"type":29,"value":2721},{"type":23,"tag":102,"props":2898,"children":2899},{"style":188},[2900],{"type":29,"value":228},{"type":23,"tag":102,"props":2902,"children":2903},{"style":115},[2904],{"type":29,"value":2618},{"type":23,"tag":102,"props":2906,"children":2907},{"style":194},[2908],{"type":29,"value":2818},{"type":23,"tag":102,"props":2910,"children":2912},{"class":104,"line":2911},26,[2913],{"type":23,"tag":102,"props":2914,"children":2915},{"style":211},[2916],{"type":29,"value":2917},"        // ONLY RIGHT child, current node is parents LEFT node\n",{"type":23,"tag":102,"props":2919,"children":2921},{"class":104,"line":2920},27,[2922,2926,2930,2934,2939,2943,2947,2951,2955,2959,2963,2967,2971,2975],{"type":23,"tag":102,"props":2923,"children":2924},{"style":194},[2925],{"type":29,"value":2660},{"type":23,"tag":102,"props":2927,"children":2928},{"style":188},[2929],{"type":29,"value":1639},{"type":23,"tag":102,"props":2931,"children":2932},{"style":188},[2933],{"type":29,"value":1644},{"type":23,"tag":102,"props":2935,"children":2936},{"style":194},[2937],{"type":29,"value":2938}," (right",{"type":23,"tag":102,"props":2940,"children":2941},{"style":188},[2942],{"type":29,"value":1584},{"type":23,"tag":102,"props":2944,"children":2945},{"style":115},[2946],{"type":29,"value":1948},{"type":23,"tag":102,"props":2948,"children":2949},{"style":188},[2950],{"type":29,"value":1574},{"type":23,"tag":102,"props":2952,"children":2953},{"style":194},[2954],{"type":29,"value":1966},{"type":23,"tag":102,"props":2956,"children":2957},{"style":188},[2958],{"type":29,"value":2589},{"type":23,"tag":102,"props":2960,"children":2961},{"style":115},[2962],{"type":29,"value":1948},{"type":23,"tag":102,"props":2964,"children":2965},{"style":188},[2966],{"type":29,"value":1574},{"type":23,"tag":102,"props":2968,"children":2969},{"style":115},[2970],{"type":29,"value":2618},{"type":23,"tag":102,"props":2972,"children":2973},{"style":188},[2974],{"type":29,"value":2623},{"type":23,"tag":102,"props":2976,"children":2977},{"style":194},[2978],{"type":29,"value":2628},{"type":23,"tag":102,"props":2980,"children":2982},{"class":104,"line":2981},28,[2983,2987,2991,2995],{"type":23,"tag":102,"props":2984,"children":2985},{"style":194},[2986],{"type":29,"value":2636},{"type":23,"tag":102,"props":2988,"children":2989},{"style":188},[2990],{"type":29,"value":228},{"type":23,"tag":102,"props":2992,"children":2993},{"style":115},[2994],{"type":29,"value":2618},{"type":23,"tag":102,"props":2996,"children":2997},{"style":194},[2998],{"type":29,"value":2999},".right\n",{"type":23,"tag":102,"props":3001,"children":3003},{"class":104,"line":3002},29,[3004],{"type":23,"tag":102,"props":3005,"children":3006},{"style":211},[3007],{"type":29,"value":3008},"        // ONLY RIGHT child, current node is parents RIGHT node\n",{"type":23,"tag":102,"props":3010,"children":3012},{"class":104,"line":3011},30,[3013,3017,3021,3025,3030,3034,3038,3042,3046,3050,3054,3058,3062,3066],{"type":23,"tag":102,"props":3014,"children":3015},{"style":194},[3016],{"type":29,"value":2660},{"type":23,"tag":102,"props":3018,"children":3019},{"style":188},[3020],{"type":29,"value":1639},{"type":23,"tag":102,"props":3022,"children":3023},{"style":188},[3024],{"type":29,"value":1644},{"type":23,"tag":102,"props":3026,"children":3027},{"style":194},[3028],{"type":29,"value":3029},"(right",{"type":23,"tag":102,"props":3031,"children":3032},{"style":188},[3033],{"type":29,"value":1584},{"type":23,"tag":102,"props":3035,"children":3036},{"style":115},[3037],{"type":29,"value":1948},{"type":23,"tag":102,"props":3039,"children":3040},{"style":188},[3041],{"type":29,"value":1574},{"type":23,"tag":102,"props":3043,"children":3044},{"style":194},[3045],{"type":29,"value":1966},{"type":23,"tag":102,"props":3047,"children":3048},{"style":188},[3049],{"type":29,"value":2589},{"type":23,"tag":102,"props":3051,"children":3052},{"style":115},[3053],{"type":29,"value":1948},{"type":23,"tag":102,"props":3055,"children":3056},{"style":188},[3057],{"type":29,"value":1574},{"type":23,"tag":102,"props":3059,"children":3060},{"style":115},[3061],{"type":29,"value":2618},{"type":23,"tag":102,"props":3063,"children":3064},{"style":188},[3065],{"type":29,"value":2623},{"type":23,"tag":102,"props":3067,"children":3068},{"style":194},[3069],{"type":29,"value":3070}," parent.right) {\n",{"type":23,"tag":102,"props":3072,"children":3074},{"class":104,"line":3073},31,[3075,3079,3083,3087],{"type":23,"tag":102,"props":3076,"children":3077},{"style":194},[3078],{"type":29,"value":2721},{"type":23,"tag":102,"props":3080,"children":3081},{"style":188},[3082],{"type":29,"value":228},{"type":23,"tag":102,"props":3084,"children":3085},{"style":115},[3086],{"type":29,"value":2618},{"type":23,"tag":102,"props":3088,"children":3089},{"style":194},[3090],{"type":29,"value":2999},{"type":23,"tag":102,"props":3092,"children":3094},{"class":104,"line":3093},32,[3095],{"type":23,"tag":102,"props":3096,"children":3097},{"style":211},[3098],{"type":29,"value":3099},"        // BOTH Children exists, replace current data with min value from right \n",{"type":23,"tag":102,"props":3101,"children":3103},{"class":104,"line":3102},33,[3104,3108,3112],{"type":23,"tag":102,"props":3105,"children":3106},{"style":194},[3107],{"type":29,"value":2660},{"type":23,"tag":102,"props":3109,"children":3110},{"style":188},[3111],{"type":29,"value":1639},{"type":23,"tag":102,"props":3113,"children":3114},{"style":194},[3115],{"type":29,"value":1790},{"type":23,"tag":102,"props":3117,"children":3119},{"class":104,"line":3118},34,[3120,3125,3130,3134,3138,3142,3147],{"type":23,"tag":102,"props":3121,"children":3122},{"style":188},[3123],{"type":29,"value":3124},"            data",{"type":23,"tag":102,"props":3126,"children":3127},{"style":188},[3128],{"type":29,"value":3129}," =",{"type":23,"tag":102,"props":3131,"children":3132},{"style":194},[3133],{"type":29,"value":2030},{"type":23,"tag":102,"props":3135,"children":3136},{"style":188},[3137],{"type":29,"value":1605},{"type":23,"tag":102,"props":3139,"children":3140},{"style":194},[3141],{"type":29,"value":1283},{"type":23,"tag":102,"props":3143,"children":3144},{"style":109},[3145],{"type":29,"value":3146},"min",{"type":23,"tag":102,"props":3148,"children":3149},{"style":194},[3150],{"type":29,"value":3151},"()\n",{"type":23,"tag":102,"props":3153,"children":3155},{"class":104,"line":3154},35,[3156,3161,3165,3169,3173,3177,3181,3185,3189],{"type":23,"tag":102,"props":3157,"children":3158},{"style":194},[3159],{"type":29,"value":3160},"            right",{"type":23,"tag":102,"props":3162,"children":3163},{"style":188},[3164],{"type":29,"value":1605},{"type":23,"tag":102,"props":3166,"children":3167},{"style":194},[3168],{"type":29,"value":1283},{"type":23,"tag":102,"props":3170,"children":3171},{"style":109},[3172],{"type":29,"value":2346},{"type":23,"tag":102,"props":3174,"children":3175},{"style":194},[3176],{"type":29,"value":343},{"type":23,"tag":102,"props":3178,"children":3179},{"style":188},[3180],{"type":29,"value":1299},{"type":23,"tag":102,"props":3182,"children":3183},{"style":194},[3184],{"type":29,"value":2359},{"type":23,"tag":102,"props":3186,"children":3187},{"style":115},[3188],{"type":29,"value":2364},{"type":23,"tag":102,"props":3190,"children":3191},{"style":194},[3192],{"type":29,"value":253},{"type":23,"tag":102,"props":3194,"children":3196},{"class":104,"line":3195},36,[3197],{"type":23,"tag":102,"props":3198,"children":3199},{"style":194},[3200],{"type":29,"value":3201},"        }\n",{"type":23,"tag":102,"props":3203,"children":3205},{"class":104,"line":3204},37,[3206,3210],{"type":23,"tag":102,"props":3207,"children":3208},{"style":188},[3209],{"type":29,"value":1961},{"type":23,"tag":102,"props":3211,"children":3212},{"style":115},[3213],{"type":29,"value":3214}," true\n",{"type":23,"tag":102,"props":3216,"children":3218},{"class":104,"line":3217},38,[3219],{"type":23,"tag":102,"props":3220,"children":3221},{"style":194},[3222],{"type":29,"value":1826},{"type":23,"tag":102,"props":3224,"children":3226},{"class":104,"line":3225},39,[3227],{"type":23,"tag":102,"props":3228,"children":3229},{"style":194},[3230],{"type":29,"value":1430},{"type":23,"tag":102,"props":3232,"children":3234},{"class":104,"line":3233},40,[3235],{"type":23,"tag":102,"props":3236,"children":3237},{"emptyLinePlaceholder":202},[3238],{"type":29,"value":205},{"type":23,"tag":102,"props":3240,"children":3242},{"class":104,"line":3241},41,[3243,3247,3252,3257,3261,3265,3269,3274,3278,3282,3287,3291,3296,3300,3304,3308,3312],{"type":23,"tag":102,"props":3244,"children":3245},{"style":188},[3246],{"type":29,"value":1518},{"type":23,"tag":102,"props":3248,"children":3249},{"style":109},[3250],{"type":29,"value":3251}," min",{"type":23,"tag":102,"props":3253,"children":3254},{"style":194},[3255],{"type":29,"value":3256},"() : ",{"type":23,"tag":102,"props":3258,"children":3259},{"style":109},[3260],{"type":29,"value":1337},{"type":23,"tag":102,"props":3262,"children":3263},{"style":188},[3264],{"type":29,"value":3129},{"type":23,"tag":102,"props":3266,"children":3267},{"style":188},[3268],{"type":29,"value":1644},{"type":23,"tag":102,"props":3270,"children":3271},{"style":194},[3272],{"type":29,"value":3273}," (left",{"type":23,"tag":102,"props":3275,"children":3276},{"style":188},[3277],{"type":29,"value":2589},{"type":23,"tag":102,"props":3279,"children":3280},{"style":115},[3281],{"type":29,"value":1948},{"type":23,"tag":102,"props":3283,"children":3284},{"style":194},[3285],{"type":29,"value":3286},") ",{"type":23,"tag":102,"props":3288,"children":3289},{"style":188},[3290],{"type":29,"value":1299},{"type":23,"tag":102,"props":3292,"children":3293},{"style":188},[3294],{"type":29,"value":3295}," else",{"type":23,"tag":102,"props":3297,"children":3298},{"style":194},[3299],{"type":29,"value":1966},{"type":23,"tag":102,"props":3301,"children":3302},{"style":188},[3303],{"type":29,"value":1605},{"type":23,"tag":102,"props":3305,"children":3306},{"style":194},[3307],{"type":29,"value":1283},{"type":23,"tag":102,"props":3309,"children":3310},{"style":109},[3311],{"type":29,"value":3146},{"type":23,"tag":102,"props":3313,"children":3314},{"style":194},[3315],{"type":29,"value":3151},{"type":23,"tag":32,"props":3317,"children":3318},{},[3319,3321],{"type":29,"value":3320},"You can find the complete code of this example in this\n",{"type":23,"tag":38,"props":3322,"children":3324},{"href":3323,"target":41},"https://github.com/JaimeDeArcos/kotlin-algorithms/blob/main/trees/src/main/kotlin/es/jaimedearcos/algorithms/tree/data/BinarySearchTreeNode.kt",[3325],{"type":29,"value":3326},"\nGitHub repository\n",{"type":23,"tag":1175,"props":3328,"children":3329},{},[3330],{"type":29,"value":1179},{"title":7,"searchDepth":132,"depth":132,"links":3332},[3333,3334,3335,3336],{"id":1267,"depth":132,"text":1270},{"id":1445,"depth":132,"text":1448},{"id":1836,"depth":132,"text":1839},{"id":2107,"depth":132,"text":2110},"content:posts:algorithms-binary-search-tree.md","posts/algorithms-binary-search-tree.md","posts/algorithms-binary-search-tree",{"_path":3341,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":3342,"description":3343,"date":3344,"layout":11,"subtitle":3343,"image":1202,"optimized_image":1202,"category":13,"tags":3345,"author":18,"paginate":6,"body":3346,"_type":1191,"_id":4553,"_source":1193,"_file":4554,"_stem":4555,"_extension":1196},"/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",[98,1204,1205,13],{"type":20,"children":3347,"toc":4546},[3348,3354,3373,3378,3419,3425,3430,3494,3500,3510,3518,3637,3645,3812,3820,3972,3980,4134,4140,4147,4152,4183,4531,4542],{"type":23,"tag":24,"props":3349,"children":3351},{"id":3350},"traversals",[3352],{"type":29,"value":3353},"Traversals :",{"type":23,"tag":1209,"props":3355,"children":3356},{},[3357],{"type":23,"tag":32,"props":3358,"children":3359},{},[3360,3365,3367],{"type":23,"tag":1136,"props":3361,"children":3362},{},[3363],{"type":29,"value":3364},"\"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":29,"value":3366}," -— ",{"type":23,"tag":38,"props":3368,"children":3371},{"href":3369,"rel":3370},"https://en.wikipedia.org/wiki/Tree_traversal",[1168],[3372],{"type":29,"value":1228},{"type":23,"tag":32,"props":3374,"children":3375},{},[3376],{"type":29,"value":3377},"There are 2 options:",{"type":23,"tag":745,"props":3379,"children":3380},{},[3381,3397],{"type":23,"tag":749,"props":3382,"children":3383},{},[3384,3389,3391],{"type":23,"tag":50,"props":3385,"children":3386},{},[3387],{"type":29,"value":3388},"DFS",{"type":29,"value":3390}," : 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":23,"tag":38,"props":3392,"children":3395},{"href":3393,"rel":3394},"https://en.wikipedia.org/wiki/Depth-first_search",[1168],[3396],{"type":29,"value":1228},{"type":23,"tag":749,"props":3398,"children":3399},{},[3400,3405,3407,3412,3413],{"type":23,"tag":50,"props":3401,"children":3402},{},[3403],{"type":29,"value":3404},"BFS",{"type":29,"value":3406}," : Breadth-First Search ",{"type":23,"tag":1136,"props":3408,"children":3409},{},[3410],{"type":29,"value":3411},"“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":29,"value":3366},{"type":23,"tag":38,"props":3414,"children":3417},{"href":3415,"rel":3416},"https://en.wikipedia.org/wiki/Breadth-first_search",[1168],[3418],{"type":29,"value":1228},{"type":23,"tag":24,"props":3420,"children":3422},{"id":3421},"dfs-depth-first-search",[3423],{"type":29,"value":3424},"DFS - Depth-First Search",{"type":23,"tag":32,"props":3426,"children":3427},{},[3428],{"type":29,"value":3429},"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":23,"tag":745,"props":3431,"children":3432},{},[3433,3454,3474],{"type":23,"tag":749,"props":3434,"children":3435},{},[3436,3441,3443,3448,3450],{"type":23,"tag":50,"props":3437,"children":3438},{},[3439],{"type":29,"value":3440},"Pre-Order",{"type":29,"value":3442},": ",{"type":23,"tag":1136,"props":3444,"children":3445},{},[3446],{"type":29,"value":3447},"(NLR)",{"type":29,"value":3449}," process node data, left child and finally right child\n",{"type":23,"tag":61,"props":3451,"children":3453},{"alt":7,"src":3452},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/pre-order.gif",[],{"type":23,"tag":749,"props":3455,"children":3456},{},[3457,3462,3463,3468,3470],{"type":23,"tag":50,"props":3458,"children":3459},{},[3460],{"type":29,"value":3461},"In-Order",{"type":29,"value":3442},{"type":23,"tag":1136,"props":3464,"children":3465},{},[3466],{"type":29,"value":3467},"(LNR)",{"type":29,"value":3469}," process left child, node data and finally right child\n",{"type":23,"tag":61,"props":3471,"children":3473},{"alt":7,"src":3472},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/in-order.gif",[],{"type":23,"tag":749,"props":3475,"children":3476},{},[3477,3482,3483,3488,3490],{"type":23,"tag":50,"props":3478,"children":3479},{},[3480],{"type":29,"value":3481},"Post-Order",{"type":29,"value":3442},{"type":23,"tag":1136,"props":3484,"children":3485},{},[3486],{"type":29,"value":3487},"(LRN)",{"type":29,"value":3489}," process left child, right child and finally node data\n",{"type":23,"tag":61,"props":3491,"children":3493},{"alt":7,"src":3492},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/post-order.gif",[],{"type":23,"tag":423,"props":3495,"children":3497},{"id":3496},"kotlin-examples",[3498],{"type":29,"value":3499},"Kotlin Examples:",{"type":23,"tag":32,"props":3501,"children":3502},{},[3503,3505,3509],{"type":29,"value":3504},"Usually the DFS algorithms are ease to implement with ",{"type":23,"tag":50,"props":3506,"children":3507},{},[3508],{"type":29,"value":2150},{"type":29,"value":1283},{"type":23,"tag":32,"props":3511,"children":3512},{},[3513],{"type":23,"tag":50,"props":3514,"children":3515},{},[3516],{"type":29,"value":3517},"Binary tree",{"type":23,"tag":91,"props":3519,"children":3521},{"className":1286,"code":3520,"language":1204,"meta":7,"style":7},"data class BinaryTreeNode(\n        val data:Int,\n        val left:BinaryTreeNode? = null,\n        val right:BinaryTreeNode? = null\n)\n",[3522],{"type":23,"tag":98,"props":3523,"children":3524},{"__ignoreMap":7},[3525,3545,3569,3602,3630],{"type":23,"tag":102,"props":3526,"children":3527},{"class":104,"line":105},[3528,3532,3536,3541],{"type":23,"tag":102,"props":3529,"children":3530},{"style":188},[3531],{"type":29,"value":1299},{"type":23,"tag":102,"props":3533,"children":3534},{"style":188},[3535],{"type":29,"value":1304},{"type":23,"tag":102,"props":3537,"children":3538},{"style":109},[3539],{"type":29,"value":3540}," BinaryTreeNode",{"type":23,"tag":102,"props":3542,"children":3543},{"style":194},[3544],{"type":29,"value":1314},{"type":23,"tag":102,"props":3546,"children":3547},{"class":104,"line":132},[3548,3553,3557,3561,3565],{"type":23,"tag":102,"props":3549,"children":3550},{"style":188},[3551],{"type":29,"value":3552},"        val",{"type":23,"tag":102,"props":3554,"children":3555},{"style":188},[3556],{"type":29,"value":1327},{"type":23,"tag":102,"props":3558,"children":3559},{"style":194},[3560],{"type":29,"value":1332},{"type":23,"tag":102,"props":3562,"children":3563},{"style":109},[3564],{"type":29,"value":1337},{"type":23,"tag":102,"props":3566,"children":3567},{"style":194},[3568],{"type":29,"value":1342},{"type":23,"tag":102,"props":3570,"children":3571},{"class":104,"line":146},[3572,3576,3581,3586,3590,3594,3598],{"type":23,"tag":102,"props":3573,"children":3574},{"style":188},[3575],{"type":29,"value":3552},{"type":23,"tag":102,"props":3577,"children":3578},{"style":194},[3579],{"type":29,"value":3580}," left:",{"type":23,"tag":102,"props":3582,"children":3583},{"style":109},[3584],{"type":29,"value":3585},"BinaryTreeNode",{"type":23,"tag":102,"props":3587,"children":3588},{"style":194},[3589],{"type":29,"value":1364},{"type":23,"tag":102,"props":3591,"children":3592},{"style":188},[3593],{"type":29,"value":228},{"type":23,"tag":102,"props":3595,"children":3596},{"style":115},[3597],{"type":29,"value":1373},{"type":23,"tag":102,"props":3599,"children":3600},{"style":194},[3601],{"type":29,"value":1342},{"type":23,"tag":102,"props":3603,"children":3604},{"class":104,"line":217},[3605,3609,3614,3618,3622,3626],{"type":23,"tag":102,"props":3606,"children":3607},{"style":188},[3608],{"type":29,"value":3552},{"type":23,"tag":102,"props":3610,"children":3611},{"style":194},[3612],{"type":29,"value":3613}," right:",{"type":23,"tag":102,"props":3615,"children":3616},{"style":109},[3617],{"type":29,"value":3585},{"type":23,"tag":102,"props":3619,"children":3620},{"style":194},[3621],{"type":29,"value":1364},{"type":23,"tag":102,"props":3623,"children":3624},{"style":188},[3625],{"type":29,"value":228},{"type":23,"tag":102,"props":3627,"children":3628},{"style":115},[3629],{"type":29,"value":1406},{"type":23,"tag":102,"props":3631,"children":3632},{"class":104,"line":256},[3633],{"type":23,"tag":102,"props":3634,"children":3635},{"style":194},[3636],{"type":29,"value":253},{"type":23,"tag":32,"props":3638,"children":3639},{},[3640],{"type":23,"tag":50,"props":3641,"children":3642},{},[3643],{"type":29,"value":3644},"Preorder traversal",{"type":23,"tag":91,"props":3646,"children":3648},{"className":1286,"code":3647,"language":1204,"meta":7,"style":7},"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",[3649],{"type":23,"tag":98,"props":3650,"children":3651},{"__ignoreMap":7},[3652,3678,3704,3738,3746,3764,3772,3785,3793,3805],{"type":23,"tag":102,"props":3653,"children":3654},{"class":104,"line":105},[3655,3659,3664,3669,3673],{"type":23,"tag":102,"props":3656,"children":3657},{"style":188},[3658],{"type":29,"value":1518},{"type":23,"tag":102,"props":3660,"children":3661},{"style":109},[3662],{"type":29,"value":3663}," preOrderTraversal",{"type":23,"tag":102,"props":3665,"children":3666},{"style":194},[3667],{"type":29,"value":3668},"(node: ",{"type":23,"tag":102,"props":3670,"children":3671},{"style":109},[3672],{"type":29,"value":3585},{"type":23,"tag":102,"props":3674,"children":3675},{"style":194},[3676],{"type":29,"value":3677},"?, \n",{"type":23,"tag":102,"props":3679,"children":3680},{"class":104,"line":132},[3681,3686,3690,3695,3700],{"type":23,"tag":102,"props":3682,"children":3683},{"style":194},[3684],{"type":29,"value":3685},"                      operation: (",{"type":23,"tag":102,"props":3687,"children":3688},{"style":109},[3689],{"type":29,"value":3585},{"type":23,"tag":102,"props":3691,"children":3692},{"style":194},[3693],{"type":29,"value":3694},") -> ",{"type":23,"tag":102,"props":3696,"children":3697},{"style":109},[3698],{"type":29,"value":3699},"Unit",{"type":23,"tag":102,"props":3701,"children":3702},{"style":194},[3703],{"type":29,"value":1414},{"type":23,"tag":102,"props":3705,"children":3706},{"class":104,"line":146},[3707,3711,3716,3720,3724,3728,3733],{"type":23,"tag":102,"props":3708,"children":3709},{"style":188},[3710],{"type":29,"value":1552},{"type":23,"tag":102,"props":3712,"children":3713},{"style":194},[3714],{"type":29,"value":3715}," (node ",{"type":23,"tag":102,"props":3717,"children":3718},{"style":188},[3719],{"type":29,"value":2589},{"type":23,"tag":102,"props":3721,"children":3722},{"style":115},[3723],{"type":29,"value":1373},{"type":23,"tag":102,"props":3725,"children":3726},{"style":194},[3727],{"type":29,"value":3286},{"type":23,"tag":102,"props":3729,"children":3730},{"style":188},[3731],{"type":29,"value":3732},"return",{"type":23,"tag":102,"props":3734,"children":3735},{"style":194},[3736],{"type":29,"value":3737},";\n",{"type":23,"tag":102,"props":3739,"children":3740},{"class":104,"line":217},[3741],{"type":23,"tag":102,"props":3742,"children":3743},{"style":211},[3744],{"type":29,"value":3745},"    // Visit node\n",{"type":23,"tag":102,"props":3747,"children":3748},{"class":104,"line":256},[3749,3754,3759],{"type":23,"tag":102,"props":3750,"children":3751},{"style":194},[3752],{"type":29,"value":3753},"    operation.",{"type":23,"tag":102,"props":3755,"children":3756},{"style":109},[3757],{"type":29,"value":3758},"invoke",{"type":23,"tag":102,"props":3760,"children":3761},{"style":194},[3762],{"type":29,"value":3763},"(node)\n",{"type":23,"tag":102,"props":3765,"children":3766},{"class":104,"line":283},[3767],{"type":23,"tag":102,"props":3768,"children":3769},{"style":211},[3770],{"type":29,"value":3771},"    // Traverse left\n",{"type":23,"tag":102,"props":3773,"children":3774},{"class":104,"line":301},[3775,3780],{"type":23,"tag":102,"props":3776,"children":3777},{"style":109},[3778],{"type":29,"value":3779},"    preOrderTraversal",{"type":23,"tag":102,"props":3781,"children":3782},{"style":194},[3783],{"type":29,"value":3784},"(node.left,operation);\n",{"type":23,"tag":102,"props":3786,"children":3787},{"class":104,"line":309},[3788],{"type":23,"tag":102,"props":3789,"children":3790},{"style":211},[3791],{"type":29,"value":3792},"    // Traverse right\n",{"type":23,"tag":102,"props":3794,"children":3795},{"class":104,"line":323},[3796,3800],{"type":23,"tag":102,"props":3797,"children":3798},{"style":109},[3799],{"type":29,"value":3779},{"type":23,"tag":102,"props":3801,"children":3802},{"style":194},[3803],{"type":29,"value":3804},"(node.right,operation);\n",{"type":23,"tag":102,"props":3806,"children":3807},{"class":104,"line":332},[3808],{"type":23,"tag":102,"props":3809,"children":3810},{"style":194},[3811],{"type":29,"value":1430},{"type":23,"tag":32,"props":3813,"children":3814},{},[3815],{"type":23,"tag":50,"props":3816,"children":3817},{},[3818],{"type":29,"value":3819},"InOrder traversal",{"type":23,"tag":91,"props":3821,"children":3823},{"className":1286,"code":3822,"language":1204,"meta":7,"style":7},"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",[3824],{"type":23,"tag":98,"props":3825,"children":3826},{"__ignoreMap":7},[3827,3851,3875,3906,3913,3925,3932,3947,3954,3965],{"type":23,"tag":102,"props":3828,"children":3829},{"class":104,"line":105},[3830,3834,3839,3843,3847],{"type":23,"tag":102,"props":3831,"children":3832},{"style":188},[3833],{"type":29,"value":1518},{"type":23,"tag":102,"props":3835,"children":3836},{"style":109},[3837],{"type":29,"value":3838}," inOrderTraversal",{"type":23,"tag":102,"props":3840,"children":3841},{"style":194},[3842],{"type":29,"value":3668},{"type":23,"tag":102,"props":3844,"children":3845},{"style":109},[3846],{"type":29,"value":3585},{"type":23,"tag":102,"props":3848,"children":3849},{"style":194},[3850],{"type":29,"value":3677},{"type":23,"tag":102,"props":3852,"children":3853},{"class":104,"line":132},[3854,3859,3863,3867,3871],{"type":23,"tag":102,"props":3855,"children":3856},{"style":194},[3857],{"type":29,"value":3858},"                     operation: (",{"type":23,"tag":102,"props":3860,"children":3861},{"style":109},[3862],{"type":29,"value":3585},{"type":23,"tag":102,"props":3864,"children":3865},{"style":194},[3866],{"type":29,"value":3694},{"type":23,"tag":102,"props":3868,"children":3869},{"style":109},[3870],{"type":29,"value":3699},{"type":23,"tag":102,"props":3872,"children":3873},{"style":194},[3874],{"type":29,"value":1414},{"type":23,"tag":102,"props":3876,"children":3877},{"class":104,"line":146},[3878,3882,3886,3890,3894,3898,3902],{"type":23,"tag":102,"props":3879,"children":3880},{"style":188},[3881],{"type":29,"value":1552},{"type":23,"tag":102,"props":3883,"children":3884},{"style":194},[3885],{"type":29,"value":3715},{"type":23,"tag":102,"props":3887,"children":3888},{"style":188},[3889],{"type":29,"value":2589},{"type":23,"tag":102,"props":3891,"children":3892},{"style":115},[3893],{"type":29,"value":1373},{"type":23,"tag":102,"props":3895,"children":3896},{"style":194},[3897],{"type":29,"value":3286},{"type":23,"tag":102,"props":3899,"children":3900},{"style":188},[3901],{"type":29,"value":3732},{"type":23,"tag":102,"props":3903,"children":3904},{"style":194},[3905],{"type":29,"value":3737},{"type":23,"tag":102,"props":3907,"children":3908},{"class":104,"line":217},[3909],{"type":23,"tag":102,"props":3910,"children":3911},{"style":211},[3912],{"type":29,"value":3771},{"type":23,"tag":102,"props":3914,"children":3915},{"class":104,"line":256},[3916,3921],{"type":23,"tag":102,"props":3917,"children":3918},{"style":109},[3919],{"type":29,"value":3920},"    inOrderTraversal",{"type":23,"tag":102,"props":3922,"children":3923},{"style":194},[3924],{"type":29,"value":3784},{"type":23,"tag":102,"props":3926,"children":3927},{"class":104,"line":283},[3928],{"type":23,"tag":102,"props":3929,"children":3930},{"style":211},[3931],{"type":29,"value":3745},{"type":23,"tag":102,"props":3933,"children":3934},{"class":104,"line":301},[3935,3939,3943],{"type":23,"tag":102,"props":3936,"children":3937},{"style":194},[3938],{"type":29,"value":3753},{"type":23,"tag":102,"props":3940,"children":3941},{"style":109},[3942],{"type":29,"value":3758},{"type":23,"tag":102,"props":3944,"children":3945},{"style":194},[3946],{"type":29,"value":3763},{"type":23,"tag":102,"props":3948,"children":3949},{"class":104,"line":309},[3950],{"type":23,"tag":102,"props":3951,"children":3952},{"style":211},[3953],{"type":29,"value":3792},{"type":23,"tag":102,"props":3955,"children":3956},{"class":104,"line":323},[3957,3961],{"type":23,"tag":102,"props":3958,"children":3959},{"style":109},[3960],{"type":29,"value":3920},{"type":23,"tag":102,"props":3962,"children":3963},{"style":194},[3964],{"type":29,"value":3804},{"type":23,"tag":102,"props":3966,"children":3967},{"class":104,"line":332},[3968],{"type":23,"tag":102,"props":3969,"children":3970},{"style":194},[3971],{"type":29,"value":1430},{"type":23,"tag":32,"props":3973,"children":3974},{},[3975],{"type":23,"tag":50,"props":3976,"children":3977},{},[3978],{"type":29,"value":3979},"PostOrder traversal",{"type":23,"tag":91,"props":3981,"children":3983},{"className":1286,"code":3982,"language":1204,"meta":7,"style":7},"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",[3984],{"type":23,"tag":98,"props":3985,"children":3986},{"__ignoreMap":7},[3987,4011,4035,4066,4073,4086,4093,4105,4112,4127],{"type":23,"tag":102,"props":3988,"children":3989},{"class":104,"line":105},[3990,3994,3999,4003,4007],{"type":23,"tag":102,"props":3991,"children":3992},{"style":188},[3993],{"type":29,"value":1518},{"type":23,"tag":102,"props":3995,"children":3996},{"style":109},[3997],{"type":29,"value":3998}," postOrderTraversal",{"type":23,"tag":102,"props":4000,"children":4001},{"style":194},[4002],{"type":29,"value":3668},{"type":23,"tag":102,"props":4004,"children":4005},{"style":109},[4006],{"type":29,"value":3585},{"type":23,"tag":102,"props":4008,"children":4009},{"style":194},[4010],{"type":29,"value":3677},{"type":23,"tag":102,"props":4012,"children":4013},{"class":104,"line":132},[4014,4019,4023,4027,4031],{"type":23,"tag":102,"props":4015,"children":4016},{"style":194},[4017],{"type":29,"value":4018},"                       operation: (",{"type":23,"tag":102,"props":4020,"children":4021},{"style":109},[4022],{"type":29,"value":3585},{"type":23,"tag":102,"props":4024,"children":4025},{"style":194},[4026],{"type":29,"value":3694},{"type":23,"tag":102,"props":4028,"children":4029},{"style":109},[4030],{"type":29,"value":3699},{"type":23,"tag":102,"props":4032,"children":4033},{"style":194},[4034],{"type":29,"value":1414},{"type":23,"tag":102,"props":4036,"children":4037},{"class":104,"line":146},[4038,4042,4046,4050,4054,4058,4062],{"type":23,"tag":102,"props":4039,"children":4040},{"style":188},[4041],{"type":29,"value":1552},{"type":23,"tag":102,"props":4043,"children":4044},{"style":194},[4045],{"type":29,"value":3715},{"type":23,"tag":102,"props":4047,"children":4048},{"style":188},[4049],{"type":29,"value":2589},{"type":23,"tag":102,"props":4051,"children":4052},{"style":115},[4053],{"type":29,"value":1373},{"type":23,"tag":102,"props":4055,"children":4056},{"style":194},[4057],{"type":29,"value":3286},{"type":23,"tag":102,"props":4059,"children":4060},{"style":188},[4061],{"type":29,"value":3732},{"type":23,"tag":102,"props":4063,"children":4064},{"style":194},[4065],{"type":29,"value":3737},{"type":23,"tag":102,"props":4067,"children":4068},{"class":104,"line":217},[4069],{"type":23,"tag":102,"props":4070,"children":4071},{"style":211},[4072],{"type":29,"value":3771},{"type":23,"tag":102,"props":4074,"children":4075},{"class":104,"line":256},[4076,4081],{"type":23,"tag":102,"props":4077,"children":4078},{"style":109},[4079],{"type":29,"value":4080},"    postOrderTraversal",{"type":23,"tag":102,"props":4082,"children":4083},{"style":194},[4084],{"type":29,"value":4085},"(node.left,operation)\n",{"type":23,"tag":102,"props":4087,"children":4088},{"class":104,"line":283},[4089],{"type":23,"tag":102,"props":4090,"children":4091},{"style":211},[4092],{"type":29,"value":3792},{"type":23,"tag":102,"props":4094,"children":4095},{"class":104,"line":301},[4096,4100],{"type":23,"tag":102,"props":4097,"children":4098},{"style":109},[4099],{"type":29,"value":4080},{"type":23,"tag":102,"props":4101,"children":4102},{"style":194},[4103],{"type":29,"value":4104},"(node.right,operation)\n",{"type":23,"tag":102,"props":4106,"children":4107},{"class":104,"line":309},[4108],{"type":23,"tag":102,"props":4109,"children":4110},{"style":211},[4111],{"type":29,"value":3745},{"type":23,"tag":102,"props":4113,"children":4114},{"class":104,"line":323},[4115,4119,4123],{"type":23,"tag":102,"props":4116,"children":4117},{"style":194},[4118],{"type":29,"value":3753},{"type":23,"tag":102,"props":4120,"children":4121},{"style":109},[4122],{"type":29,"value":3758},{"type":23,"tag":102,"props":4124,"children":4125},{"style":194},[4126],{"type":29,"value":3763},{"type":23,"tag":102,"props":4128,"children":4129},{"class":104,"line":332},[4130],{"type":23,"tag":102,"props":4131,"children":4132},{"style":194},[4133],{"type":29,"value":1430},{"type":23,"tag":24,"props":4135,"children":4137},{"id":4136},"bfs-breadth-first-search",[4138],{"type":29,"value":4139},"BFS - Breadth-First Search",{"type":23,"tag":32,"props":4141,"children":4142},{},[4143],{"type":23,"tag":61,"props":4144,"children":4146},{"alt":7,"src":4145},"https://jaimedearcos-resources.s3-eu-west-1.amazonaws.com/blog/bfs.gif",[],{"type":23,"tag":32,"props":4148,"children":4149},{},[4150],{"type":29,"value":4151},"For BFS algorithm we are going to use a queue:",{"type":23,"tag":745,"props":4153,"children":4154},{},[4155,4160],{"type":23,"tag":749,"props":4156,"children":4157},{},[4158],{"type":29,"value":4159},"Push root node to the queue",{"type":23,"tag":749,"props":4161,"children":4162},{},[4163,4165],{"type":29,"value":4164},"While queue is not empty:",{"type":23,"tag":745,"props":4166,"children":4167},{},[4168,4173,4178],{"type":23,"tag":749,"props":4169,"children":4170},{},[4171],{"type":29,"value":4172},"Poll element from queue and process data",{"type":23,"tag":749,"props":4174,"children":4175},{},[4176],{"type":29,"value":4177},"If left child exist, add to the queue",{"type":23,"tag":749,"props":4179,"children":4180},{},[4181],{"type":29,"value":4182},"If right child exist, add to the queue",{"type":23,"tag":91,"props":4184,"children":4186},{"className":1286,"code":4185,"language":1204,"meta":7,"style":7},"   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",[4187],{"type":23,"tag":98,"props":4188,"children":4189},{"__ignoreMap":7},[4190,4232,4239,4297,4314,4331,4338,4370,4396,4413,4420,4445,4462,4470,4494,4510,4517,4524],{"type":23,"tag":102,"props":4191,"children":4192},{"class":104,"line":105},[4193,4198,4203,4207,4211,4216,4220,4224,4228],{"type":23,"tag":102,"props":4194,"children":4195},{"style":188},[4196],{"type":29,"value":4197},"   fun",{"type":23,"tag":102,"props":4199,"children":4200},{"style":109},[4201],{"type":29,"value":4202}," bfs",{"type":23,"tag":102,"props":4204,"children":4205},{"style":194},[4206],{"type":29,"value":3668},{"type":23,"tag":102,"props":4208,"children":4209},{"style":109},[4210],{"type":29,"value":3585},{"type":23,"tag":102,"props":4212,"children":4213},{"style":194},[4214],{"type":29,"value":4215},", operation: (",{"type":23,"tag":102,"props":4217,"children":4218},{"style":109},[4219],{"type":29,"value":3585},{"type":23,"tag":102,"props":4221,"children":4222},{"style":194},[4223],{"type":29,"value":3694},{"type":23,"tag":102,"props":4225,"children":4226},{"style":109},[4227],{"type":29,"value":3699},{"type":23,"tag":102,"props":4229,"children":4230},{"style":194},[4231],{"type":29,"value":1414},{"type":23,"tag":102,"props":4233,"children":4234},{"class":104,"line":132},[4235],{"type":23,"tag":102,"props":4236,"children":4237},{"emptyLinePlaceholder":202},[4238],{"type":29,"value":205},{"type":23,"tag":102,"props":4240,"children":4241},{"class":104,"line":146},[4242,4246,4251,4255,4260,4265,4269,4274,4279,4284,4288,4292],{"type":23,"tag":102,"props":4243,"children":4244},{"style":188},[4245],{"type":29,"value":3552},{"type":23,"tag":102,"props":4247,"children":4248},{"style":194},[4249],{"type":29,"value":4250}," queue ",{"type":23,"tag":102,"props":4252,"children":4253},{"style":188},[4254],{"type":29,"value":228},{"type":23,"tag":102,"props":4256,"children":4257},{"style":109},[4258],{"type":29,"value":4259}," LinkedList",{"type":23,"tag":102,"props":4261,"children":4262},{"style":194},[4263],{"type":29,"value":4264},"\u003C",{"type":23,"tag":102,"props":4266,"children":4267},{"style":109},[4268],{"type":29,"value":3585},{"type":23,"tag":102,"props":4270,"children":4271},{"style":194},[4272],{"type":29,"value":4273},">() ",{"type":23,"tag":102,"props":4275,"children":4276},{"style":188},[4277],{"type":29,"value":4278},"as",{"type":23,"tag":102,"props":4280,"children":4281},{"style":194},[4282],{"type":29,"value":4283}," Queue",{"type":23,"tag":102,"props":4285,"children":4286},{"style":188},[4287],{"type":29,"value":4264},{"type":23,"tag":102,"props":4289,"children":4290},{"style":194},[4291],{"type":29,"value":3585},{"type":23,"tag":102,"props":4293,"children":4294},{"style":188},[4295],{"type":29,"value":4296},">\n",{"type":23,"tag":102,"props":4298,"children":4299},{"class":104,"line":217},[4300,4305,4310],{"type":23,"tag":102,"props":4301,"children":4302},{"style":194},[4303],{"type":29,"value":4304},"        queue.",{"type":23,"tag":102,"props":4306,"children":4307},{"style":109},[4308],{"type":29,"value":4309},"offer",{"type":23,"tag":102,"props":4311,"children":4312},{"style":194},[4313],{"type":29,"value":3763},{"type":23,"tag":102,"props":4315,"children":4316},{"class":104,"line":256},[4317,4321,4326],{"type":23,"tag":102,"props":4318,"children":4319},{"style":188},[4320],{"type":29,"value":1322},{"type":23,"tag":102,"props":4322,"children":4323},{"style":194},[4324],{"type":29,"value":4325}," current : ",{"type":23,"tag":102,"props":4327,"children":4328},{"style":109},[4329],{"type":29,"value":4330},"BinaryTreeNode\n",{"type":23,"tag":102,"props":4332,"children":4333},{"class":104,"line":283},[4334],{"type":23,"tag":102,"props":4335,"children":4336},{"emptyLinePlaceholder":202},[4337],{"type":29,"value":205},{"type":23,"tag":102,"props":4339,"children":4340},{"class":104,"line":301},[4341,4346,4350,4355,4360,4365],{"type":23,"tag":102,"props":4342,"children":4343},{"style":188},[4344],{"type":29,"value":4345},"        while",{"type":23,"tag":102,"props":4347,"children":4348},{"style":194},[4349],{"type":29,"value":343},{"type":23,"tag":102,"props":4351,"children":4352},{"style":188},[4353],{"type":29,"value":4354},"!",{"type":23,"tag":102,"props":4356,"children":4357},{"style":194},[4358],{"type":29,"value":4359},"queue.",{"type":23,"tag":102,"props":4361,"children":4362},{"style":109},[4363],{"type":29,"value":4364},"isEmpty",{"type":23,"tag":102,"props":4366,"children":4367},{"style":194},[4368],{"type":29,"value":4369},"()){\n",{"type":23,"tag":102,"props":4371,"children":4372},{"class":104,"line":309},[4373,4378,4382,4387,4392],{"type":23,"tag":102,"props":4374,"children":4375},{"style":194},[4376],{"type":29,"value":4377},"            current ",{"type":23,"tag":102,"props":4379,"children":4380},{"style":188},[4381],{"type":29,"value":228},{"type":23,"tag":102,"props":4383,"children":4384},{"style":194},[4385],{"type":29,"value":4386}," queue.",{"type":23,"tag":102,"props":4388,"children":4389},{"style":109},[4390],{"type":29,"value":4391},"poll",{"type":23,"tag":102,"props":4393,"children":4394},{"style":194},[4395],{"type":29,"value":3151},{"type":23,"tag":102,"props":4397,"children":4398},{"class":104,"line":323},[4399,4404,4408],{"type":23,"tag":102,"props":4400,"children":4401},{"style":194},[4402],{"type":29,"value":4403},"            operation.",{"type":23,"tag":102,"props":4405,"children":4406},{"style":109},[4407],{"type":29,"value":3758},{"type":23,"tag":102,"props":4409,"children":4410},{"style":194},[4411],{"type":29,"value":4412},"(current)\n",{"type":23,"tag":102,"props":4414,"children":4415},{"class":104,"line":332},[4416],{"type":23,"tag":102,"props":4417,"children":4418},{"emptyLinePlaceholder":202},[4419],{"type":29,"value":205},{"type":23,"tag":102,"props":4421,"children":4422},{"class":104,"line":355},[4423,4428,4433,4437,4441],{"type":23,"tag":102,"props":4424,"children":4425},{"style":188},[4426],{"type":29,"value":4427},"            if",{"type":23,"tag":102,"props":4429,"children":4430},{"style":194},[4431],{"type":29,"value":4432}," (current.left ",{"type":23,"tag":102,"props":4434,"children":4435},{"style":188},[4436],{"type":29,"value":1584},{"type":23,"tag":102,"props":4438,"children":4439},{"style":115},[4440],{"type":29,"value":1373},{"type":23,"tag":102,"props":4442,"children":4443},{"style":194},[4444],{"type":29,"value":1414},{"type":23,"tag":102,"props":4446,"children":4447},{"class":104,"line":368},[4448,4453,4457],{"type":23,"tag":102,"props":4449,"children":4450},{"style":194},[4451],{"type":29,"value":4452},"                queue.",{"type":23,"tag":102,"props":4454,"children":4455},{"style":109},[4456],{"type":29,"value":4309},{"type":23,"tag":102,"props":4458,"children":4459},{"style":194},[4460],{"type":29,"value":4461},"(current.left)\n",{"type":23,"tag":102,"props":4463,"children":4464},{"class":104,"line":968},[4465],{"type":23,"tag":102,"props":4466,"children":4467},{"style":194},[4468],{"type":29,"value":4469},"            }\n",{"type":23,"tag":102,"props":4471,"children":4472},{"class":104,"line":988},[4473,4477,4482,4486,4490],{"type":23,"tag":102,"props":4474,"children":4475},{"style":188},[4476],{"type":29,"value":4427},{"type":23,"tag":102,"props":4478,"children":4479},{"style":194},[4480],{"type":29,"value":4481}," (current.right ",{"type":23,"tag":102,"props":4483,"children":4484},{"style":188},[4485],{"type":29,"value":1584},{"type":23,"tag":102,"props":4487,"children":4488},{"style":115},[4489],{"type":29,"value":1373},{"type":23,"tag":102,"props":4491,"children":4492},{"style":194},[4493],{"type":29,"value":1414},{"type":23,"tag":102,"props":4495,"children":4496},{"class":104,"line":996},[4497,4501,4505],{"type":23,"tag":102,"props":4498,"children":4499},{"style":194},[4500],{"type":29,"value":4452},{"type":23,"tag":102,"props":4502,"children":4503},{"style":109},[4504],{"type":29,"value":4309},{"type":23,"tag":102,"props":4506,"children":4507},{"style":194},[4508],{"type":29,"value":4509},"(current.right)\n",{"type":23,"tag":102,"props":4511,"children":4512},{"class":104,"line":1014},[4513],{"type":23,"tag":102,"props":4514,"children":4515},{"style":194},[4516],{"type":29,"value":4469},{"type":23,"tag":102,"props":4518,"children":4519},{"class":104,"line":1023},[4520],{"type":23,"tag":102,"props":4521,"children":4522},{"style":194},[4523],{"type":29,"value":3201},{"type":23,"tag":102,"props":4525,"children":4526},{"class":104,"line":1045},[4527],{"type":23,"tag":102,"props":4528,"children":4529},{"style":194},[4530],{"type":29,"value":1826},{"type":23,"tag":32,"props":4532,"children":4533},{},[4534,4536],{"type":29,"value":4535},"You can find the complete code of this example in this ",{"type":23,"tag":38,"props":4537,"children":4539},{"href":4538,"target":41},"https://github.com/JaimeDeArcos/kotlin-algorithms/tree/main/trees/src/main/kotlin/es/jaimedearcos/algorithms/tree",[4540],{"type":29,"value":4541},"GitHub repository",{"type":23,"tag":1175,"props":4543,"children":4544},{},[4545],{"type":29,"value":1179},{"title":7,"searchDepth":132,"depth":132,"links":4547},[4548,4549,4552],{"id":3350,"depth":132,"text":3353},{"id":3421,"depth":132,"text":3424,"children":4550},[4551],{"id":3496,"depth":146,"text":3499},{"id":4136,"depth":132,"text":4139},"content:posts:algorithms-working-with-trees.md","posts/algorithms-working-with-trees.md","posts/algorithms-working-with-trees",[4557,4561,4565,4569,4573,4577,4581,4585,4589,4593,4597,4601,4605,4609,4613,4617,4621,4622,4623,4627,4628],{"_path":4558,"title":4559,"date":4560},"/posts/gpt-sql-integration","Implementa un analizador de consultas en lenguaje natural para bases de datos SQL con GPT","2025-01-15T11:00:00.000Z",{"_path":4562,"title":4563,"date":4564},"/posts/java-security-best-practices","Java Security Best Practices: Preventing Vulnerabilities and Threats","2024-08-15T11:00:00.000Z",{"_path":4566,"title":4567,"date":4568},"/posts/circuit-breaking-resilience","Circuit Breaking in Distributed Systems","2024-07-15T11:00:00.000Z",{"_path":4570,"title":4571,"date":4572},"/posts/maven-and-github-actions","Automating Java Builds with Maven and GitHub Actions CI/CD","2024-06-15T11:00:00.000Z",{"_path":4574,"title":4575,"date":4576},"/posts/pattern-matching-sealed-classes-java21","A Guide to Pattern Matching and Sealed Classes in Java 21","2024-05-15T11:00:00.000Z",{"_path":4578,"title":4579,"date":4580},"/posts/async-java-completable-vs-reactive","Asynchronous Programming in Java: CompletableFuture vs Reactive Streams","2024-04-15T11:00:00.000Z",{"_path":4582,"title":4583,"date":4584},"/posts/mastering-concurrency","Mastering Concurrency in Java: Threads, Executors, and Virtual Threads","2024-03-15T11:00:00.000Z",{"_path":4586,"title":4587,"date":4588},"/posts/microservices-mistakes","Common Mistakes When Developing Microservices","2024-02-15T11:00:00.000Z",{"_path":4590,"title":4591,"date":4592},"/posts/tdd-testing","Test-Driven Development (TDD) in Java with JUnit and Mockito","2024-01-15T11:00:00.000Z",{"_path":4594,"title":4595,"date":4596},"/posts/single-table-design","Single Table Design","2023-12-27T11:00:00.000Z",{"_path":4598,"title":4599,"date":4600},"/posts/java-17","Exploring Java 17's New Features","2023-10-08T11:00:00.000Z",{"_path":4602,"title":4603,"date":4604},"/posts/hexagonal-architecture","Introduction to Hexagonal Architecture","2023-10-02 18:00:00",{"_path":4606,"title":4607,"date":4608},"/posts/terraform","Unleashing the Power of Infrastructure as Code (IaC)","2023-09-24 18:00:00",{"_path":4610,"title":4611,"date":4612},"/posts/python-virtual-environments","Python Virtual Environments (venv)","2023-09-17 22:00:00",{"_path":4614,"title":4615,"date":4616},"/posts/api-first-principles","API First principles","2023-09-01 22:15:18",{"_path":4618,"title":4619,"date":4620},"/posts/how-to-configure-ssh-key-based-authentication","How To Configure SSH Key-Based Authentication","2021-02-21 03:46:12",{"_path":1199,"title":1200,"date":10},{"_path":4,"title":8,"date":10},{"_path":4624,"title":4625,"date":4626},"/posts/manage-aws-infrastructure-with-terraform","Bootstrap complete Java application infrastructure in AWS with Terraform","2020-12-02T11:00:00.000Z",{"_path":3341,"title":3342,"date":3344},{"_path":4629,"title":4630,"date":4631},"/posts/playing-with-ocr-libraries","Playing with OCR libraries","2020-11-22T11:00:00.000Z",1790510066437]