Join Raghavendra Dixit for an in-depth discussion in this video Inserting an item in a binary search tree, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] We saw how to search for an item…in a binary search tree.…Now, let's see how to insert a new data item in it.…When inserting a new node, we essentially keep looking…for a place where to insert this new node…such that the binary search tree property is not violated.…That is the right child should be greater than…or equal to the current node,…and the left child should be less than the current node.…And, well, we can do the equality thing…for the right child in case duplicate values are allowed.…
So, if the data is equal to the current node,…we insert the new value as a right child.…But that may not be the immediate right child, alright?…We do the insertion recursively.…Let's see what I mean.…Let's say we have to insert 63…in the binary search tree shown here.…We start at the root and compare the two values.…So in this case, 63 is greater than 52.…So we know that it must be inserted somewhere…in the right subtree.…
So we move to the right child of this root node.…Again, we compare the two values.…Since 63 is smaller than 65,…
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.