mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:24:05 -06:00
36 lines
1.4 KiB
Markdown
36 lines
1.4 KiB
Markdown
---
|
|
title: "tree"
|
|
tags:
|
|
- cosc201
|
|
---
|
|
|
|
not so much a data type. More of a data concept of a way in which data can be organised
|
|
|
|
The first example we saw was with the chains of representatives in [union-find](notes/union-find.md)
|
|
|
|
The type required for the ordered [set](notes/set.md) data type is the binary tree
|
|
|
|
Trees in general:
|
|
- Consists of *Nodes*
|
|
- One node is distinguished and called the *root*
|
|
- Each node, except the root, has a unique *parent*
|
|
- Any chain that moves from a mnode to its parent , its grandparent etc, eventually reaches the root.
|
|
- The *children* of a nore arll the nodes of which it is the parent
|
|
- Nodes may (and usually do) have additional data associated to them. (does not affect the structure)
|
|
- Nodes with no children are *leaves*
|
|
|
|
For example:
|
|
|
|
- *cat* is the root (root is drawn at the top)
|
|
- the parent of *dog* is cat*,* of *rat* is *emu*
|
|
- some nodes have two children, one has three (*emu* ) and some have none.
|
|
|
|

|
|
|
|
The only differnce between these two trees is the *order* of the elements.
|
|
|
|
We need to specify whether this makes them different or not. In computer science, order usually *does* mater. These are sometimes called*plane trees*.
|
|
|
|
Sometimes there are fixed slots for the children e.g.,
|
|
|
|
[binary-search-tree](notes/binary-search-tree.md) |