Binary Search Tree (Part 2 The AVL-tree)

Similar documents
CS : Data Structures

5 AVL trees: deletion

CSS 343 Data Structures, Algorithms, and Discrete Math II. Balanced Search Trees. Yusuf Pisan

Indirect Measurement

Punctured Binary Turbo-Codes with Optimized Performance

Lecture-3 Amplitude Modulation: Single Side Band (SSB) Modulation

CSE 100: RED-BLACK TREES

Unit 5 Waveguides P a g e 1

RBT Operations. The basic algorithm for inserting a node into an RBT is:

Directional Derivative, Gradient and Level Set

Trigonometric Functions of any Angle

ON TWO-PLANE BALANCING OF SYMMETRIC ROTORS

Topic 23 Red Black Trees

11.2 Areas of Trapezoids and Kites

5.3 Sum and Difference Identities

Image Feature Extraction and Recognition of Abstractionism and Realism Style of Indonesian Paintings

Center for Academic Excellence. Area and Perimeter

and 6.855J. Network Simplex Animations

MITOCW 6. AVL Trees, AVL Sort

CAPACITY OF MULTIPLE ACCESS CHANNELS WITH CORRELATED JAMMING

IMAGE ILLUMINATION (4F 2 OR 4F 2 +1?)

ON THE IMPACT OF RESIDUAL CFO IN UL MU-MIMO

Copyright 2005, Favour Education Centre. Mathematics Exercises for Brilliancy Book 3. Applications of trigonometry.

Spectrum Sharing with Multi-hop Relaying

This study concerns the use of machine learning based

On the relation between radiated and conducted RF emission tests

Research on harmonic analysis and Simulation of grid connected synchronous motor Jian Huang1,a, Bingyang Luo2,b

I ve downloaded the app, now where do I tap?

Francesc Casanellas C. Sant Ramon, Aiguafreda - Spain NATURAL PERSPECTIVE

DYNAMIC BEAM FORMING USING CHIRP SIGNALS

mywbut.com Two agent games : alpha beta pruning

Genetic Algorithm for Wireless Sensor Network With Localization Based Techniques

Optimal DG Placement and Sizing in Distribution System for Loss and THD Reduction

Balanced Trees. Balanced Trees Tree. 2-3 Tree. 2 Node. Binary search trees are not guaranteed to be balanced given random inserts and deletes

Multi-Round Sensor Deployment for Guaranteed Barrier Coverage

Manipulating map objects

Loading transformers with non sinusoidal currents

OPTI-502 Optical Design and Instrumentation I John E. Greivenkamp Homework Set 5 Fall, 2018

Grade 10 Mathematics: Question Paper 2

An Efficient Handoff Scheme Using a Minimum Residual Time First Scheme

ELEC 546 Lecture #9. Orthogonal Frequency Division Multiplexing (OFDM): Basic OFDM System

h = v h 2 = height of the object is negative for inverted image and positive for erect image. is always positive. Direction of incident light

Multi-Objectivity for Brain-Behavior Evolution of a Physically-Embodied Organism

Image Reconstruction Based On Bayer And Implementation On FPGA Sun Chen 1, a, Duan Xiaofeng 2, b and Wu Qijing 3, c

Energy Savings with an Energy Star Compliant Harmonic Mitigating Transformer

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 17: Heaps and Priority Queues

Chapter 5 Analytic Trigonometry

A new melting layer detection algorithm that combines polarimetric radar-based detection with thermodynamic output from numerical models

Splay tree concept Splaying operation: double-rotations Splay insertion Splay search Splay deletion Running time of splay tree operations

A Guide for the Assessment and Mitigation of Bleed, Gloss Change, and Mold in Inkjet Prints During High-humidity Conditions

ANALYSIS OF HARMONIC DISTORTION LEVELS ON A DISTRIBUTION NETWORK

School of Electrical and Computer Engineering, Cornell University. ECE 303: Electromagnetic Fields and Waves. Fall 2007

Cooperative Request-answer Schemes for Mobile Receivers in OFDM Systems

A REVIEW OF THE NEW AUSTRALIAN HARMONICS STANDARD AS/NZS

Multi-Objectivity for Brain-Behavior Evolution of a Physically-Embodied Organism

Biased Support Vector Machine for Relevance Feedback in Image Retrieval

Skip Lists S 3 S 2 S 1. 2/6/2016 7:04 AM Skip Lists 1

Abstract 1. INTRODUCTION

Branch and bound methods based tone injection schemes for PAPR reduction of DCO-OFDM visible light communications

Development of Outdoor Service Robots

Evaluation Model of Microblog Information Confidence Based on BP Neural Network

The deterministic EPQ with partial backordering: A new approach

PRIORITY QUEUES AND HEAPS. Lecture 19 CS2110 Spring 2014

PRIORITY QUEUES AND HEAPS

MIMO-based Jamming Resilient Communication in Wireless Networks

Application of two-stage ADALINE for estimation of synchrophasor

sketch a simplified small-signal equivalent circuit of a differential amplifier

Installation Instructions

Closed-Form Optimality Characterization of Network-Assisted Device-to-Device Communications

The Haptic Scissors: Cutting in Virtual Environments

Modelling Capture Behaviour in IEEE Radio Modems

This is a repository copy of PWM Harmonic Signature Based Islanding Detection for a Single-Phase Inverter with PWM Frequency Hopping.

Contour Measuring System CONTRACER CV-1000/2000

Random Binary Search Trees. EECS 214, Fall 2017

Grid Filter Design for a Multi-Megawatt Medium-Voltage Voltage Source Inverter

SOLUTIONS TO PROBLEM SET 5. Section 9.1

CS188 Spring 2014 Section 3: Games

Machine Vision System for Automatic Weeding Strategy in Oil Palm Plantation using Image Filtering Technique

1 Permutations. Example 1. Lecture #2 Sept 26, Chris Piech CS 109 Combinatorics

Methodology To Analyze Driver Decision Environment During Signal Change Intervals: Application of Fuzzy Set Theory

Complex-valued restricted Boltzmann machine for direct learning of frequency spectra

Problems on Differential and OP-AMP circuits

Performance Analysis for LTE Wireless Communication

The investment casting process can produce

Calculation of Antenna Pattern Influence on Radiated Emission Measurement Uncertainty

Wireless Information and Energy Transfer in Multi-Antenna Interference Channel

Aalborg Universitet. Published in: IET Power Electronics. DOI (link to publication from Publisher): /iet-pel Publication date: 2018

Estimation of Dielectric Constant for Various Standard Materials using Microstrip Ring Resonator

An Experimental Downlink Multiuser MIMO System with Distributed and Coherently-Coordinated Transmit Antennas

Modelling and Control of Gene Regulatory Networks for Perturbation Mitigation

On the Sum Capacity of Multiaccess Block-Fading Channels with Individual Side Information

Research on Three-level Rectifier Neutral-Point Voltage Balance. Control in Traction Power Supply System of High. Speed Train

Recommendation ITU-R F (02/2014)

CSE 100: BST AVERAGE CASE AND HUFFMAN CODES

Channel Estimation Filter Using Sinc-Interpolation for UTRA FDD Downlink

Power Quality Issues, Problems and Related Standards Avinash Panwar1,ASSISTANT PROFESSOR, MADHAV UNIVERSITY ABU ROAD INDIA

Contour Measuring System CONTRACER CV-1000/2000

Lecture 14 Instruction Selection: Tree-pattern matching

Architecture for filtering images using Xilinx System Generator

Lecture 18: Mobile Radio Propagation: Large Scale Prop. Modeling. Mobile Radio Propagation: Large Scale Propagation Modeling

Transcription:

Yufei Tao ITEE University of Queensland

We ave already learned a static version of te BST. In tis lecture, we will make te structure dynamic, namely, allowing it to support updates (i.e., insertions and deletions). Te dynamic version we will learn is called te AVL-tree.

Recall: Binary Searc Tree (BST) A BST on a set S of n integers is a binary tree T satisfying all te following requirements: T as n nodes. Eac node u in T stores a distinct integer in S, wic is called te key of u. For every internal u, it olds tat: Te key of u is larger tan all te keys in te left subtree of u. Te key of u is smaller tan all te keys in te rigt subtree of u.

Recall: Balanced Binary Tree A binary tree T is balanced if te following olds on every internal node u of T : Te eigt of te left subtree of u differs from tat of te rigt subtree of u by at most 1. If u violates te above requirement, we say tat u is imbalanced.

AVL-Tree An AVL-tree on a set S of n integers is a balanced binary searc tree T were te following olds on every internal node u u stores te eigts of its left and rigt subtrees.

Example An AVL-tree on S = {, 10,, 20, 0,, 60, 7, 80} 2 7 2 2 1 1 10 0 60 80 1 0 1 0 20 For example, te numbers and 2 near node indicate tat its left subtree as eigt, and its rigt subtree as eigt 2. By storing te subtree eigts, an internal node knows weter it as become imbalanced. Te left subtree eigt of an internal node can be obtained in O(1) time from its left cild (ow?). Similarly for te rigt.

Next, we will explain ow to perform updates. Te most crucial step is to remedy a node u wen it becomes imbalanced. It suffices to consider a scenario called 2-level imbalance. In tis situation, two conditions apply: Tere is a difference of 2 in te eigts of te left and rigt subtrees of u. All te proper descendants of u are balanced. Before delving into te insertion and deletion algoritms, we will first explain ow to rebalance u in te above situation.

2-Level Imbalance Tere are two cases: + 2 + 2 Due to symmetry, it suffices to explain only te left case, wic can be furter divided into a left-left and a left-rigt case, as sown next.

2-Level Imbalance + 1 or + 1 + 1 Left-left Left-Rigt

Rebalancing Left-Left By a rotation: a + 2 + 1 b x + 1 + 1 b x C A x a + 1 A B B C Only pointers to cange (te red ones). Te cost is O(1). Recall x = or + 1.

Rebalancing Left-Rigt By a double rotation: + 2 a + 2 a + 1 c + 1 b + 1 b + 1 c x y D b x y a + 1 A A B C D B C Only 5 pointers to cange (see above). Hence, te cost is O(1). Note tat x and y must be or 1. Furtermore, at least one of tem must be (wy?).

We are now to explain te insertion algoritm

Insertion Suppose tat we need to insert a new integer e. First create a new leaf z storing te key e. Tis can be done by descending a root-to-leaf pat: 1 Set u te root of T 2 If u is a leaf node: 2.1 If te key of u > e, make z te left cild of u, and done. 2.2 Oterwise, make z te rigt cild of u, and done. Oterwise (i.e., u is an internal node): 2.1 If te key of u > e, set u to te left cild. 2.2 Oterwise, set u to te rigt cild. 4 Repeat from Line 2. Finally, update te subtree eigt values on te nodes of te root-to-z pat in te bottom-up order. Te total cost is proportional to te eigt of T, i.e., O(log n).

Example Inserting 5: 7 2 2 10 0 60 80 1 1 20 5 Te red eigt values are modified by tis insertion.

Example An insertion may cause te tree to become imbalanced! 7 7 10 0 60 80 10 0 60 80 20 5 20 5 1 6 In te left tree, nodes 10 and become imbalanced, wereas in te rigt, node is now imbalanced.

Imbalance in an Insertion... Only te nodes along te pat from te insertion pat (from te root to te newly added leaf) can become imbalanced. It suffices remedy only te lowest imbalanced node.

Left-Left Example a + 2 + 1 b x + 1 b + 1 x C A x a + 1 A B B C 7 7 10 2 0 0 60 80 0 1 1 60 80 20 1 0 5 1 10 20 5 1

Left-Rigt Example a + 2 a + 2 + 1 c + 1 b + 1 b + 1 c x y D b x y a + 1 A A B C D B C 4 2 0 2 7 2 1 2 2 10 0 1 2 60 80 10 20 5 7 20 5 6 60 80 6

Insertion Time... It will be left as an exercise for you to prove: Only 2-level imbalance can occur in an insertion. Once we ave remedied te lowest imbalanced node, all te nodes in te tree will become balanced again. Te total insertion time is terefore O(log n).

We now proceed to explain te deletion algoritm.

Deletion Suppose tat we want to delete an integer e. First, find te node u wose key equals e in O(log n) time (troug a predecessor query). Case 1: If u is a leaf node, simply remove it from (te AVL-tree) T. Case 1 Example Remove 60: 0 10 20 5 7 6 60

Deletion Now suppose tat node u (containing te integer e to be deleted) is not a leaf node. We proceed as follows: Case 2: If u as a rigt subtree: Find te node v storing te successor s of e. Set te key of u to s Case 2.1: If v is a leaf node, ten remove it from T. Case 2.2: Oterwise, it must old tat v as a rigt cild w, wic is a leaf (wy?), but not left cild. Set te key of v to tat of w, and remove w from T. Case : If u as no rigt subtree: It must old tat u as a left cild v, wic is a leaf. (wy?) Set te key of u to tat of v, and remove v from T.

Case 2.1 Example Delete : 0 0 60 10 20 5 7 10 20 5 7 6 60 6

Case 2.2 Example Delete 0: 0 5 10 20 5 7 10 20 6 7 6 60 60

Case Example 0 0 10 20 5 7 10 20 5 60 6 60 6

Deletion... In all te above cases, we ave essentially descended a root-to-leaf pat (call it te deletion pat), and removed a leaf node. We can now update te subtree eigt values for te nodes on tis pat in te bottom-up order. Te cost so far is O(log n). Recall tat te successor of an integer can be found in O(log n) time.

Imbalance in a Deletion... Only te nodes along te deletion pat may become imbalanced. We fix eac of tem in te bottom-up order in exactly te same way as described for insertions, namely, using eiter a rotation or double rotation. Unlike an insertion, we may need to remedy more tan one imbalanced node.

Left-Left Example 1 Delete 0: 0 5 10 20 5 10 20 Node 5 becomes imbalanced a left-left case andle by a rotation: 5 10 20 10 5 20

Left-Left Example 2 Delete 0: 0 5 10 20 5 10 20 25 25 Node 5 becomes imbalanced also a left-left case andle by a rotation: 5 10 5 10 20 20 25 25

Left-Rigt Example Delete : 0 0 7 10 20 5 7 10 20 5 17 25 6 17 25 6 27 27 Node 7 becomes imbalanced a left-rigt case andled by a double rotation. See te next slide.

Left-Rigt Example 0 0 7 6 10 20 5 10 20 5 7 17 25 6 17 25 27 27 Node 0 is still imbalanced a left-rigt case andled by a double rotation. See next.

Left-Rigt Example 0 20 6 0 10 20 5 7 10 17 25 6 17 25 27 5 7 27 Final tree after te deletion. Note tat tis deletion required fixing 2 imbalanced nodes.

Deletion Time... It will be left as an exercise for you to prove tat Only 2-level imbalance can occur in an insertion. Since we spend O(1) time fixing eac imbalanced nodes, te total deletion time is O(log n).

We now conclude our discussion on te AVL-tree, wic provides te following guarantees: O(n) space consumption. O(log n) time per predecessor query (ence, also per dictionary lookup). O(log n) time per insertion O(log n) time per deletion. All te above complexities old in te worst case.