Unlike linked list and array which can only be traversed linearly, there are several ways to traverse a binary tree. The tree traversal algorithms are mainly divided into two parts, depth first and breadth first. As their name suggests, in depth first, the tree is traversed downwards (towards the depth) before the next sibling is visited, the PreOrder, InOrder and PostOrder traversal of a binary tree are actually depth-first traversals. On the breadth first, the entire breadth of the tree is traversed before moving to next level, hence it is also known as level order traversal. There are other algorithms to traverse a binary tree as well e.g. Monte Carlo tree search, which concentrates on analyzing the most promising moves, but the pre-order, post-order, and in-order traversal are the most popular ways to traverse a binary tree in Java. They are also the most popular data structure and algorithm questions at beginner and intermediate level.
Read more »
Anda baru saja membaca artikel yang berkategori binary tree |
data structure and algorithm
dengan judul Binary Tree PreOrder Traversal in Java - Recursion and Iteration Example. Jika kamu suka, janganlike dan bagikan keteman-temanmu ya... By : En Kolay Yolu
Ditulis oleh:
Adsız -


Belum ada komentar untuk "Binary Tree PreOrder Traversal in Java - Recursion and Iteration Example"
Yorum Gönder