Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

Similar documents
Basic Polyhedral theory

Strongly Connected Components

Week 3: Connected Subgraphs

The Equitable Dominating Graph

Analysis of Algorithms - Elementary graphs algorithms -

Analysis of Algorithms - Elementary graphs algorithms -

1 Minimum Cut Problem

From Elimination to Belief Propagation

priority queue ADT heaps 1

cycle that does not cross any edges (including its own), then it has at least

On spanning trees and cycles of multicolored point sets with few intersections

Finding low cost TSP and 2-matching solutions using certain half integer subtour vertices

Computing and Communications -- Network Coding

Examples and applications on SSSP and MST

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Minimum Spanning Trees

Addition of angular momentum

UNTYPED LAMBDA CALCULUS (II)

Final Exam Solutions

Roadmap. XML Indexing. DataGuide example. DataGuides. Strong DataGuides. Multiple DataGuides for same data. CPS Topics in Database Systems

Random Process Part 1

Slide 1. Slide 2. Slide 3 DIGITAL SIGNAL PROCESSING CLASSIFICATION OF SIGNALS

Addition of angular momentum

Search sequence databases 3 10/25/2016

Square of Hamilton cycle in a random graph

Coupled Pendulums. Two normal modes.

10. EXTENDING TRACTABILITY

Section 6.1. Question: 2. Let H be a subgroup of a group G. Then H operates on G by left multiplication. Describe the orbits for this operation.

International Journal of Scientific & Engineering Research, Volume 6, Issue 7, July ISSN

Network Congestion Games

SOME PARAMETERS ON EQUITABLE COLORING OF PRISM AND CIRCULANT GRAPH.

Combinatorial Networks Week 1, March 11-12

Chapter 6 Folding. Folding

Supplementary Materials

CPSC 665 : An Algorithmist s Toolkit Lecture 4 : 21 Jan Linear Programming

Pipe flow friction, small vs. big pipes

1 A lower bound. Lecture notes: Online bipartite matching algorithms

a g f 8 e 11 Also: Minimum degree, maximum degree, vertex of degree d 1 adjacent to vertex of degree d 2,...

Problem Set 6 Solutions

Abstract Interpretation: concrete and abstract semantics

Where k is either given or determined from the data and c is an arbitrary constant.

A Propagating Wave Packet Group Velocity Dispersion

That is, we start with a general matrix: And end with a simpler matrix:

COMPUTER GENERATED HOLOGRAMS Optical Sciences 627 W.J. Dallas (Monday, April 04, 2005, 8:35 AM) PART I: CHAPTER TWO COMB MATH.

Mutually Independent Hamiltonian Cycles of Pancake Networks

Hardy-Littlewood Conjecture and Exceptional real Zero. JinHua Fei. ChangLing Company of Electronic Technology Baoji Shannxi P.R.

Hydrogen Atom and One Electron Ions

Sundials and Linear Algebra

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

Solution of Assignment #2

EECE 301 Signals & Systems Prof. Mark Fowler

EEO 401 Digital Signal Processing Prof. Mark Fowler

SECTION where P (cos θ, sin θ) and Q(cos θ, sin θ) are polynomials in cos θ and sin θ, provided Q is never equal to zero.

Linked-List Implementation. Linked-lists for two sets. Multiple Operations. UNION Implementation. An Application of Disjoint-Set 1/9/2014

Chapter Finding Small Vertex Covers. Extending the Limits of Tractability. Coping With NP-Completeness. Vertex Cover

Derangements and Applications

Dealing with quantitative data and problem solving life is a story problem! Attacking Quantitative Problems

Higher-Order Discrete Calculus Methods

Function Spaces. a x 3. (Letting x = 1 =)) a(0) + b + c (1) = 0. Row reducing the matrix. b 1. e 4 3. e 9. >: (x = 1 =)) a(0) + b + c (1) = 0

2. Laser physics - basics

(1) Then we could wave our hands over this and it would become:

Outlines: Graphs Part-4. Applications of Depth-First Search. Directed Acyclic Graph (DAG) Generic scheduling problem.


Y 0. Standing Wave Interference between the incident & reflected waves Standing wave. A string with one end fixed on a wall

Quasi-Classical States of the Simple Harmonic Oscillator

AS 5850 Finite Element Analysis

The second condition says that a node α of the tree has exactly n children if the arity of its label is n.

MCE503: Modeling and Simulation of Mechatronic Systems Discussion on Bond Graph Sign Conventions for Electrical Systems

CS 361 Meeting 12 10/3/18

GEOMETRICAL PHENOMENA IN THE PHYSICS OF SUBATOMIC PARTICLES. Eduard N. Klenov* Rostov-on-Don, Russia

SCHUR S THEOREM REU SUMMER 2005

4.5 Minimum Spanning Tree. Chapter 4. Greedy Algorithms. Minimum Spanning Tree. Motivating application

The Matrix Exponential

General Notes About 2007 AP Physics Scoring Guidelines

Introduction to Arithmetic Geometry Fall 2013 Lecture #20 11/14/2013

Weak Unit Disk and Interval Representation of Graphs

Lucas Test is based on Euler s theorem which states that if n is any integer and a is coprime to n, then a φ(n) 1modn.

The Matrix Exponential

Brief Introduction to Statistical Mechanics

Approximate Maximum Flow in Undirected Networks by Christiano, Kelner, Madry, Spielmann, Teng (STOC 2011)

4.5 Minimum Spanning Tree. Chapter 4. Greedy Algorithms. Minimum Spanning Tree. Applications

Chapter 13 Aggregate Supply

EEO 401 Digital Signal Processing Prof. Mark Fowler

Data Assimilation 1. Alan O Neill National Centre for Earth Observation UK

y = 2xe x + x 2 e x at (0, 3). solution: Since y is implicitly related to x we have to use implicit differentiation: 3 6y = 0 y = 1 2 x ln(b) ln(b)

orbiting electron turns out to be wrong even though it Unfortunately, the classical visualization of the

Image Filtering: Noise Removal, Sharpening, Deblurring. Yao Wang Polytechnic University, Brooklyn, NY11201

Recall that by Theorems 10.3 and 10.4 together provide us the estimate o(n2 ), S(q) q 9, q=1

Learning Spherical Convolution for Fast Features from 360 Imagery

Thus, because if either [G : H] or [H : K] is infinite, then [G : K] is infinite, then [G : K] = [G : H][H : K] for all infinite cases.

Random Access Techniques: ALOHA (cont.)

ph People Grade Level: basic Duration: minutes Setting: classroom or field site

Approximation and Inapproximation for The Influence Maximization Problem in Social Networks under Deterministic Linear Threshold Model

4. Money cannot be neutral in the short-run the neutrality of money is exclusively a medium run phenomenon.

u 3 = u 3 (x 1, x 2, x 3 )

Davisson Germer experiment Announcements:

Exam 1. It is important that you clearly show your work and mark the final answer clearly, closed book, closed notes, no calculator.

ECE 344 Microwave Fundamentals

First order differential equation Linear equation; Method of integrating factors

Chemical Physics II. More Stat. Thermo Kinetics Protein Folding...

Transcription:

3 3 4 8 6 3 3 4 8 6 3 3 4 8 6 () (d) 3 Sarching Linkd Lists Sarching Linkd Lists Sarching Linkd Lists ssum th list is sortd, but is stord in a linkd list. an w us binary sarch? omparisons? Work? What if w add additional pointrs? Sam. Is this a good modl? No. ssum th list is sortd, but is stord in a linkd list. an w us binary sarch? omparisons? Work? Much highr sinc w must mov around a lot (without comparisons) to gt to th sam position. Might gt to dsird position fastr. What if w add additional pointrs? : Thory of lgorithms Spring 4 79 / 4 Prfct Skip List 3 3 4 8 6 Prfct Skip List What is th accss tim? W can insrt/dlt in log n tim as wll. Prfct Skip List 3 3 4 8 6 3 3 4 8 6 : Thory of lgorithms Spring 4 8 / 4 uilding a Skip List uilding a Skip List uilding a Skip List Pick th nod siz at random (from a suitabl probability distribution). Pick th nod siz at random (from a suitabl probability distribution). (d) 3 () : Thory of lgorithms Spring 4 8 / 4 Skip List nalysis () What distribution do w want for th nod dpths? int randomlvl(void) { // xponntial distrib for (int lvl=; Random() == ; lvl++); rturn lvl; What is th worst cost to sarch in th prfct Skip List? What is th avrag cost to sarch in th prfct Skip List? What is th cost to insrt? Skip List nalysis () Skip List nalysis () What distribution do w want for th nod dpths? int randomlvl(void) { // xponntial distrib for (int lvl=; Random() == ; lvl++); rturn lvl; What is th worst cost to sarch in th prfct Skip List? What is th avrag cost to sarch in th prfct Skip List? What is th cost to insrt? What is th avrag cost in th typical Skip List? xponntial dcay. link half of th tim, links on quartr, 3 links on ighth, and so on. los to What is th avrag cost in th typical Skip List? : Thory of lgorithms Spring 4 8 / 4

Skip List nalysis () Skip List nalysis () Skip List nalysis () How dos this diffr from a ST? Simplr or mor complx? Mor or lss fficint? Which rlis on data distribution, which on basic laws of probability? bout th sam. How dos this diffr from a ST? Simplr or mor complx? Mor or lss fficint? Which rlis on data distribution, which on basic laws of probability? On avrag, about th sam if data ar wll distributd. ST rlis on data distribution, whil skiplist mrly rlis on chanc. : Thory of lgorithms Spring 4 83 / 4 Quicksort runs into troubl on highly structurd input. Solution: Randomiz input ordr. hanc of worst cas is thn /n!. Quicksort runs into troubl on highly structurd input. Solution: Randomiz input ordr. hanc of worst cas is thn /n!. This principl is why, for xampl, th Skip List data structur has much mor rliabl prformanc than a ST. Th ST s prformanc dpnds on th input data. Th Skip List s prformanc dpnds ntirly on chanc. or random data, th two ar ssntially idntical. ut you can t trust data to b random. : Thory of lgorithms Spring 4 84 / 4 Random Numbr Gnrators Random Numbr Gnrators Random Numbr Gnrators Most computrs systms us a dtrministic algorithm to slct psudorandom numbrs. Linar congruntial mthod: Pick a sd r(). Thn, r(i) = (r(i ) b) mod t. Must pick good valus for b and t. Rsulting numbrs must b in th rang: What happns if r(i) = r(j)? Most computrs systms us a dtrministic algorithm to slct psudorandom numbrs. Linar congruntial mthod: Pick a sd r(). Thn, r(i) = (r(i ) b) mod t. Lots of commrcial random numbr gnrators hav poor prformanc bcaus thy don t gt th numbrs right. Must b in rang to t. Thy gnrat th sam numbr, which lads to ycl of lngth j i. Must pick good valus for b and t. Rsulting numbrs must b in th rang: What happns if r(i) = r(j)? : Thory of lgorithms Spring 4 8 / 4 Random Numbr Gnrators (cont) Random Numbr Gnrators (cont) Random Numbr Gnrators (cont) Som xampls: r(i) = 6r(i ) mod 3 =, 6,, 8, 9,,, 7, 3,, 4,, r(i) = 7r(i ) mod 3 =, 7,,, 9,,, 6, 3, 8, 4,, r(i) = r(i ) mod 3 =,,, 8,,,, 3, 4, 7, 9, 6, 4, Th last on dpnds on th start valu of th sd. Suggstd gnrator: r(i) = 687r(i ) mod 3 Som xampls: r(i) = 6r(i ) mod 3 =, 6,, 8, 9,,, 7, 3,, 4,, r(i) = 7r(i ) mod 3 =, 7,,, 9,,, 6, 3, 8, 4,, r(i) = r(i ) mod 3 =,,, 8,,,, 3, 4, 7, 9, 6, 4, Th last on dpnds on th start valu of th sd. Suggstd gnrator: r(i) = 687r(i ) mod 3 : Thory of lgorithms Spring 4 86 / 4

Graph lgorithms Graph lgorithms Graph lgorithms Graphs ar usful for rprsnting a varity of concpts: ata Structurs Rlationships amilis ommunication Ntworks Road Maps Graphs ar usful for rprsnting a varity of concpts: ata Structurs Rlationships amilis ommunication Ntworks Road Maps : Thory of lgorithms Spring 4 87 / 4 Tr Proof finition: fr tr is onnctd, undirctd graph that has no cycls. Thorm: If T is a fr tr having n vrtics, thn T has xactly n dgs. Proof: y induction on n. as as: n =. T consists of vrtx and dgs. Inductiv Hypothsis: Th thorm is tru for a tr having n vrtics. If T has n vrtics, thn T contains a vrtx of dgr. Rmov that vrtx and its incidnt dg to obtain T, a fr tr with n vrtics. y IH, T has n dgs. Thus, T has n dgs. graph G = (V, ) consists of a st of vrtics V, and a st of dgs, such that ach dg in is onnction btwn a pair of vrtics in V. irctd vs. Undirctd Labld graph, wightd graph Labls for dgs vs. wights for dgs Multipl dgs, loops ycl, ircuit, path, simpl path, tours ipartit, acyclic, connctd Rootd tr, unrootd tr, fr tr Tr Proof Tr Proof finition: fr tr is onnctd, undirctd graph that has no cycls. Thorm: If T is a fr tr having n vrtics, thn T has xactly n dgs. Proof: y induction on n. as as: n =. T consists of vrtx and dgs. Inductiv Hypothsis: Th thorm is tru for a tr having n vrtics. If T has n vrtics, thn T contains a vrtx of dgr. Rmov that vrtx and its incidnt dg to obtain T, a fr tr with n vrtics. y IH, T has n dgs. Thus, T has n dgs. This is clos to a satisfactory dfinition for fr tr. Thr ar svral quivalnt dfinitions for fr trs, with similar proofs to rlat thm. Why do w know that som vrtx has dgr? caus th dfinition says that th r Tr has no cycls. : Thory of lgorithms Spring 4 88 / 4 Graph Travrsals Graph Travrsals Graph Travrsals Various problms rquir a way to travrs a graph that is, visit ach vrtx and dg in a systmatic way. Thr common travrsals: ulrian tours Travrs ach dg xactly onc pth-first sarch Kps vrtics on a stack 3 radth-first sarch Kps vrtics on a quu Various problms rquir a way to travrs a graph that is, visit ach vrtx and dg in a systmatic way. a vrtx may b visitd multipl tims Thr common travrsals: ulrian tours Travrs ach dg xactly onc pth-first sarch Kps vrtics on a stack 3 radth-first sarch Kps vrtics on a quu : Thory of lgorithms Spring 4 89 / 4 ulrian Tours ulrian Tours ulrian Tours circuit that contains vry dg xactly onc. xampl: f Tour: b a f c d. f xampl: g No ulrian tour. How can you tll for sur? circuit that contains vry dg xactly onc. xampl: f Tour: b a f c d. f xampl: g No ulrian tour. How can you tll for sur? Why no tour? caus som vrtics hav odd dgr. ll vn nods is a ncssary condition. Is it sufficint? : Thory of lgorithms Spring 4 9 / 4

ulrian Tour Proof Thorm: connctd, undirctd graph with m dgs that has no vrtics of odd dgr has an ulrian tour. Proof: y induction on m. as as: Inductiv Hypothsis: Start with an arbitrary vrtx and follow a path until you rturn to th vrtx. Rmov this circuit. What rmains ar connctd componnts G, G,..., G k ach with nods of vn dgr and < m dgs. y IH, ach connctd componnt has an ulrian tour. ombin th tours to gt a tour of th ntir graph. ulrian Tour Proof ulrian Tour Proof Thorm: connctd, undirctd graph with m dgs that has no vrtics of odd dgr has an ulrian tour. Proof: y induction on m. as as: Inductiv Hypothsis: Start with an arbitrary vrtx and follow a path until you rturn to th vrtx. Rmov this circuit. What rmains ar connctd componnts G, G,..., Gk ach with nods of vn dgr and < m dgs. y IH, ach connctd componnt has an ulrian tour. ombin th tours to gt a tour of th ntir graph. as cas: dgs and vrtx fits th thorm. IH: Th thorm is tru for < m dgs. lways possibl to find ircuit starting at any arbitrary vrtx, sinc ach vrtx has vn dgr. : Thory of lgorithms Spring 4 9 / 4 pth irst Sarch pth irst Sarch pth irst Sarch void S(Graph G, int v) { // pth first sarch PrVisit(G, v); // Tak appropriat action G.stMark(v, VISIT); for (dg w = ach nighbor of v) if (G.gtMark(G.v(w)) == UNVISIT) S(G, G.v(w)); PostVisit(G, v); // Tak appropriat action Initial call: S(G, r) whr r is th root of th S. ost: Θ( V + ). void S(Graph G, int v) { // pth first sarch PrVisit(G, v); // Tak appropriat action G.stMark(v, VISIT); for (dg w = ach nighbor of v) if (G.gtMark(G.v(w)) == UNVISIT) S(G, G.v(w)); PostVisit(G, v); // Tak appropriat action Initial call: S(G, r) whr r is th root of th S. ost: Θ( V + ). : Thory of lgorithms Spring 4 9 / 4 pth irst Sarch xampl pth irst Sarch xampl pth irst Sarch xampl Th dirctions ar imposd by th travrsal. This is th pth irst Sarch Tr. : Thory of lgorithms Spring 4 93 / 4 S Tr If w numbr th vrtics in th ordr that thy ar markd, w gt S numbrs. Lmma 7.: vry dg is ithr in th S tr T, or conncts two vrtics of G, on of which is an ancstor of th othr in T. S Tr Rsults: No cross dgs. That is, no dgs conncting vrtics sidways in th tr. S Tr If w numbr th vrtics in th ordr that thy ar markd, w gt S numbrs. Lmma 7.: vry dg is ithr in th S tr T, or conncts two vrtics of G, on of which is an ancstor of th othr in T. Proof: onsidr th first tim an dg (v, w) is xamind, with v th currnt vrtx. If w is unmarkd, thn (v, w) is in T. If w is markd, thn w has a smallr S numbr than v N (v, w) is an unxamind dg of w. Thus, w is still on th stack. That is, w is on a path from v. Proof: onsidr th first tim an dg (v, w) is xamind, with v th currnt vrtx. If w is unmarkd, thn (v, w) is in T. If w is markd, thn w has a smallr S numbr than v N (v, w) is an unxamind dg of w. Thus, w is still on th stack. That is, w is on a path from v. : Thory of lgorithms Spring 4 94 / 4

S for irctd Graphs S for irctd Graphs S for irctd Graphs Main problm: connctd graph may not giv a singl S tr. 6 7 4 orward dgs: (, 3) ack dgs: (, ) 3 9 8 ross dgs: (6, ), (8, 7), (9, ), (9, 8), (4, ) Solution: Maintain a list of unmarkd vrtics. Whnvr on S tr is complt, choos an arbitrary unmarkd vrtx as th root for a nw tr. Main problm: connctd graph may not giv a singl S tr. 6 7 4 orward dgs: (, 3) ack dgs: (, ) 3 9 8 ross dgs: (6, ), (8, 7), (9, ), (9, 8), (4, ) Solution: Maintain a list of unmarkd vrtics. Whnvr on S tr is complt, choos an arbitrary unmarkd vrtx as th root for a nw tr. : Thory of lgorithms Spring 4 9 / 4 irctd ycls Lmma 7.4: Lt G b a dirctd graph. G has a dirctd cycl iff vry S of G producs a back dg. Proof: Suppos a S producs a back dg (v, w). v and w ar in th sam S tr, w an ancstor of v. (v, w) and th path in th tr from w to v form a dirctd cycl. Suppos G has a dirctd cycl. o a S on G. Lt w b th vrtx of with smallst S numbr. Lt (v, w) b th dg of coming into w. v is a dscndant of w in a S tr. Thrfor, (v, w) is a back dg. : Thory of lgorithms Spring 4 96 / 4 irctd ycls S arlir lmma. irctd ycls Lmma 7.4: Lt G b a dirctd graph. G has a dirctd cycl iff vry S of G producs a back dg. Proof: Suppos a S producs a back dg (v, w). v and w ar in th sam S tr, w an ancstor of v. (v, w) and th path in th tr from w to v form a dirctd cycl. Suppos G has a dirctd cycl. o a S on G. Lt w b th vrtx of with smallst S numbr. Lt (v, w) b th dg of coming into w. v is a dscndant of w in a S tr. Thrfor, (v, w) is a back dg.