CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Similar documents
CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

COMP108 Algorithmic Foundations

1 Introduction to Modulo 7 Arithmetic

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

CS 461, Lecture 17. Today s Outline. Example Run

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Planar Upward Drawings

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

Present state Next state Q + M N

SOLVED EXAMPLES. be the foci of an ellipse with eccentricity e. For any point P on the ellipse, prove that. tan

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

The Plan. Honey, I Shrunk the Data. Why Compress. Data Compression Concepts. Braille Example. Braille. x y xˆ

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

CSI35 Chapter 11 Review

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

12. Traffic engineering

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Garnir Polynomial and their Properties

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Minimum Spanning Trees

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

QUESTIONS BEGIN HERE!

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions.

Binomials and Pascal s Triangle

UNCORRECTED SAMPLE PAGES 4-1. Naming fractions KEY IDEAS. 1 Each shape represents ONE whole. a i ii. b i ii

Aquauno Video 6 Plus Page 1

Numbering Boundary Nodes

Chem 104A, Fall 2016, Midterm 1 Key

MA1506 Tutorial 2 Solutions. Question 1. (1a) 1 ) y x. e x. 1 exp (in general, Integrating factor is. ye dx. So ) (1b) e e. e c.

Multipoint Alternate Marking method for passive and hybrid performance monitoring

CS 241 Analysis of Algorithms

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

Constructive Geometric Constraint Solving

Section 3: Antiderivatives of Formulas

Seven-Segment Display Driver

Polygons POLYGONS.

Jonathan Turner Exam 2-10/28/03

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

a b c cat CAT A B C Aa Bb Cc cat cat Lesson 1 (Part 1) Verbal lesson: Capital Letters Make The Same Sound Lesson 1 (Part 1) continued...

CS September 2018

Instructions for Section 1

Problem solving by search

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Construction 11: Book I, Proposition 42

Outline. Binary Tree

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

SAMPLE PAGES. Primary. Primary Maths Basics Series THE SUBTRACTION BOOK. A progression of subtraction skills. written by Jillian Cockings

Trees as operads. Lecture A formalism of trees

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

Last time: introduced our first computational model the DFA.

Chapter 16. 1) is a particular point on the graph of the function. 1. y, where x y 1

TOPIC 5: INTEGRATION

RAM Model. I/O Model. Real Machine Example: Nehalem : Algorithms in the Real World 4/9/13

A prefix word in each of these sentences is incorrect. Rewrite the prefix words correctly.

Multi-Section Coupled Line Couplers

XML and Databases. Outline. Recall: Top-Down Evaluation of Simple Paths. Recall: Top-Down Evaluation of Simple Paths. Sebastian Maneth NICTA and UNSW

Formal Concept Analysis

N1.1 Homework Answers

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Section 10.4 Connectivity (up to paths and isomorphism, not including)

Module 2 Motion Instructions

Decimals DECIMALS.

MSLC Math 151 WI09 Exam 2 Review Solutions

CS553 Lecture Register Allocation I 3

Lecture 11 Waves in Periodic Potentials Today: Questions you should be able to address after today s lecture:

Ch 1.2: Solutions of Some Differential Equations

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

Case Study VI Answers PHA 5127 Fall 2006

Designing A Concrete Arch Bridge

Graph Contraction and Connectivity

QUESTIONS BEGIN HERE!

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

EE1000 Project 4 Digital Volt Meter

Homework #3. 1 x. dx. It therefore follows that a sum of the

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

Transcription:

rmup CSE 7: AVL trs rmup: ht is n invrint? Mihl L Friy, Jn 9, 0 ht r th AVL tr invrints, xtly? Disuss with your nighor. AVL Trs: Invrints Intrlu: Exploring th ln invrint Cor i: xtr invrint to BSTs tht nfor ln. AVL Tr Invrints An AVL tr hs th following invrints: Th strutur invrint: All nos hv 0,, or hilrn. Th BST invrint: For ll nos, ll kys in th lft sutr r smllr; ll kys in th right sutr r lrgr Th ln invrint: For ll nos, s (hight (lft)) hight (hight (right)). Qustion: why s (hight (lft)) hight (hight (right))? hy not hight (lft) = hight (right)? ht hppns if w insrt two lmnts. ht hppns? AVL = Alson-Vlsky n Lnis AVL tr invrints rviw AVL tr invrints rviw Qustion: is this vli AVL tr? Qustion: is this lso n AVL tr? 7 0 5 9 7 5 0 9 5

AVL tr invrints rviw Implmnting n AVL itionry Qustion:...n wht out now? How o w implmnt n AVL itionry? gt: Sm s BST! ontinsky: Sm s BST! 7 5 put:??? rmov:??? - 5 9 7 A si xmpl AVL rottion Suppos w insrt,, n. ht hppns? insrt() insrt() insrt() ht o w o now? Hint: thr s only on possil solution. An lgorithm for insrt / put, in piturs: Originl tr Insrt Rott lft (Bln) (Unln!) (Bln!) Rott. 9 0 Prti Prti Prti: insrt, n fix th tr: 5 0 9 7 0 Stp : insrt 5 0 9 7 0

Prti Stp : Strt from th insrt no n mov k up to th root. Fin th first unln sutr. 5 Prti Stp : Rott lft or right to fix. (Hr, w rott right). 5 9 0 9 0 7 7 0 0 A son s... Th two AVL ss Th lin s Now, try this. Insrt,, thn. ht s th issu? insrt n insrt rott lft Th kink s Tr is still unln! 5 Hnling th kink s Lt s try gin A son ttmpt... Insight: Hnling th kink s is hr. Cn w somhow onvrt th kink s into th lin s? insrt,, (unln!) oul-rott: onvrt to lin oul-rott: fix tr Solution: s, us two rottions! 7

Th kink s: rottion Th kink s: rottion Initil tr (Unln) Fix th innr sutr: Aftr fixing th sutr Fix th outr sutr: 9 0 Prti Prti Try insrting,,,, into n AVL tr. rott lft on insrt insrt insrt insrt insrt Prti In summry... oul rottion on, prt oul rottion on, prt In summry... Implmnting AVL oprtions gt: Sm s BST! ontinsky: Sm s BST! put: Do BST insrt, mov up tr, prform singl or oul rottions to ln tr rmov: Eithr lzy-lt or us similr mtho to insrt

A not on implmnttion Anlyzing Arrylist somtims n to rott lft, rott right, oul-rott lft, or oul-rott right. Do w n to implmnt mthos? No: n ru runny y hving n rry of hilrn inst of using lft or right fils. This lts us rfr to hilrn y inx so w only hv to writ two mthos: rott, n oul-rott. An now, for ompltly unrlt topi... (E.g. w n hv rott pt two ints: th inx to th iggr sutr, n th inx to th smllr sutr) 5 Anlyzing ArryList Anlyzing ArryList Exris: mol th worst-s runtim of ArryList s mtho in trms of n, th numr of itms insi th list: puli voi (T itm) { if (rry is full) { rsiz n opy } this.rry[this.siz] = itm; this.siz += ; } whn th rry is not full Answr: T (n) = n + whn th rry is full Qustion: wht s th runtim on vrg? Cor i: ost of rsizing is mortiz ovr th susqunt lls Mtphors: hn you py rnt, tht lrg ost is mortiz ovr th following month hn you uy n xpnsiv mhin, tht lrg ost is mortiz n pys itslf k ovr th nxt svrl yrs So, in th ORST possil s, wht s th runtim? Θ (n). 7 Anlyzing ArryList s whn th rry is not full Our rurrn: T (n) = n + whn th rry is full Snrio: Lt s suppos th rry initilly hs siz k. Lt s lso suppos th rry initilly is t pity. How muh work o w n to o to rsiz on thn fill k up to pity? (k + ) + (k ) = k + k. Not: sin rry ws full, n = k in first rsiz ht is th vrg mount of work on? k + k = + k 9 Anlyzing ArryList s vritions Now, wht if inst of rsizing y ouling, wht if w inrs th pity y 00 h tim? Assuming w r full, how muh work o w o in totl to rsiz on thn fill k up to pity? (k + ) + 99 = k + 00 ht is th vrg mount of work on? k + 00 = k 00 00 + ht is k? k is th vlu of n h tim w rsiz. If w plot this, w ll gt stp-wis funtion tht grows linrly! So, woul in Θ (n). 0

Anlyzing ArryList s vritions Amortiz nlysis This is ll mortiz nlysis. Th thniqu w isuss: Now, wht if inst of rsizing y ouling, w tripl? Assuming w r full, how muh work o w o in totl to rsiz on thn fill k up to pity? (k + ) + (k ) = k + k ht is th vrg mount of work on? k + k = k + So, woul in Θ (). Aggrgt nlysis: Show sris of n oprtions hs n uppr-oun of T (n). Th vrg ost is thn T (n) n. Othr ommon thniqus (not ovr in this lss): Th ounting mtho: Assign h oprtion n mortiz ost, whih my iffr from tul ost. If mortiz ost > tul ost, inur rit. Crit is ltr us to py for oprtions whr mortiz ost < tul ost. Th potntil mtho: Th t strutur hs potntil nrgy, iffrnt oprtions ltr tht nrgy. Hoory, physis mtphors?