Data Structure: Binary Tree
source link: https://dev.to/nashmeyah/data-structure-binary-tree-nga
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Data Structure: Binary Tree
Hello All!
(all the photos used are from google btw)
Its been a while, I hope you all are doing well.
In this post, I wanted to share some basic knowledge of trees in programming and data structures.
We are starting with the trees. A tree is a data structure used to simulate a hierarchical tree structure. A node of the tree has a root value and a list of references to other nodes which are referred to as child nodes.
The most typical tree structure used is the Binary tree. As the name suggests, each node of the binary tree has at most two children referred to as left child and right child.
Notice the image above to understand a visual representation of how this looks like.
Traversal Methods used in a Binary Tree
Def. of Traverse ~ travel across or through.
Pre-order Traversal
--Pre-order traversal is to visit the root first. Then traverse the left subtree. Finally, traverse the right subtree.
The red indicates that we return from the visit on the node to move to the next node, but continue to move down on all left nodes.
In-order Traversal
--In-order traversal is to traverse the left subtree first. Then visit the root. Finally, traverse the right subtree
In a binary search tree, all data is retrieved in a sorted order using in-order traversal.
Post-order Traversal
--Traverse the left subtree first. Then traverse the right subtree. Finally, visit the root.
Personally I think this one is a bit hard foe me to wrap my head around. Spend some time running the numbers back in your head and understand the map.
I hope this makes sense and simplified the Binary Tree. Next post I'd like to cover recursions using one of these traverse methods.
When you delete nodes in a tree, deletion process will be in post-order, when you delete a node, you will delete its left child and its right child before you delete the node itself.
Recommend
-
16
题目¶ 原题地址:https://leetcode.com/problems/binary-tr...
-
13
题目¶ 原题地址:https://leetcode.com/problems/binary-...
-
13
题目¶ 原题地址:https://leetcode.com/problems/binary-tree-...
-
12
DatabaseB-Tree index structure At some point we all worked with a relational database. We all had problems with query performance and we fixed them usually by first looking a...
-
10
What is a Tree data structure Before we talk BST, we have to understand that a tree is a kind of Graph with a root node and no cycles, each node can...
-
5
The Tree Structure of File Systems 2021-11-02 | 14 min read I’ve been using file system for a long time and have always thought of them as tree data structures. A couple of days ago, I ha...
-
6
Episode 485: Howard Chu on B+tree Data Structure in Depth Filed in
-
6
[Golang] BK-tree Data Structure Implementation April 06, 2017 Go im...
-
6
What is the order of a tree?The arrangement or positioning of a tree structure’s nodes and subnodes in relation to one another is referred to as the tree structure’s “order.” The preferred order of each node’s...
-
4
Crossword Puzzle Of The Week #18 (for Tree Data Structure)Skip to content
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK