Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Balanced Binary Search Trees - Algorithms and Applications in Java - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Algorithms and Applications in Java which includes Greedy Method, Divide and Conquer, Dynamic Programming, Backtracking, Branch and Bound, Integer Programming, Neural Networks, Genetic Algorithms, Tabu Search etc.Key important points are: Balanced Binary Search Trees, Number of Elements, Adelson-Velsky and Landis Trees, Red-Black Trees, Indexed Operations, Balanced Search Trees, Balance Factor, Height of Right Subtree

Typology: Slides

2012/2013

Uploaded on 03/27/2013

agarkar
agarkar 🇮🇳

4.3

(26)

380 documents

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Balanced Binary Search Trees
height is O(log n), where n is the
number of elements in the tree
AVL (Adelson-Velsky and Landis)
trees
red-black trees
get, put, and remove take O(log n)
time
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download Balanced Binary Search Trees - Algorithms and Applications in Java - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Balanced Binary Search Trees

• height is O(log n), where n is the

number of elements in the tree

• AVL (Adelson-Velsky and Landis)

trees

• red-black trees

• get, put, and remove take O(log n)

time

Balanced Binary Search Trees

• Indexed AVL trees

• Indexed red-black trees

• Indexed operations also take

O(log n) time

AVL Tree

• binary tree

• for every node x, define its balance factor

balance factor of x = height of left subtree of x

- height of right subtree of x

• balance factor of every node x is -1, 0, or 1

Balance Factors

This is an AVL tree.

AVL Search Tree

put(9)

0

0

put(29)

RR rotation.

AVL Rotations

• RR

• LL

• RL

• LR

Example Red Black Tree

Red Black Trees

Colored Edges Definition

• Binary search tree.

• Child pointers are colored red or black.

• Pointer to an external node is black.

• No root to external node path has two

consecutive red pointers.

• Every root to external node path has the

same number of black pointers.

Red Black Tree

• The height of a red black tree that has n

(internal) nodes is between log

(n+1) and

2log

(n+1).

• java.util.TreeMap => red black tree

Graphs

• G = (V,E)

• V is the vertex set.

• Vertices are also called nodes and points.

• E is the edge set.

• Each edge connects two different vertices.

• Edges are also called arcs and lines.

• Directed edge has an orientation (u,v).

u v

Undirected Graph

Directed Graph (Digraph)