Join Raghavendra Dixit for an in-depth discussion in this video Finding an item in a binary search tree, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Let's look at how to search…for an item in a binary search tree.…So let's say this is how the data is laid out…in our binary tree data structure,…and we would like to find the integer 52 in this tree.…And, remember, we always start from the root,…because as you already saw here, the tree has…a reference to the root node only, okay.…And if you find the data in the tree,…we will just return the node object itself;…otherwise, we'll return a null.…So how can we do this?…Well, we start at the root of the tree and compare the data…in this node to the data we are searching for;…and if it is equal, we just return the root node.…
So in this case, as you can see,…52 is the root node; so we just return that.…Now, let's say we would like to find 39 in this tree.…So, again, we start at the root and compare it…to the data we are searching for.…Here, 52 is greater than 39; so we can be sure…that the node 39, if it exists in the tree,…will be on the left side of the root node…because all children smaller than this node…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.