# Study sets matching "binary trees"

Study sets

Classes

Users

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…

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)

Test a Binary Tree

Heap

Removal of item in Heap

Insert in a Heap

use In order traversal... after several deletions and insertions…

is a complete Binary Tree... it's root holds the Minimum element…

Remove Root node... replace Root with LIH(last in heap)... while(LIH…

Insert into last space in heap or bottom... while (Node > parent…

Test a Binary Tree

use In order traversal... after several deletions and insertions…

Heap

is a complete Binary Tree... it's root holds the Minimum element…

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

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;... }

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…

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…

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…

Pre-order traversal?

In-order traversal ?

Post-order traversal

What is a node?

This is when the parent is processed before the children ... ABC…

This is when the left child is processed first, then the paren…

This is when the children are processed first before the paren…

A node is an item within a binary tree ... In a binary tree each…

Pre-order traversal?

This is when the parent is processed before the children ... ABC…

In-order traversal ?

This is when the left child is processed first, then the paren…

Tree

Binary Tree and it's major operations

preorder

postorder

empty, or it has a node called the root, followed by zero or m…

preorder, inorder, postorder, level-order, height, and Size (n…

left child, root, right child

children, then root

Tree

empty, or it has a node called the root, followed by zero or m…

Binary Tree and it's major operations

preorder, inorder, postorder, level-order, height, and Size (n…

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

What is the time complexity of binary s…

why is inserting an item's time complex…

why is finding an item's time complexit…

What are the benefits of binary trees?

O(LogN)

- We may need to move N-1 items, if item is inserted at index…

We can use binary search O(logN) and make use of the indexing…

Combines dynamic link and binary searches for finding elements.

What is the time complexity of binary s…

O(LogN)

why is inserting an item's time complex…

- We may need to move N-1 items, if item is inserted at index…

What kind of search is swift built-in f…

What's the performance of binary search?

What's the downside of binary search?

What is the key property of binary sear…

In Swift, .indexOf() is linear search.

O(logn)

The array needs to be sorted.

Sorted. Left child always smaller than right child.

What kind of search is swift built-in f…

In Swift, .indexOf() is linear search.

What's the performance of binary search?

O(logn)

B. binary search tree

A. length

B. depth

C. height

A __________ (with no duplicate elements) has the property tha…

The ________ of a path is the number of the edges in the path.

The _______ of a node is the length of the path from the root…

The _______ of a nonempty tree is the length of the path from…

B. binary search tree

A __________ (with no duplicate elements) has the property tha…

A. length

The ________ of a path is the number of the edges in the path.

BST

Searching in a BST

Add algorithm

Implementing BSTs using Links

Binary tree with an ordering property of its elements such tha…

Data is stored in a way that it can be more efficiently found…

Follow algorithm for searching until there is no child and ins…

LinkedBinarySearchTree... Constructors: use super()... addElement:…

BST

Binary tree with an ordering property of its elements such tha…

Searching in a BST

Data is stored in a way that it can be more efficiently found…

There are n nodes in a tree. How many e…

Run time for in order tree walk

Describe in order tree walk

Run time for tree search

n-1

theta(n). Every node is traversed once.

Print left subtree, node, and right subtree

order(h), where log(n) <= h <= n

There are n nodes in a tree. How many e…

n-1

Run time for in order tree walk

theta(n). Every node is traversed once.

Tree

Nodes

edges

hierarchical structure

structure consist of nodes and edges that organize data in a h…

where the data elements are stored

connects the nodes represents the relationship between the nod…

resembles an upside down tree complete with branches leaves an…

Tree

structure consist of nodes and edges that organize data in a h…

Nodes

where the data elements are stored