Editing 835: 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 8: Line 8:
  
 
==Explanation==
 
==Explanation==
[[Cueball]] turns his family's living room Christmas tree into a cringingly-awful programming pun. His parents, [[Hairbun]] and a father-Cueball, are so unamused, he's not welcome back next year.
+
{{w|Binary tree}}s are data structures in computer science, based on two simple rules:
  
{{w|Tree (data structure)|Trees}} are data structures in computer science, based on two simple rules:
+
* A binary tree starts at a single node, called its root.
 
+
* Each node in a binary tree has two spaces for its children, each of which may be empty or occupied by another node. (Of course, that node may have its own children, and so forth.) As a bit of trivia, a node with no children is called a "leaf node."
*A tree starts at a single node, called its root.
 
*Each node in a tree has two or more spaces for its children, each of which may be empty or occupied by another node. Of course, that node may have its own children, and so forth. Each node except the root has exactly one parent. As a bit of trivia, a node with no children is called a "leaf node."
 
 
 
A binary tree is a tree where each node has spaces for exactly 2 children.
 
  
 
The "Christmas tree" is a basic representation of a binary tree - the star at the top is the root node, and the lights running down indicate the connections between parent and child. Contrary to what the terms "root" and "leaf" might imply, trees in computer science are typically represented upside-down, with the root on top and the leaves fanning out below.
 
The "Christmas tree" is a basic representation of a binary tree - the star at the top is the root node, and the lights running down indicate the connections between parent and child. Contrary to what the terms "root" and "leaf" might imply, trees in computer science are typically represented upside-down, with the root on top and the leaves fanning out below.
  
The Christmas tree is constructed based on no apparent rules, but the main power of binary trees comes in organizing them according to specific rules. Because code that runs later can assume the data is organized in this specific way, it can use different algorithms that make things run faster. One way of doing this is with a heap. A {{w|Heap (data structure)|heap}} is a special kind of tree (usually a binary tree, but in this case a quaternary tree), subject to one additional rule:
+
The Christmas tree is constructed based on no apparent rules, but the main power of binary trees comes in organizing them according to specific rules. Because code that runs later can assume the data are organized in this specific way, it can use different algorithms that make things run faster. One way of doing this is with a heap. A {{w|Heap (data structure)|heap}} is a special kind of tree, subject to one additional rule:
  
*For every node in the tree, ''everything'' beneath that node - both or all of its children, all of its children's children, all of ''their'' children, and so on - are "less than" the node itself.
+
* For every node in the tree, ''everything'' beneath that node - both of its children, all of its children's children, all of ''their'' children, and so on - are "less than" the node itself.
  
 
"Less than" in this case can refer to any comparison that can be made between two nodes - in this case, it's based on the size of the presents. Of course, there's a cost to all this; the heap must first be placed in that order. Not only that, but if a node gets removed from the heap, the heap has to be "rebuilt" to put it back in the right order. This is referenced in the title text - if Billy opens the root present, several comparisons must be done to shift other presents in its place to preserve the heap rule.
 
"Less than" in this case can refer to any comparison that can be made between two nodes - in this case, it's based on the size of the presents. Of course, there's a cost to all this; the heap must first be placed in that order. Not only that, but if a node gets removed from the heap, the heap has to be "rebuilt" to put it back in the right order. This is referenced in the title text - if Billy opens the root present, several comparisons must be done to shift other presents in its place to preserve the heap rule.
 
In [[1308: Christmas Lights]] a similar strange Christmas tree has been constructed using the electromagnetic spectrum.
 
  
 
==Transcript==
 
==Transcript==
:[There is a binary Christmas tree, with each node a ball, and lights strung between parent and child nodes. Beneath it is a heap of presents - sorted with the largest on top, smaller presents connected to it with string. Next to the tree is Cueball and his parents, Hairbun and another Cueball.]
+
:[There is a binary Christmas tree, with each node a ball, and lights strung between parent and child nodes. Beneath it is a heap of presents - sorted with the largest on top, smaller presents connected to it with string. Next to the tree is Cueball and his parents.]
 
:Cueball: It's a Christmas tree with a heap of presents underneath!
 
:Cueball: It's a Christmas tree with a heap of presents underneath!
:Mother: ...We're not inviting you home next year.
+
:Mother: ... We're not inviting you home next year.
  
 
{{comic discussion}}
 
{{comic discussion}}
 +
[[Category:Comics featuring Cueball]]
 
[[Category:Comics with color]]
 
[[Category:Comics with color]]
 
[[Category:Christmas]]
 
[[Category:Christmas]]
[[Category:Comics featuring Cueball]]
 
[[Category:Comics featuring Hairbun]]
 
[[Category:Multiple Cueballs]]
 
[[Category:Programming]]
 
[[Category:Puns]]
 

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, 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 (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)