Join Raghavendra Dixit for an in-depth discussion in this video Unbalanced trees vs. balanced trees, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] We build a binary tree…according to the data we get, right?…So say we get some data from an array,…and we build a tree with that data…by constantly doing insert operations.…Now think about the case where…the data that we get is ordered.…That is, it is either in ascending or descending order.…Let's take the example shown here.…So we start with the first element, which is five.…Since this is the first element, it becomes the root.…
Here we have the data in ascending order,…so every time we insert an element it will become…the right-child of the previous node, isn't it?…We have five as the root element,…now the next element is seven,…and since it is bigger than five,…it'll become the right-child of five, right?…And then we have 12.…So 12 is bigger than five, and also bigger than seven,…so it will become the right-child of seven.…And each newly-created node…becomes the right-child of the previous node.…
So if you look at it as a tree, it's not balanced.…All the weight of the tree is on one side.…It is pretty much like a link list now.…
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.