Balanced Binary Trees

Similar documents
Algorithms and Data Structures

Heap Sort. Lecture 35. Robb T. Koether. Hampden-Sydney College. Mon, Apr 25, 2016

Real World Search Problems. CS 331: Artificial Intelligence Uninformed Search. Simpler Search Problems. Example: Oregon. Search Problem Formulation

Princess Nora University Faculty of Computer & Information Systems ARTIFICIAL INTELLIGENCE (CS 370D) Computer Science Department

SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY :: PUTTUR (AUTONOMOUS) Siddharth Nagar, Narayanavanam Road QUESTION BANK (DESCRIPTIVE)

Decision Trees. Nicholas Ruozzi University of Texas at Dallas. Based on the slides of Vibhav Gogate and David Sontag

G53CLP Constraint Logic Programming

Surf Life Saving Australia Circular. Proficiency Testing

Wiimote in Physical Etoys

CS 173: Discrete Structures, Spring 2010 Homework 9 Solutions

Table of Contents 1. Service Structure PIN (Personal Identification Number) Function of PIN Forget PIN

YSC-8330 USER MANUAL XI AN TYPICAL INDUSTRIES CO.,LTD.

CS472 Foundations of Artificial Intelligence. Final Exam December 19, :30pm

2465 Piston Gauge with 2456 PG Monitor, Setup in COMPASS for Pressure

Administrative Official Clinic Handouts

NCSS Statistical Software

Guide to Completing The Sheffield & District Junior Sunday League Online Player Registration Form

Uninformed Search Strategies

/435 Artificial Intelligence Fall 2015

6 th - 12 th grade. 30 minutes in class; 2 hours to make the first time

Artificial Intelligence. Uninformed Search Strategies

Design Project 2 Sizing of a Bicycle Chain Ring Bolt Set ENGR 0135 Sangyeop Lee November 16, 2016 Jordan Gittleman Noah Sargent Seth Strayer Desmond

Building an NFL performance metric

Trigonometric Functions

8.7 Extension: Laws of Sines and Cosines

Exercise 1: Control Functions

Better Search Improved Uninformed Search CIS 32

Newton s Laws of Motion

Computing the Probability of Scoring a 2 in Disc Golf Revised November 20, 2014 Steve West Disc Golf, LLC

CSE 3401: Intro to AI & LP Uninformed Search II

2017 Back to School Promotion Frequently Asked Questions

(a) (First lets try to design the set of toy s the easy way.) The easiest thing to do would be to pick integer lengths for the lengths of the sticks.

Recycle Rescue The Game

Uninformed Search (Ch )

Navigate to the golf data folder and make it your working directory. Load the data by typing

CprE 281: Digital Logic

Tension Cracks. Topics Covered. Tension crack boundaries Tension crack depth Query slice data Thrust line Sensitivity analysis.

Prestan professional Training manikin

START: Read 1 Guide for Repeated Interactive Read-Alouds

EUROPEAN BRIDGE LEAGUE. 4 t h EBL TOURNAMENT DIRECTORS COURSE 31 st August 5 th September 2001 Tabiano di Salsomaggiore Terme, Italy

DESIGNING OF THE OFFSHORE WIND FARM INSTALLATION VESSELS (on basis of the VIDAR project)

Multi Class Event Results Calculator User Guide Updated Nov Resource

APPENDIX A COMPUTATIONALLY GENERATED RANDOM DIGITS 748 APPENDIX C CHI-SQUARE RIGHT-HAND TAIL PROBABILITIES 754

Today we will focus on solving for the sides and angles of non-right triangles when given two angles and a side.

Robust Task Execution: Procedural and Model-based. Outline. Desiderata: Robust Task-level Execution

Laybotpro Automated Betfair Bot. LayBotPro User Manual

Bobbie the Safety Boat Lesson Plan 1 PFDs Canadian Coast Guard Auxiliary

CSE 3402: Intro to Artificial Intelligence Uninformed Search II

MIS0855: Data Science In-Class Exercise: Working with Pivot Tables in Tableau

QUESTIONS and ANSWERS WHY TEST KONGSBERGS

Global Physical Activity Questionnaire (GPAQ)

Mechanical Advantage 1

V393.R46. NalupwL UNITED STATES EXPERIMENTAL MODEL BASIN NAVY YARD, WASHINGTON, D.C. BILGE KEEL CAVITATION J. G. THEWS SEPTEMBER REPORT NO.

The Diver Returns Circular Functions, Vector Components, and Complex Numbers

Quadratic Probing. Hash Tables (continued) & Disjoint Sets. Quadratic Probing. Quadratic Probing Example insert(40) 40%7 = 5

3 Energy saving. I wonder... 2 Choose a situation and ask a classmate for advice. 3 Write an energy-saving poster for your home.

3. Select a colour and then use the Rectangle drawing tool to draw a rectangle like the one below.

The Stack Effect. Mat Ansari PE

Which Type of Age 5-12 Playground Style?

Problem Solving as Search - I

Introduction. AI and Searching. Simple Example. Simple Example. Now a Bit Harder. From Hammersmith to King s Cross

CENG 466 Artificial Intelligence. Lecture 4 Solving Problems by Searching (II)

TASK 4.2.1: "HAMILTON'S ROBOT" ==============================

CRHS Visual Daily Drill

1. What is the SGA Centralised Handicapping System (CHS)?

TRAP MOM FUN SHOOT 2011

CS Lecture 5. Vidroha debroy. Material adapted courtesy of Prof. Xiangnan Kong and Prof. Carolina Ruiz at Worcester Polytechnic Institute

Prestige Solo Prestige Excellence 24-32

Uninformed Search (Ch )

Search I. Tuomas Sandholm Carnegie Mellon University Computer Science Department. [Read Russell & Norvig Chapter 3]

Number & Place Value: Read, write, order and compare numbers to at least 1,000,000 and determine the value of each digit.

PHARMACOLOGY LABORATORY 2 PHARMACOKINETIC LABORATORY

Math Spring Operational Geometry PBA Item #18 Classmates in the Pool VH003506

Creating animation rigs that solve problems, are fun to use, and don t cause nervous breakdowns.

The New Mexico Lottery Continued. Lotteries II 1/26

UNIT 2 RIGHT TRIANGLE TRIGONOMETRY Lesson 2: Applying Trigonometric Ratios Instruction

Chapter 6 The Rime of the Ancient Mariner: Transcript. 1. Jenny: Okay, as you guys look at these words, what do you think of?

Water Waves in an Electric Sink

Probability of an Ace in Disc Golf by stevewestdiscgolf.com April 18, 2011

THE CHAOS THEORY ROULETTE SYSTEM

A SEMI-PRESSURE-DRIVEN APPROACH TO RELIABILITY ASSESSMENT OF WATER DISTRIBUTION NETWORKS

Spider Search: An Efficient and Non-Frontier-Based Real-Time Search Algorithm

What is fall protection?

You can still join the game after the tournament has started, but you will not score any points for past rounds which you have missed.

Using Markov Chains to Analyze a Volleyball Rally

Workshop 1: Bubbly Flow in a Rectangular Bubble Column. Multiphase Flow Modeling In ANSYS CFX Release ANSYS, Inc. WS1-1 Release 14.

Flying High. HHJS Science Week Background Information. Forces and Flight

HAPP CONTROLS OWNERS MANUAL FOR. 106 Garlisch Drive Elk Grove, IL PHONE: FAX:

Knot Maths! For most people, a knot looks like this: But a mathematician s knot looks like this:

Review questions CPSC 203 midterm 2

Unachievable Region in Precision-Recall Space and Its Effect on Empirical Evaluation

ALGE DIVE! ALGE. ALGE-TIMING GmbH & Co

Search the Sea. By Sadie Young

Unit 3 Trigonometry. 3.1 Use Trigonometry to Find Lengths

Name: 1. A car moves m/s north at a constant velocity. What is the car's displacement after 2.0 hours?

Basic Tryout Registration Set Up. Using the pre-loaded folder set up from US Soccer Connect

Provably Secure Camouflaging Strategy for IC Protection

In my left hand I hold 15 Argentine pesos. In my right, I hold 100 Chilean

A Proof-Producing CSP Solver 1

Instruction Manual: VelectriX Ascent 29 MTB

Transcription:

CSE : AVL TREES

2 Balanced Binary Trees Recall: Worst case for find in a BST is : Worst case for find in a Balanced BST is:

3 Balanced Binary Trees Deterministic Balancing Change insert and delete operations to ensure that the tree always stays balanced TODAY Randomized Balancing Use random numbers to determine the values of the nodes, independent from the keys The resulting tree will probably be balanced (e.g., more like the average case), but not guaranteed LATER

Height of a node Mark the height of each node in the tree. 4 42 67 What is the height of node with key 53? A. One B. Two C. Three D. Zero 53 9 Height of a node = Depth of a node=

Local computation of height of a node 5 Height of a node= max{ Height of left child, Height of right child} + 42 67 53 9 Goal of AVL trees: For each node, maintain the difference between height of left and right children to within +/ Each node maintains then a balance factor: Balance factor= height of the right child height of left child

Which of the following is/are balanced trees? And thus can become AVL trees by adding the balance factors 6 A 42 67 B 42 67 C 42 67 53 9 53 9 53 9 87 87 D. A&C E. A&B&C Annotate the trees with balance factors (for those that are balanced)

Finding an element in a AVL Tree is worst case O(logN)! How would you prove this (we won t, but imagine we wanted to)? A. Come up with a formula that shows that the height of the tallest AVL tree with N nodes is never bigger than c*logn + k, for some c and k (assuming large N). B. Come up with a formula that shows that the number of nodes, N, in an AVL tree is never bigger than c*logn + k for some c and k (assuming large N) C. Come up with a formula that shows that the height of the tree never grows by more than log(n) when you insert a node. D. Run some empirical tests to show that for any size tree, the time to find an element is never more than some formula c*logn + k for some c and k (assuming large N) 7

8 An AVL Tree is worst case O(logN) to find an element! (We might prove this later) How would you prove this? A. Come up with a formula that shows that the height of the tallest AVL tree with N nodes is never bigger than c*logn + k, for some c and k (assuming large N). The key to this proof is showing that the height stays small, no matter how legally unbalanced the tree is. But how does the tree stay balanced as new nodes are inserted??

9 Inserting and rebalancing 3 5 7 2 6 85 5 5 65 8 9 4 55 Insert 3

Inserting and rebalancing 3 5 7 2 6 85 5 5 65 8 9 3 Propagate news up 4 55 Insert 3

Inserting and rebalancing 3 5 7 2 6 85 5 We re OK, Keep going up 5 65 8 9 3 4 55 Insert 3

2 Inserting and rebalancing 3 Uh oh! 5 7-2 2 6 85 5 5 65 8 9 3 4 55 Insert 3

3 Rotations X y y X A B C A B C

4 Inserting and rebalancing Rotate! Left or right? cut 5 7 3-2 2 6 85 5 5 65 8 9 3 4 55 Insert 3

5 Inserting and rebalancing 3 5 7-2 2 6 85 5 lift 5 65 8 9 3 4 55 Insert 3

6 Inserting and rebalancing Adjust and reattach 5 7 3 5 2 6 85-2 3 5 65 8 9 4 55 Insert 3

7 We just did a single rotation of 5 around A.k.a. a single right rotation Done! 5 7 3 5 2 6 85 3 5 65 8 9 4 55 Insert 3

8 Single rotation practice 3 5 7 2 6 What could you insert into this AVL tree that would result in a single right rotation? A. 7 B. C. 5 D. 66

9 Single rotation practice 3 5 7 2 6 Insert 5. Draw the resulting AVL tree. (Don t peek)

2 Single rotation practice 3-2 5 7 2 6 5 After insertion

2 Single rotation practice 3 5 6 2 5 7 After rotation

22 Single rotation is not enough 3 5 7 2 6 What happens if we insert 66?

23 Single rotation is not enough 3 cut -2 5 7 2 6 66

24 Is this a valid rotation? A. Yes B. No 3-2 5 7 lift 6 2 6 66 66 7

25 Invalid rotation! 3-2 5 6 2 66 7 UH OH!

26 Double rotation to the rescue 3-2 5 7 2 6 66 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7.

27 Double rotation to the rescue -2 5 7 3 cut 2 6 66 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7.

28 Double rotation to the rescue 3-2 5 7 2 6 lift 66 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7.

29 Double rotation to the rescue 3-2 5 7 2 66 adjust 6 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7.

3 Double rotation to the rescue 3-2 5 7 2 66 reattach 6 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7.

3 Double rotation to the rescue 3 A -2 5 7 B 2 6 C 66 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7. Where in the tree above should I cut to start this rotation?

32 Double rotation to the rescue 5 3 2 6 66 7 Single rotations only work when involved nodes are in a line So we will first rotate left around 6, then we can rotate right around 7.

33 It s sometimes even more complicated 3 5 66 6 7 Insert 64 do we need a double or a single rotation? A. Double B. Single C. No rotation needed

34 Where is the tree out of balance? 3 5 66 6 7 64 A. Node 3 B. Node 66 C. Node 6 D. Node 64

35 Rotate right around 66 to make a straight line 3 5 66 6 7 64

36 Rotate right around 66 to make a straight line 3 5 66 6 7 64

37 Rotate right around 66 to make a straight line 5 3 6 66 64 7 UH OH! Where do we put 64?? Are we stuck?

38 Rotate right around 66 to make a straight line 3 5 6 66 64 7 A. No, sometimes this doesn t work B. Yes, this will always work Will 64 always reattach there?

39 Finishing the rotation to balance the tree 6 3 66 5 64 7