# Study sets matching "binary trees"

Study sets

Diagrams

Classes

Users

What is The definition of a Binary Tree…

What is the first property of a binary…

What is the second property of a binary…

What is the 3rd property of a binary tr…

In a Binary tree a node cannot have more than 2 Child nodes.

Whatever level you're on, The maximum number of nodes possible…

Given the height of a tree you can work out the maximum number…

What is The definition of a Binary Tree…

In a Binary tree a node cannot have more than 2 Child nodes.

What is the first property of a binary…

Whatever level you're on, The maximum number of nodes possible…

Definition of Tree

Binary Search Tree

Binary Search Tree - Traversal

Binary Heap

* empty or ... * a node with:... * A key, and ... * A list of child t…

* Binary Search - good for search but not for insertion/remova…

* DFS - Time Complexity - O(n)... * In-Order... * L - N - R... * Pre…

* Parent is less than both left and right child... * Its a comple…

Definition of Tree

* empty or ... * a node with:... * A key, and ... * A list of child t…

Binary Search Tree

* Binary Search - good for search but not for insertion/remova…

Formal definition: Tree

Can a tree be empty?

Define: Leafs, Siblings, Grandparents,…

Define: Depth, height, path, length.

Collection of N nodes, one of which is the... root, and N − 1 edg…

Yes

Leafs: ... Nodes with no children... Siblings:... Nodes with the same…

Depth:... A node's 'depth' is the number of edges on the path fro…

Formal definition: Tree

Collection of N nodes, one of which is the... root, and N − 1 edg…

Can a tree be empty?

Yes

Binary Tree

Root

3 types of traversals

Preorder Traversal

A tree where each node can have two child nodes; a left and ri…

The top node; also the node with no parent

Pre-order, in-order, post-order

Visit the root then left subtree then right subtree

Binary Tree

A tree where each node can have two child nodes; a left and ri…

Root

The top node; also the node with no parent

Level order traversal:

Preorder traversal:

Inorder traversal:

Postorder traversal:

Level by level, left to right.

1. visit parent, 2. visit left child, 3. visit right child.

1. visit left child, 2. visit parent, 3. visit right child.

1. visit left child, 2. visit right child, 3. visit parent.

Level order traversal:

Level by level, left to right.

Preorder traversal:

1. visit parent, 2. visit left child, 3. visit right child.

A binary search tree is a binary tree w…

For each node in a binary search tree:

"Comparable" object belongs to a class…

We use the class Comparable's method __…

Comparable

The data in a node is greater than the data in the node's left…

Comparable

compareTo... *The basis for this comparison varies from class to…

A binary search tree is a binary tree w…

Comparable

For each node in a binary search tree:

The data in a node is greater than the data in the node's left…

Full Binary Tree

Complete Binary Tree

Perfect Binary Tree

Balanced Binary Tree

A Binary Tree is full if every node has 0 or 2 children. Follo…

A Binary Tree is complete Binary Tree if all levels are comple…

A Binary tree is Perfect Binary Tree in which all internal nod…

A binary tree is balanced if height of the tree is O(Log n) wh…

Full Binary Tree

A Binary Tree is full if every node has 0 or 2 children. Follo…

Complete Binary Tree

A Binary Tree is complete Binary Tree if all levels are comple…

degenerate

balanced

complete

rooted

only one child. linked list data structure behavior

mostly two children. every node needs balance (left & right su…

always two children; full row filled left to right

root node and at most two children

degenerate

only one child. linked list data structure behavior

balanced

mostly two children. every node needs balance (left & right su…

Advantages of Trees:

Nodes

Edges

Root

1. Quick insertion and deletion... 2. Quick search

Where we store a typical piece of data

The lines connecting nodes

The node at the top of the tree

Advantages of Trees:

1. Quick insertion and deletion... 2. Quick search

Nodes

Where we store a typical piece of data

Tree

Binary tree

Implementing a linked list:

Implementing a binary tree:

Data type that consists of Nodes and edges... Can be empty or no…

A tree with at most two children per node. ... left child and ri…

Data fields in Node:... T value... Link to the next node... Data field…

Min data fields of a node:... T value... Link to left child... Link to…

Tree

Data type that consists of Nodes and edges... Can be empty or no…

Binary tree

A tree with at most two children per node. ... left child and ri…

Parent

Child

Leaf

Root

A node that has a direct connection to a descending node(s)

A node that has a direct connection to an ascending node(s)

A node whose children are empty

A node that is not a child of any other node.

Parent

A node that has a direct connection to a descending node(s)

Child

A node that has a direct connection to an ascending node(s)

LT and RT

Struct of Binary tree node

Height of a binary tree

Copy tree

Subtree names

Template <class elemType>... {... elemType info;... Struct binaryTreeNo…

Count the nodes from the root to the lowest child

Shallow Copy of binary tree

LT and RT

Subtree names

Struct of Binary tree node

Template <class elemType>... {... elemType info;... Struct binaryTreeNo…

What is the depth/height of a binary tr…

Binary tree structure

Depth formula

Add to binary tree

Leaf node to parent node

Smaller on the left... Bigger on the right

Log2(n+1)

O(logN)

What is the depth/height of a binary tr…

Leaf node to parent node

Binary tree structure

Smaller on the left... Bigger on the right

pre order, in order, post order, level…

löschen eine knotens:

Blatt?

halblatt?

pre order: W-L-R... in order: L-W-R... post order: L-R-W... level order…

2 Kinder:... Suchen des nächst größten elements des "unter baumes…

keine nachfolger

nur ein nachfolger

pre order, in order, post order, level…

pre order: W-L-R... in order: L-W-R... post order: L-R-W... level order…

löschen eine knotens:

2 Kinder:... Suchen des nächst größten elements des "unter baumes…

What is a binary tree

what is the advantage of storing data i…

What is a recursive data structure

What is... LVR... VLR... LRV

A data structure where each parent has at most two children an…

It speeds up sorting and searching

One which contains within itself, a simpler version of itself…

in order traversal... pre order ""... post order ""

What is a binary tree

A data structure where each parent has at most two children an…

what is the advantage of storing data i…

It speeds up sorting and searching

<=, >

leafs, root

1

node

For a node, n, a BST has all descendants in the left subtree (…

New nodes are inserted into a BST as __ of the tree. Insertion…

A BST is balanced if no two subtrees from a given node differ…

To delete a node with 0 children, just delete the __ from the…

<=, >

For a node, n, a BST has all descendants in the left subtree (…

leafs, root

New nodes are inserted into a BST as __ of the tree. Insertion…

Tree ADT

Nodes

Edges

Root

Nonlinear abstract data type that stores elements in a hierarc…

Elements in the tree

Connections between nodes

Distinguished element that is the origin of the tree... -only ONE…

Tree ADT

Nonlinear abstract data type that stores elements in a hierarc…

Nodes

Elements in the tree

depth

height

degree

complete

The number of movements from the root to a given node, n, is t…

The __ of a tree is the depth of the farthest node.

The number of children of a node, n, is the __ of n.

A __ binary tree has every level fully filled, except for (per…

depth

The number of movements from the root to a given node, n, is t…

height

The __ of a tree is the depth of the farthest node.

Run time of Binary Search Trees

Binary Search vs Linear Search

How are trees useful?

Trees

Average run time of most operations is O(log N).

Binary search...... Requires that data items should be in ascendi…

--used to implement the file system of several popular operati…

A data structure! ... --a tree is a collection of nodes. Unless e…

Run time of Binary Search Trees

Average run time of most operations is O(log N).

Binary Search vs Linear Search

Binary search...... Requires that data items should be in ascendi…

Height of a Binary Tree

Depth of a Binary Tree node k

Search path for a node d

Node is an ancestor and descendant of i…

Height of the Binary tree is the Maximum Depth of the Binary t…

Number of nodes in the path from root to node 'k' (NOT INCLUDI…

Search path for a node d includes all nodes from root to d.

Yes

Height of a Binary Tree

Height of the Binary tree is the Maximum Depth of the Binary t…

Depth of a Binary Tree node k

Number of nodes in the path from root to node 'k' (NOT INCLUDI…

True or False: A node in a binary tree…

True or False: A binary tree node is ge…

Which of the following sequences would…

Which of the following sequences would…

False

True

A, B, D, E, C, F, G

D, E, B, F, G, C, A

True or False: A node in a binary tree…

False

True or False: A binary tree node is ge…

True

Binary Tree

Binary Tree Node

Binary Tree Node Struct

Parent

Set of nodes connected by pointers. Each node has two pointers…

Contains data field, pointer to left child and pointer to righ…

Write the struct for a Binary Tree Node.

Root has no parent. If the root has a children, that node's pa…

Binary Tree

Set of nodes connected by pointers. Each node has two pointers…

Binary Tree Node

Contains data field, pointer to left child and pointer to righ…

A binary tree

The root

A tree node

A traversal

is a linked structure in which each node refers to two other n…

is the top node of a tree. A leaf node is a node that has no c…

object stores a data value and left/right references to other…

is an examination of all elements in a binary tree. Traversals…

A binary tree

is a linked structure in which each node refers to two other n…

The root

is the top node of a tree. A leaf node is a node that has no c…