# 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…

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…

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

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

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…

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)

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…

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…

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…

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

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…

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…

Pre-order traversal

In-order traversal

Post-order traversal

Advantages of linked lists

1. Start at the root node.... 2. Traverse left sub tree.... 3. Trave…

1. Traverse left sub tree.... 2. Visit root node.... 3. Traverse rig…

1. Traverse left sub tree.... 2. Traverse right sub tree.... 3. Visi…

No elements need to be shuffled around in memory.... New elements…

Pre-order traversal

1. Start at the root node.... 2. Traverse left sub tree.... 3. Trave…

In-order traversal

1. Traverse left sub tree.... 2. Visit root node.... 3. Traverse rig…

binary trees

binary search trees

binary search trees time complexity

binary tree node

a nonlinear linked data structure in which each node may point…

binary tree whose data is ordered to simplify searches... search…

worst: O(n)... average: O(log2(n))... time slows down- searching fo…

holds:... 1. the data (value field)... 2. a pointer to its left chil…

binary trees

a nonlinear linked data structure in which each node may point…

binary search trees

binary tree whose data is ordered to simplify searches... search…

Binary Tree

Internal Nodes vs. Leafs

Full Tree

Complete Tree

-Made up of Nodes... -Nodes root together to form subtrees

-Internal Nodes have node children... -Leafs have no node children

each node is internal w/ 2 children or leaf

All levels except d-1 are full

Binary Tree

-Made up of Nodes... -Nodes root together to form subtrees

Internal Nodes vs. Leafs

-Internal Nodes have node children... -Leafs have no node children

Binary Tree

Root

Left subtree

Right subtree

Finite set of nodes that is either empty and consists of a roo…

The first node in a binary tree which contains two trees linke…

A subtree on the left of its parent and has to be less than or…

A subtree that is larger than its parent tree.

Binary Tree

Finite set of nodes that is either empty and consists of a roo…

Root

The first node in a binary tree which contains two trees linke…

binary trees ?

what is a depth of a node u

what is a ancestor and descendant of a…

what is a subtree?

Rooted, acyclic graphs a connected, undirected, ﬁnite graph wi…

u, in a binary tree is the length of the path from u to the ro…

If a node, w, is on the path from u to r, then w is called an…

. The subtree of a node, u, is the binary tree that is rooted…

binary trees ?

Rooted, acyclic graphs a connected, undirected, ﬁnite graph wi…

what is a depth of a node u

u, in a binary tree is the length of the path from u to the ro…

what do trees have?

what do trees with indexer >1 and cycle…

what is the only way to get to a node?

how are edges represented in a program?

they consist of nodes connected by edges, indegree <=1, no cyc…

graphs

along an indicated path(edges) and these are downward.

by references; nodes as likely primitives or objects.

what do trees have?

they consist of nodes connected by edges, indegree <=1, no cyc…

what do trees with indexer >1 and cycle…

graphs

public class BinaryTree<E> {

BinaryTree(){

BinaryTree(E item){

BinaryTree(E item, BinaryTree<E> left,…

protected E data;... protected BinaryTree<E> left,right;

data = null;... left = right = null;... }

data = item;... left = new BinaryTree<E>();... right = new BinaryT…

data = item;... this.left = left;... this.right = right;... }

public class BinaryTree<E> {

protected E data;... protected BinaryTree<E> left,right;

BinaryTree(){

data = null;... left = right = null;... }

traversal

InOrder traversal

PostOrder traversal

PreOrder Traversal (DFS)

algorithm that iterates through each node of a binary tree exa…

a recursive algorithm that processes a tree's elements in left…

a recursive algorithm that processes elements in left-right-ro…

recursive algorithm that processes elements in a tree root-lef…

traversal

algorithm that iterates through each node of a binary tree exa…

InOrder traversal

a recursive algorithm that processes a tree's elements in left…

Depth of a Node

Height of a node

Level of a node

Height of a tree

Number of edges from the root to the node

Number of edges from the node to the deepest leaf

depth of the node + 1

height of tree = height of root

Depth of a Node

Number of edges from the root to the node

Height of a node

Number of edges from the node to the deepest leaf

class btree{... private:... type data;... btree<…

class btree{... private:... type data;... btree<…

class btree{... private:... type data;... btree<…

class btree{... private:... type data;... btree<…

//preorder VLR btree<type>::btree(const btree<type>& rhs){... dat…

//postorder LRV... btree<type>::~btree(){... if(left) delete left;... i…

//LVR void btree<type>::inorder(std::ostream& out){... if(left) l…

void btree<type>::preorder(std::ostream & out){... out << data <<…

class btree{... private:... type data;... btree<…

//preorder VLR btree<type>::btree(const btree<type>& rhs){... dat…

class btree{... private:... type data;... btree<…

//postorder LRV... btree<type>::~btree(){... if(left) delete left;... i…