Editing Tree

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 29: Line 29:
 
Tree '''traversal''' is the act of visiting every vertex of a tree. Traversing a tree produces an ordering of the tree's vertices. If a tree has <math>N</math> nodes, then there are <math>N!</math> different orderings, but two are particularly important: '''preorder''' and '''postorder'''. In a preorder traversal, we perform a [[depth-first search]] starting from the tree's root, and a node is considered to be visited as soon as it is first pushed onto the stack. A postorder traversal is similar, but now a node is considered to be visited only after all its children have been visited. (Leaf nodes are still considered visited as soon as they are pushed on the stack, as they have no children.) In some trees, an order is already imposed on the children of any given vertex; that is, a node with multiple children has a well-defined first child, second child, and so on. In these case, preorder and postorder traversals always visit a node's children in order, and are unique for a given rooted tree.
 
Tree '''traversal''' is the act of visiting every vertex of a tree. Traversing a tree produces an ordering of the tree's vertices. If a tree has <math>N</math> nodes, then there are <math>N!</math> different orderings, but two are particularly important: '''preorder''' and '''postorder'''. In a preorder traversal, we perform a [[depth-first search]] starting from the tree's root, and a node is considered to be visited as soon as it is first pushed onto the stack. A postorder traversal is similar, but now a node is considered to be visited only after all its children have been visited. (Leaf nodes are still considered visited as soon as they are pushed on the stack, as they have no children.) In some trees, an order is already imposed on the children of any given vertex; that is, a node with multiple children has a well-defined first child, second child, and so on. In these case, preorder and postorder traversals always visit a node's children in order, and are unique for a given rooted tree.
  
==Binary and ''k''-ary trees==
+
==Binary trees==
 
A '''binary tree''' is a rooted tree in which every vertex has at most two children, called ''left'' and ''right''. The subtree rooted at a node's left child is called the ''left subtree'', with ''right subtree'' defined analogously. Binary trees are of special interest because of their ability to organize data, as in [[binary search tree]]s and [[binary heap]]s.
 
A '''binary tree''' is a rooted tree in which every vertex has at most two children, called ''left'' and ''right''. The subtree rooted at a node's left child is called the ''left subtree'', with ''right subtree'' defined analogously. Binary trees are of special interest because of their ability to organize data, as in [[binary search tree]]s and [[binary heap]]s.
  
Line 43: Line 43:
  
 
A binary tree is said to be '''complete''' when levels 0 through <math>h-1</math> are completely filled, and all nodes on level <math>h</math> are as far to the left as possible. A complete binary tree will always have the minimum height possible. A binary tree is said to be '''balanced''' when all external nodes have similar height; if the heights of any two external nodes differ by at most one, it is said to be '''perfectly balanced'''. Balanced trees are useful for searching efficiently.
 
A binary tree is said to be '''complete''' when levels 0 through <math>h-1</math> are completely filled, and all nodes on level <math>h</math> are as far to the left as possible. A complete binary tree will always have the minimum height possible. A binary tree is said to be '''balanced''' when all external nodes have similar height; if the heights of any two external nodes differ by at most one, it is said to be '''perfectly balanced'''. Balanced trees are useful for searching efficiently.
 
A ''k''-ary tree is a rooted tree in which every vertex has at most <math>k</math> children. Similar terminology applies.
 
  
 
===Inorder traversal===
 
===Inorder traversal===

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)
Retrieved from "https://wcipeg.com/wiki/Tree"