CSE 4101/5101 Prof. Andy Mirzaian. Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees 2-3-4 Trees Red-Black.

Slides:



Advertisements
Similar presentations
Chapter 11. Hash Tables.
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
October 31, 2005Copyright © by Erik D. Demaine and Charles E. LeisersonL13.1 Introduction to Algorithms LECTURE 11 Amortized Analysis Dynamic tables.
Introduction to Algorithms
Multistage Sampling.
Using Matrices in Real Life
Advanced Piloting Cruise Plot.
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
Chapter 1 The Study of Body Function Image PowerPoint
APWeb 2004 Hangzhou, China 1 Labeling and Querying Dynamic XML Trees Jiaheng Lu and Tok Wang Ling School of Computing National University of Singapore.
October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 18 L10.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 10 Prof. Erik Demaine.
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 17 L9.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 9 Prof. Charles E. Leiserson.
©2001 by Charles E. Leiserson Introduction to AlgorithmsDay 9 L6.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 6 Prof. Erik Demaine.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
1 Outline relationship among topics secrets LP with upper bounds by Simplex method basic feasible solution (BFS) by Simplex method for bounded variables.
1 © R. Guerraoui Universal constructions R. Guerraoui Distributed Programming Laboratory.
Comp 122, Spring 2004 Order Statistics. order - 2 Lin / Devi Comp 122 Order Statistic i th order statistic: i th smallest element of a set of n elements.
David Luebke 1 6/1/2014 CS 332: Algorithms Medians and Order Statistics Structures for Dynamic Sets.
CSE 4101/5101 Prof. Andy Mirzaian Augmenting Data Structures.
Randomized Algorithms Randomized Algorithms CS648 1.
Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
Singly Linked Lists What is a singly-linked list? Why linked lists?
David Luebke 1 6/7/2014 ITCS 6114 Skip Lists Hashing.
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Data Structures Using C++
Topic 14 Searching and Simple Sorts "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The.
ABC Technology Project
The Weighted Proportional Resource Allocation Milan Vojnović Microsoft Research Joint work with Thành Nguyen Microsoft Research Asia, Beijing, April, 2011.
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Hash Table.
Briana B. Morrison Adapted from William Collins
Chapter 9 -- Simplification of Sequential Circuits.
Hash Tables.
Online Algorithm Huaping Wang Apr.21
Chapter 10: Virtual Memory
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
Review Pseudo Code Basic elements of Pseudo code
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Introduction to Machine Learning Fall 2013 Perceptron (6) Prof. Koby Crammer Department of Electrical Engineering Technion 1.
David Luebke 1 8/25/2014 CS 332: Algorithms Red-Black Trees.
Routing and Congestion Problems in General Networks Presented by Jun Zou CAS 744.
CSE 4101/5101 Prof. Andy Mirzaian B-trees trees.
© 2012 National Heart Foundation of Australia. Slide 2.
Scalable and Dynamic Quorum Systems Moni Naor & Udi Wieder The Weizmann Institute of Science.
25 seconds left…...
10 -1 Chapter 10 Amortized Analysis A sequence of operations: OP 1, OP 2, … OP m OP i : several pops (from the stack) and one push (into the stack)
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Mathematics1 Mathematics 1 Applied Informatics Štefan BEREŽNÝ.
PSSA Preparation.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Bart Jansen 1.  Problem definition  Instance: Connected graph G, positive integer k  Question: Is there a spanning tree for G with at least k leaves?
The Pumping Lemma for CFL’s
all-pairs shortest paths in undirected graphs
NON - zero sum games.
EECS 4101/5101 Prof. Andy Mirzaian. Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees Trees Red-Black.
On the Competitiveness of Self Organizing Linear Search J. Ian Munro (University of Waterloo) Competitiveness: How well does an on line algorithm do in.
Self-Organizing Lists1 Self-Organizing Lists Competitive Analysis Lee Wee Sun SoC Modified by Orgad Keller Modified again by.
Binary search trees Definition Binary search trees and dynamic set operations Balanced binary search trees –Tree rotations –Red-black trees Move to front.
Online Algorithms. Introduction An offline algorithm has a full information in advance so it can compute the optimal strategy to maximize its profit (minimize.
Binary search trees Definition
Presentation transcript:

CSE 4101/5101 Prof. Andy Mirzaian

Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees Trees Red-Black Trees SELF ADJUSTING WORST-CASE EFFICIENT competitive competitive? Linear Lists Multi-Lists Hash Tables DICTIONARIES 2

TOPICS in this slide  Linear List with Move-to-Front  Competitiveness of Move-to-Front:  Static Dictionary  Dynamic Dictionary  Expected Case 3

References: Lecture Note 2 Lecture Note 2 4

Move-to-Front 5

Introduction  s = a sequence of m dictionary operations.  We usually assume D is initially empty (except for static dictionaries, i.e., search only).  We often assume there is a linear ordering defined on keys (e.g., integers) so that we can make key comparisons.  D as a SEQUENTIAL LINEAR LIST: We need i probes to sequentially access the item at position i on list D.  SELF-ADJUSTING FEATURE: Exchange: swap the positions of a pair of adjacent items on D. Free exchange: exchanging the accessed/inserted item with its preceding item on D. Paid exchange: all other types of exchanges. Costs: 1 for each item probe 1 for each paid exchange 0 for each free exchange  DICTIONARY: Maintain a set D of items (each with a unique identifier called key) that supports the following three operations: Search (x, D):Locate item x in D (also called access) Insert (x, D):Insert item x in D (no duplicate keys) Delete (x, D):Delete item x from D 6

Some on-line heuristics  Move-to-Front (MF): After each dictionary operation perform maximum number of free exchanges (no paid exchanges). This moves the accessed/inserted item to the front of the list without affecting the relative order of the other items on the list.  Transpose (T): After each dictionary operation perform one free exchange if possible (no paid exchanges). This moves the accessed/inserted item one position closer to the front (if not at the front already), without affecting the relative order of the other items on the list.  Frequency Count (FC): Maintain a frequency count for each item, initially zero. (This requires extra space.) Increase the count of an item each time it is accessed/inserted; reduce its count to zero when deleted. Perform exchanges as necessary to maintain the list in non-increasing order of frequency counts. 7

C A E D A E D C Insert C 4 A E D Delete C 2 A C E D Search A 3 C E A D Search B 4 C E A D Insert C 3 E A C D A C D E Insert E 4 Move-to-Front Example A C D List Operation Cost 8

Move-to-Front Applications  Cash based Memory Management: - Small fast Cash versus large slower main memory. - Cash I/O page-in-page-out rules. - Least Recently Used (LRU) paging rule  Move-to-Front. [Sleator, Tarjan, “Amortized efficiency of list update and paging rules,” Communications of ACM, 28(2), pp: , 1985.]  Adaptive Data Compression: - Adaptive coding based on MF compares favorably with Hoffman coding. [Bentley, Sleator, Tarjan, Wei, “A locally adaptive data compression scheme,” Communications of ACM, 29(4), pp: , 1986.] 9

Static Dictionary 10

Static Dictionary: Search only  Decreasing Frequency (DF): This off-line strategy initially arranges the list items in non-increasing order of access frequencies, and does not perform any exchanges. We do not charge DF the cost of the initial rearrangement! Without loss of generality assume: k 1  k 2  …  k n  FACT: Among off-line strategies that perform no exchanges, DF is Optimum. t ij = position of x i during its j th access.  Initial list D 0 = [ x 1, x 2, x 3, …, x n ]. s = a sequence of m successful searches. k i = the frequency count (number of search requests in s) for item x i, i = 1..n. m = k 1 + k 2 + … + k n total number of search requests in s.  Challenging Question: What is the optimum off-line strategy with exchanges? 11

Static Dictionary: Example sequence  s 1 = A A A A B B B C C C MF (s 1 ) = = 12 < C DF (s 1 )  s 2 = C C B B B A A A A C MF (s 2 ) = = 15< C DF (s 2 )  s 3 = C B A C B A B A A C MF (s 3 ) = = 23> C DF (s 3 ) Initial list D 0 = [ A, B, C ]. s = a sequence of m=9 searches to A, B, C. k A = 4 > k B = 3 > k C = 2. C DF (s) = 1  k A + 2  k B + 3  k C = 1    2 = 16. C MF (s) = ? Depends on s. 12

Static Dictionary: MF Efficiency THEOREM 1: C MF (s)  2C DF (s) – m. Proof: s =... x i... x i... x i... x i x i... x i... x i... j th access to x i subsequence s ij (j-1) st access to x i A ij = |{ x h | h > i, x h accessed during s ij }| B ij = |{ x l | l < i, x l accessed during s ij }|  i -1 t ij = A ij + B ij + 1  A ij + i ………………………….. x i …………….. MF’s List: t ij = cost of j th access to x i continued 13

Static Dictionary: MF Efficiency THEOREM 1: C MF (s)  2C DF (s) – m. Proof Cont’d: QED 14

Accounting Interpretation Excess access cost due to x h, h > i, having jumped in front of x i. These jumps also cause inversions on MF’s list compared to DF’s fixed list. Transfer excess charge from x i to x h (back in time to) when x h was last accessed and jumped ahead of x i. So, x h gets charged its normal access cost h, and a transferred charge of at most h-1 (for lower indexed items x i, i=1..h-1, that were jumped over). Amortized access cost to x h : ĉ MF  h + (h-1) = 2h-1 = 2c DF –1. We will generalize this idea to dynamic dictionaries. An amortized interpretation of C MF (s)  2C DF (s) – m is ĉ MF  2c DF – 1, where ĉ MF = the amortized cost of a search operation by MF, c DF = the actual cost of the same operation by DF. …………x h …………….. x i …………….. MF’s List: access cost to x i h > i 15

Dynamic Dictionary 16

The Setup  s = a sequence of m search, insert, delete operations on an initially empty list.  A = an arbitrary algorithm that executes s.  F A (s) = total # of free exchanges made by A on s.  X A (s) = total # of paid exchanges made by A on s.  C - A (s) = total cost by A on s, excluding paid exchanges.  C A (s) = total cost by A on s, including paid exchanges. FACT: The following hold: 1. C A (s) = C - A (s) + X A (s). 2. F A (s)  C - A (s) – m. 3. X MF (s) = X T (s) = X FC (s) = C MF (s) = C - MF (s). 17

MF is 2-Competitive THEOREM 2: C MF (s)  2C A (s) – m, for all A and s. Proof: We will prove C MF (s)  2C - A (s) + X A (s) – F A (s) – m. ĉ MF = amortized cost charged to MF by a single operation, excluding A’s exchanges. c A = actual cost of A on the same operation, excluding A’s exchanges. CLAIM: Proof by the potential function method. Potential:  (MF, A) = Number of inversions in MF’s list with respect to A’s list. Inversion = any (not necessarily adjacent) pair of items (x,y), where x appears before y in MF’s list, but x appears after y in A’s list. Example:  ( [3,6,2,5,4,1], [1,2,3,4,5,6] ) = 10. continued 18

MF is 2-Competitive THEOREM 2: C MF (s)  2C A (s) – m, for all A and s. Proof of CLAIM Cont’d: continued Not yet accounting for exchanges made by A: Search: ĉ MF = c MF +  = k + [ p – (k-1-p) ] = 2p +1  2(i – 1)+1 = 2i – 1 = 2c A –1. Insert: The same as search with i = k = L+1 (L = length of the list before insertion.) Delete: ĉ MF = c MF +  = k + [ - (i-1-p) – (k-1-p) ] = 2(p+1) - i  i = c A  2c A –1. i k x 1 x 2 ……………… x i x i+1 ……………………………….. A’s List: ………………….……………… x i …………………...….. MF’s List: p k-1-p 19

MF is 2-Competitive THEOREM 2: C MF (s)  2C A (s) – m, for all A and s. Proof of CLAIM Cont’d: QED i k x 1 x 2 ……………… x i x i+1 ……………………………….. A’s List: ………………….……………… x i …………………...….. MF’s List: p k-1-p Accounting for exchanges made by A: Paid exchage by A:ĉ MF = c MF +   = 1. Free exchage by A: ĉ MF = c MF +  = =

Expected Case 21

Static Dictionary: Expected Case  Initial list D 0 = [ x 1, x 2, x 3, …, x n ]. Search only.  p i = search probability for item x i, i = 1..n.  p i > 0, p 1 + p 2 + … + p n = 1.  As in Decreasing Frequency (DF), assume initial list is arranged in non-increasing order of access probability: p 1  p 2  …  p n > 0.  E A = expected cost of a single search operation by algorithm A. 22

Static Dictionary: Expected Case THEOREM 3: The following hold (when p 1  p 2  …  p n > 0): Proof: (a) This follows directly from the definition of expectation. (c) This follows from (a) and (b) and using the fact that p i / (p i + p j )  1. (b) See Next page. continued 23

Static Dictionary: Expected Case QED Proof of (b): conditional probability by the linearity of expectation 24

Exercises 25

1.Consider the Move-to-Front (MF) and the Transpose (T) heuristics on linear-lists. Show a sequence s of n dictionary operations search/insert/delete that starts with the empty set, such that the ratio C T (s)/C MF (s) is asymptotically as high as possible. What is that asymptotic ratio as a function of n? 2.Show that the Transpose (T) and the Frequency Count (FC) on-line heuristics are not competitive for: (a) Static dictionaries. (b) Dynamic dictionaries. 3.Theorem 2 shows that the total cost of the Move-to-Front (MF) heuristic is at most twice the cost of the best off-line strategy (over any sequence s of m dictionary operations on an initially empty list). Show this ratio bound is tight in the worst case. That is, for any sufficiently large m, give an adversarial sequence s of m dictionary operations on an initially empty list such that if algorithm A is the optimal off-line strategy for sequence s, then the asymptotic cost ratio is C MF (s) /C A (s) = 2 - o(1) (i.e., the ratio approaches 2). 4.Theorem 2 shows that the amortized running time of the Move-to-Front (MF) heuristic on linear lists is within a constant (i.e., 2) multiplicative factor of the best off-line strategy. Does the same result hold (possibly with a somewhat larger multiplicative constant factor) for the Move-Half-Way-to-Front (MHWF) strategy? Prove your claim. (The latter strategy moves the accessed/inserted item half-way towards the front. That is, if the item was at position i, then it is moved to position  i/2 , without affecting the relative order of the other elements.) [Hint: First compare MHWF with MF, then apply transitivity.] 26

5.In the no-free-exchange model we assume that both “free” and “paid” exchanges have unit cost each. Prove that in this model the move-to-front algorithm has a competitive ratio of 4. [Hint: You'll need to adjust the potential function.] 6.Randomized Move-to-Front: This algorithm flips a coin and moves the accessed or inserted item to front with probability ½. Now to be competitive, the expected cost (taken over all its random choices) of the algorithm running on the sequence should be within a constant factor of the cost of the optimum off-line algorithm on the same sequence. Prove that in this sense, the randomized move-to-front algorithm is competitive. 7.This question concerns Theorem 3 on the Move-to-Front heuristic. Consider the following (non- increasing) access probability distributions (for a suitable normalization parameter  that depends on n but not on i). (a) Uniform distribution: p i = , i=1..n. (b) Exponential distribution: p i =  2 –i, i=1..n. (c) Harmonic distribution: p i =  /i, i=1..n. For each of these access probability distributions answer the following two questions: (i) What should  be so that the given formula becomes a valid probability distribution. (ii) Evaluate the ratio E MF / E DF and derive its exact limit as n goes to infinity. How does it compare with the upper bound 2 given in Theorem 3(c)? 27

END 28