lec12 - Introduction to Algorithms 6.046J/18.401J LECTURE...

Info icon This preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.1 Introduction to Algorithms 6.046J/18.401J L ECTURE 12 Skip Lists Data structure Randomized insertion With-high-probability bound Analysis Coin flipping Prof. Erik D. Demaine
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.2 Skip lists Simple randomized dynamic search structure – Invented by William Pugh in 1989 – Easy to implement Maintains a dynamic set of n elements in O (lg n ) time per operation in expectation and with high probability – Strong guarantee on tail of distribution of T ( n ) O (lg n ) “almost always”
Image of page 2
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.3 One linked list Start from simplest data structure: (sorted) linked list Searches take Θ ( n ) time in worst case How can we speed up searches? 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.4 Two linked lists Suppose we had two sorted linked lists (on subsets of the elements) Each element can appear in one or both lists How can we speed up searches? 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79
Image of page 4
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.5 Two linked lists as a subway I DEA : Express and local subway lines (à la New York City 7th Avenue Line) Express line connects a few of the stations Local line connects all stations Links between lines at common stations 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79 14 14 34 34 42 42 72 72
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.6 Searching in two linked lists S EARCH ( x ) : Walk right in top linked list ( L 1 ) until going right would go too far Walk down to bottom linked list ( L 2 ) Walk right in L 2 until element found (or not) 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79 14 14 34 34 42 42 72 72
Image of page 6
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.7 Searching in two linked lists E XAMPLE : S EARCH (59) Too far: 59 < 72 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79 14 14 34 34 42 42 72 72
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.8 Design of two linked lists Q UESTION : Which nodes should be in L 1 ? In a subway, the “popular stations” Here we care about worst-case performance Best approach: Evenly space the nodes in L 1 • But how many nodes should be in L 1 ? 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79 14 14 34 34 42 42 72 72
Image of page 8
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.9 Analysis of two linked lists A NALYSIS : Search cost is roughly Minimized (up to constant factors) when terms are equal 14 14 23 23 34 34 42 42 50 50 59 59 66 66 72 72 79 79 14 14 34 34 42 42 72 72 1 2 1 L L L + n L n L L = = = 1 2 2 1
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
October 26, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.10 Analysis of two linked lists A NALYSIS : ,
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern