<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>binary tree search Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/binary-tree-search/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/binary-tree-search/</link>
	<description></description>
	<lastBuildDate>Sat, 02 May 2026 23:55:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>binary tree search Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/binary-tree-search/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Search in a Binary Search Tree (BST) &#8211; Step by Step Explanation with Examples</title>
		<link>https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/</link>
					<comments>https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 02 May 2026 23:54:59 +0000</pubDate>
				<category><![CDATA[Binary Search Trees]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[binary search tree tutorial]]></category>
		<category><![CDATA[binary tree search]]></category>
		<category><![CDATA[BST explained]]></category>
		<category><![CDATA[BST search]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[data structures and algorithms]]></category>
		<category><![CDATA[log n time]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[search in BST]]></category>
		<category><![CDATA[tree traversal]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=336</guid>

					<description><![CDATA[<p>Learn how to search in a Binary Search Tree. We demonstrate searching for existing and non-existing values, explain why BST search is O(log n) on average, and show how poor data ordering can turn your tree into a slow linear structure similar to a linked list. Includes discussion of tree height and balanced vs unbalanced BSTs.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/">How to Search in a Binary Search Tree (BST) &#8211; Step by Step Explanation with Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How to Search in a Binary Search Tree (BST) - Step by Step Explanation with Examples" width="1380" height="776" src="https://www.youtube.com/embed/FCz9IbLywI4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>In this video we walk through how to perform searches in a Binary Search Tree. Starting with a perfectly balanced BST, we cover the search process step by step, including finding existing nodes like 73 and determining that numbers like 44 do not exist in the tree.</p>



<p>We discuss time complexity for searches in BSTs &#8211; O(log n) on average for balanced trees and O(n) in the worst case when the tree becomes skewed like a linked list due to sorted or bad data. Learn why each comparison eliminates half the remaining data and how height affects performance.</p>



<p>Perfect for students learning data structures and algorithms. If you&#8217;re studying BSTs, this clear explanation will help you understand searching, insertion paths, and why self-balancing trees matter.</p>



<p>Thanks for watching!</p>



<p>00:00 Introduction to BST Search<br>00:31 BST Not Self-Balancing<br>00:40 Average Case Log Time<br>00:53 Linear Time in Worst Case<br>01:13 How BST Search Works<br>01:18 Search Path Example<br>02:08 Searching for Existing Node<br>02:35 Searching for Non-Existent Node<br>03:19 Tree Size and Height<br>03:30 Time Complexity O(h)<br>05:40 Bad Data Example<br>08:23 Skewed Tree Like Linked List<br>09:53 Linear Time in Worst Case<br>11:58 Why Log Time<br>12:36 Halving the Search Space<br>14:14 O(log n) Summary<br>14:28 Conclusion</p>



<p>=-=-=-=-=-=-=-=-=</p>



<p>Thanks for watching!</p>



<p>Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>



<li>Twitter / X: https://x.com/NeuralLantern</li>



<li>Rumble: https://rumble.com/c/c-3696939</li>



<li>BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt</li>



<li>Daily Motion: https://www.dailymotion.com/neurallantern</li>



<li>Minds: https://www.minds.com/neurallantern/</li>



<li>Odysee: https://odysee.com/@NeuralLantern:5</li>
</ul>



<p>Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: https://ko-fi.com/neurallantern</li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to the Blog: https://www.NeuralLantern.com</li>



<li>Watch the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p>hey there let&#8217;s perform searches in a binary search tree</p>



<p>okay if you watch my previous videos you know how to define a binary search tree by now</p>



<p>you know some terminology you know how to construct a tree and so now let&#8217;s just take</p>



<p>a tree that&#8217;s already been constructed and let&#8217;s search through it first thing i want to say is</p>



<p>first thing I want to say is this is a binary search tree this is not a self</p>



<p>balancing tree so in the future this tree could get lopsided and messed up</p>



<p>depending on what kind of data we add we can always expect that binary search</p>



<p>trees have a search time or an insert time or removal time of log log base 2</p>



<p>of n on average assuming that the data is random or in the worst possible case</p>



<p>scenario linear time so these could get slower right now you can see this tree</p>



<p>Right now you can see this tree is perfectly balanced.</p>



<p>So if we say that our tree is currently perfectly balanced and it&#8217;s always going to be perfectly balanced,</p>



<p>which is a fantasy, but let&#8217;s just say that it is,</p>



<p>then we could just say it&#8217;s a log tree.</p>



<p>It&#8217;s going to take log time to search through.</p>



<p>So how do we perform searches?</p>



<p>Again, if you saw my previous videos, you should know that it&#8217;s really easy to find out where a node belongs.</p>



<p>Like for example, if I was going to add the number 14,</p>



<p>I would first look at the root node and I&#8217;d say, okay, the root node is occupied.</p>



<p>and I&#8217;d say, okay, the root node is occupied.</p>



<p>And so where would 14 belong?</p>



<p>Well, it would belong on the left of 37</p>



<p>because it&#8217;s less than 37.</p>



<p>It would belong on the left of 16</p>



<p>because it&#8217;s less than 16.</p>



<p>It would belong on the right of 9</p>



<p>because it&#8217;s greater than 9.</p>



<p>It would belong on the right of 11</p>



<p>because it&#8217;s greater than 11.</p>



<p>And so the 14 node that we just wanted to add,</p>



<p>is that what I just said, 14?</p>



<p>Would end up going there.</p>



<p>So when you&#8217;re searching through a binary search tree,</p>



<p>you really just have to go find</p>



<p>have to go find where the node would belong as if you&#8217;re performing insert or you could think of it</p>



<p>the other way around like insert is really thinking of a search first but basically we&#8217;re just going</p>



<p>to start by saying you know pick a number and we&#8217;ll see if it exists so uh let&#8217;s pick the number</p>



<p>67 or actually let&#8217;s pick the number 73 just to see if it exists in the tree so 73 i&#8217;m going to</p>



<p>do like you know seven three with like a question mark we check the root node 73 belongs on the</p>



<p>side we look at the 59 it belongs on the right side and we found our 73 so 73 exists in the tree</p>



<p>and it only took us three examinations only three examinations let&#8217;s look for a number that doesn&#8217;t</p>



<p>actually exist in the tree so maybe oh my thing is freezing what&#8217;s going on okay so maybe uh let&#8217;s</p>



<p>The 37 here, 44 belongs on the right of 37.</p>



<p>We look at the 59, it belongs on the left.</p>



<p>We look at the 48, it belongs on the left.</p>



<p>We look at the 43, it belongs on the right.</p>



<p>The 44 would have been there, but it&#8217;s not because that right child pointer off the 43</p>



<p>is null.</p>



<p>So we only had to really examine one, two, three, four nodes in order to determine that</p>



<p>our number 44 didn&#8217;t exist in the tree.</p>



<p>Notice how we&#8217;re not doing a lot of examinations compared to the total size of the tree.</p>



<p>compared to the total size of the tree.</p>



<p>So let me just write this up here.</p>



<p>How many nodes do we have?</p>



<p>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15.</p>



<p>We got 15 nodes up here.</p>



<p>Someone say N is equal to 15.</p>



<p>And what&#8217;s the height of the tree?</p>



<p>Remember, the height of the tree is the number of nodes you must touch</p>



<p>as you make your way down towards the deepest node.</p>



<p>Or if you&#8217;ve already found the deepest node,</p>



<p>you take its depth and you just add 1, assuming that depths start at 0.</p>



<p>start at zero. So I&#8217;ll just say that the depth of the root node is zero and the 59 and the 16 are</p>



<p>one. And then that third row is two. And that last row is three. And then I just add one to the</p>



<p>deepest node that I can find, which is just going to have a depth of three. All of these on the</p>



<p>bottom row have a depth of three. So the height of this tree is actually four, because we would</p>



<p>so like 37 59 48 43 that&#8217;s four touches um or the or the depth of the deepest node plus one okay um</p>



<p>all trees all binary search trees whether they&#8217;re actually avl trees or regular binary search trees</p>



<p>or whether they&#8217;re balanced or imbalanced they&#8217;re always going to have a time complexity to search</p>



<p>through of o of h meaning in the worst case scenario you&#8217;ll have to touch h number of nodes</p>



<p>order to find a node by search query or to add a new node or even to delete a new node.</p>



<p>So how does that compare to this tree in reality?</p>



<p>Let me just open up a little calculator real fast.</p>



<p>I just want to show you.</p>



<p>So if we do log base two, because we have a binary search tree, not a trinary search</p>



<p>nodes 15 it tells us that it should take us no more than four examinations to find the node that</p>



<p>we&#8217;re looking for if the tree was perfectly balanced and if you if you if you notice that&#8217;s</p>



<p>exactly what the height is telling us here if the tree was more imbalanced the height would get</p>



<p>really bad compared to the number of nodes and it would no longer be considered a log tree it would</p>



<p>just be you know somewhere in between linear time and log time um let&#8217;s see what else can i show you</p>



<p>let&#8217;s do well we did that computation let&#8217;s do a search through the tree that</p>



<p>through a tree that&#8217;s actually really really bad let&#8217;s pretend that we have a</p>



<p>bunch of nodes here and you know I&#8217;ve got an old story that I love to tell</p>



<p>about this when like when my grandma was alive she was kind of bitter towards the</p>



<p>end you know I loved her but she used to call the cops on her neighbors for</p>



<p>gossip and at some point in time she got into a feud with her neighbor who was</p>



<p>with her neighbor who was also a bitter old lady.</p>



<p>You know, towards the end, it kind of happens sometimes.</p>



<p>It sucks, but it happened.</p>



<p>And I guess the neighbor didn&#8217;t like my grandma&#8217;s tree</p>



<p>that she had in her backyard.</p>



<p>So they fought over it, they argued over it,</p>



<p>and then one day my grandma said</p>



<p>she was looking out the backyard window</p>



<p>to yell at ducks who were jumping into her pool</p>



<p>because she just hated when the ducks went into her pool.</p>



<p>She was waiting for them to show up.</p>



<p>She wasn&#8217;t even looking at ducks.</p>



<p>even looking at ducks she was just waiting and she saw the other little old lady reach her arm over</p>



<p>the fence and spray my grandma&#8217;s tree with some sort of poison then my grandma&#8217;s tree died and uh</p>



<p>i guess you know my grandma never never got over it i always thought it was like a funny story it</p>



<p>was a little sad but um she poisoned my grandma&#8217;s tree so we can kind of do the same thing with the</p>



<p>binary search tree we can give bad data let me show you what happens here if i use this data set</p>



<p>search tree. So we&#8217;re going to add this node right here. It&#8217;s going to be the 14.</p>



<p>And then when we add the 19 node, I&#8217;m just going to duplicate it. The 19 is supposed to be on the</p>



<p>right side of 14 because it&#8217;s greater than 14. So I&#8217;m just going to like, you know, draw a 19 right</p>



<p>here and a little connecting line. Okay. Then when we add the 24, I&#8217;m going to duplicate this node</p>



<p>the 24 go belongs on the right side of the 14 and also belongs on the right side of the 19</p>



<p>because it&#8217;s greater than 19 so again we have a node that shows up on the right side let me</p>



<p>remember to actually fix the 19 so it looks like 24. then when we add the uh 29 it&#8217;s gonna end up</p>



<p>being the same thing right the 29 is gonna end up showing on the right the right the right it&#8217;s</p>



<p>If we have bad data, we can end up with a tree that kind of looks like a straight line.</p>



<p>And if you are watching this video from the future,</p>



<p>after I&#8217;ve posted all of my data structures videos that I have,</p>



<p>you might notice that this looks like another data structure.</p>



<p>If you&#8217;re watching this right away, I haven&#8217;t posted those videos just yet.</p>



<p>But just tilt your head to the right a little bit</p>



<p>and tell me if that looks like something that you recognize.</p>



<p>It looks like a linked list.</p>



<p>looks like a linked list just like a straight line or even i guess you could kind of say maybe an array</p>



<p>um just like a straight line of data there&#8217;s no uh you know there&#8217;s no splitting of the data</p>



<p>so we have the 29 and then the 35 and then uh maybe i&#8217;ll just do one more node only and i&#8217;ll</p>



<p>get rid of that 54 because that&#8217;s too many nodes so what happens is if you have you know bad data</p>



<p>tree doesn&#8217;t actually search or add insert or remove or anything like that in log time anymore</p>



<p>instead it operates in linear time just like a linked list would meaning we would have to scan</p>



<p>through every single node in the entire tree to be sure that some value did not exist well</p>



<p>not exactly but in the worst case scenario we&#8217;d have to scan through the whole entire tree</p>



<p>for example let&#8217;s just look at the the number of nodes real fast we&#8217;ll say the</p>



<p>number of nodes here is one two three four oh I put two 24s in there oh dearie</p>



<p>let me get that says 14 19 24 29 and then I guess I got to make that a 35 oh</p>



<p>okay and then there&#8217;s a 49 I guess I did add every single node okay so we added</p>



<p>so there&#8217;s like seven uh items in the tree so i&#8217;m going to say n is equal to seven the height also</p>



<p>is seven though so the height is seven notice how if we say that it&#8217;s always true that a binary</p>



<p>search tree has a time complexity in the worst case of o of h meaning you&#8217;d have to go down</p>



<p>in the worst case the number of levels that is equal to the whole entire height of the entire</p>



<p>tree that&#8217;s also the number of nodes in the tree which means uh if i wanted to add let&#8217;s say the</p>



<p>I don&#8217;t know, if you wanted to add the number 60,</p>



<p>60 would end up going down here.</p>



<p>And in order to find where 60 would go,</p>



<p>we&#8217;d have to look at the 14, that&#8217;s 1, 19, 24.</p>



<p>We&#8217;d have to look at all these nodes.</p>



<p>That is seven nodes.</p>



<p>We&#8217;d have to examine seven nodes</p>



<p>just to figure out where the 60 would go.</p>



<p>Or if we were searching for 60,</p>



<p>then we&#8217;d have to go down that far</p>



<p>to find out that 60 didn&#8217;t exist.</p>



<p>So this is nowhere near a log tree.</p>



<p>This is a linear tree, a linear time tree.</p>



<p>year time tree and just to drive the point further if we did log base two of the number of nodes in</p>



<p>this case seven notice how it&#8217;s telling us that we should if it was a log tree if it was perfectly</p>



<p>balanced or a self-balancing tree we should have to touch no more than three nodes in order to find</p>



<p>what we&#8217;re looking for to search through the tree or to insert a new node or even to delete a node</p>



<p>but that&#8217;s not the case here because the tree is really really slow compared to a perfectly balanced</p>



<p>slow compared to a perfectly balanced tree.</p>



<p>So we call this a linear tree.</p>



<p>It sucks.</p>



<p>You want to try to avoid that.</p>



<p>You don&#8217;t want your data to be poisoned.</p>



<p>On average, your trees won&#8217;t really look like this if you just have totally</p>



<p>random data, but if you think there&#8217;s a chance that your data might be skewed</p>



<p>in some way, it&#8217;s probably a good idea to upgrade to a self-balancing tree,</p>



<p>which we&#8217;re going to talk about later.</p>



<p>Okay.</p>



<p>What else can I tell you real fast?</p>



<p>So we talked about searching.</p>



<p>why are these trees considered log time? I mean, they&#8217;re really, really fast, but why?</p>



<p>Let&#8217;s just duplicate this slide here and I&#8217;ll move it down one level. I just want to kind of</p>



<p>show you why this ends up being a log time tree. Okay. So why, why is this a log time tree?</p>



<p>Suppose for the sake of argument, we&#8217;re searching for the number 52. So if we&#8217;re searching for the</p>



<p>node the root node and decide where would the 52 belong let me actually write that down so i don&#8217;t</p>



<p>forget 52 question mark where would the 52 belong it would belong on the right side of the 37 because</p>



<p>it&#8217;s greater than 37 right which means it&#8217;s actually impossible that the 52 would be in any</p>



<p>of these other nodes on the left side there&#8217;s no need to check them we&#8217;re not going to scan the</p>



<p>whole tree we&#8217;re just going to go left or right and ignore the whole other side of the tree</p>



<p>we just did is with one examination we eliminated half of the remaining data set or i guess of the</p>



<p>initial data set if we&#8217;re looking at the root node so then the next thing that we do is we just kind</p>



<p>of say okay it belongs on the right side so we look at the 59 node and we do the same thing we</p>



<p>say where would 52 be would it be on the left side or the right side of the 59 node it would be on</p>



<p>the left side which means we&#8217;re going to eliminate from consideration the entire right subtree of the</p>



<p>So again, we&#8217;re eliminating half of the remaining data set.</p>



<p>Then we kind of go down here and we look at the 48.</p>



<p>We do the same thing.</p>



<p>52 belongs on the right side.</p>



<p>So we eliminate half of the remaining data set, you know, and then eventually we do find</p>



<p>the 52 and then that&#8217;s it.</p>



<p>So if we&#8217;re eliminating half of the data set with every single, just one examination at</p>



<p>a time, that&#8217;s why it ends up being log base two.</p>



<p>getting twice as close to your destination at every step you took if you&#8217;re like in a car like</p>



<p>running maybe you&#8217;re on the moon or something then it would be a log time you know uh progress</p>



<p>towards your goal or eliminating half of the data set at every single step sometimes people see</p>



<p>for loops on exams and stuff when we talk about this um like for i equals zero uh i is less than</p>



<p>it would be like i times equals two.</p>



<p>So i&#8217;s jumping twice as far each time.</p>



<p>That&#8217;s the sort of thing that makes it log.</p>



<p>So I&#8217;m just going to write down log here real fast</p>



<p>to drive the point home a little bit more.</p>



<p>O of log base two of n.</p>



<p>Yeah, so I guess that&#8217;s all I wanted to tell you in this video.</p>



<p>Hopefully you feel like an expert in searching now.</p>



<p>If you want to see more searching videos,</p>



<p>leave a comment or something like that.</p>



<p>leave a comment or something like that. But yeah, thank you for watching. And I hope you</p>



<p>learned a little bit of stuff and had a little bit of fun. I&#8217;ll see you in the next video.</p>



<p>I&#8217;m going to go find a blueberry muffin.</p>



<p>Hey, everybody. Thanks for watching this video again from the bottom of my heart. I really</p>



<p>appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p>subscribe and follow this channel or these videos or whatever it is you do on the current social</p>



<p>media website that you&#8217;re looking at right now it would really mean the world to me and it&#8217;ll</p>



<p>help make more videos and grow this community so we&#8217;ll be able to do more videos longer videos</p>



<p>better videos or just i&#8217;ll be able to keep making videos in general so please do do me a kindness</p>



<p>and uh and subscribe you know sometimes i&#8217;m sleeping in the middle of the night and i just</p>



<p>It just wakes me up and I get filled with joy. That&#8217;s exactly what happens every single time</p>



<p>So you could do it as a nice favor to me or you could you control me if you want to just wake me up in the middle</p>



<p>And I just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen</p>



<p>Also, if you look at the middle of the screen right now</p>



<p>You should see a QR code which you can scan in order to go to the website</p>



<p>Which I think is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where you can just kind of like</p>



<p>and the services and tutorials and things that I offer and all that good stuff and</p>



<p>if you have a suggestion for</p>



<p>Clarifications or errata or just future videos that you want to see please leave a comment or if you just want to say hey</p>



<p>What&#8217;s up? What&#8217;s going on? You know, just send me a comment, whatever</p>



<p>I also wake up for those in the middle of the night. I get I wake up in a cold sweat. I&#8217;m like this</p>



<p>It would really it really mean the world to me. I would really appreciate it. So</p>



<p>So again, thank you so much for watching this video and enjoy the cool music as I fade into the darkness, which is coming for us all.</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/">How to Search in a Binary Search Tree (BST) &#8211; Step by Step Explanation with Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
