Join Raghavendra Dixit for an in-depth discussion in this video Tree traversal: Pre order, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Another way of traversing a binary tree…is to traverse it pre-order,…in which case, we first visit the root node.…Then we traverse the left sub tree, recursively,…in the pre-order way.…And then the right sub tree is traversed recursively,…the pre-order way.…So if a tree had only three nodes,…we would go to the root first,…so let's print 52.…Then traverse the left sub tree.…But because it's a single node, we just print the value,…which is 33.…
And then go to the right sub tree,…which again is just a single node, so we print 65.…What about this example?…We first visit the root.…So let's print the data in the root node.…Then recursively traverse the left sub tree.…And finally traverse the right sub tree.…So when we get to the left sub tree,…we first visit the root because, remember,…whatever order we are traversing the main tree in,…the same order needs to be applied for the sub trees also.…
Alright.…So let's print 33.…Then, in the left sub tree, within the left sub tree,…which we also traverse pre-order, so we print 25.…
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?
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.