progweek4 Flashcards
A tree can be defined as :
a non-linear
data structure, in which the
information is ordered hierarchically
and interconnected.
It consists of a collection of nodes
(vertices) (storing the value(s))
connected by edges (connections)
Path:
a group of sequential edges; let p and c be two nodes such
that there is an edge from p to c. Then we say that p is a parent of
c and that c is one of the children of p.
Root:
the only node with no parent.
Leaf:
a node with no children.
Height (of a node):
number of edges between the root and the
farthest leaf. The height of a tree is the length of the longest path to
a leaf.
Depth:
the number of edges from a node to the root.
a tree we see daily:
Unix file system
we focus on: _ trees.
binary
Why are binary trees (BTs) so important?
- Efficient searching and sorting:
BTs allow for fast searching, insertions and deletion of items.
- Hierarchical data representation:
they are used to represent structures were hierarchical order is crucial. For example in file systems, HTML, etc.
3.Elegant algorithm design:
many algorithms are based or use BTs as part of their implementation.
Why and when are trees useful?
Computer Science:
Often used to give a hierarchical structure to data, e.g., file systems,
Modelling:
Hierarchical clustering of data (Statistics! Machine Learning!)
Linguistics:
To represent the syntactic structure of sentences in a language
full BT:
Every node has either
0 or two children.
perfect BT
All the nodes have
two children, and leafs
are at the same level.
complete BT
All the levels (expect
the last one) should
be full.
Degenerate BT
Every node has only one
child, either in the left or
right.
balanced BT
Heights of the left subtree
and right subtree defer by
zero or, at most, one.
In a binary search tree (BST), all the
elements from the nodes are ordered following a specific order.
The left node must be _ than
its parent node, and the value in the
right node must be _ than the
parent node.
smaller
greater
Some key operations on BSTs are:
Searching.
Insertion.
Deletion.
Traversal.
The idea of Object Oriented Programming is
that data is what should
guide software development and that the language should support data
abstraction.