lab_001 - Homework Assignment 3 Fast Linked Lists Overview:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework Assignment 3 Fast Linked Lists Overview: One of the primary disadvantages of linked lists over other data structures is that finding a specific element in a linked list, even if it is sorted, normally requires linear time. On contrary, searching a sorted array takes log(n) by peforming a binary search. Can we use a binary search on linked lists? Theoretically yes, however the searching won't be faster than linear search. This is because the linked list can only be accessed sequentially and not in random order. In this lab assignment you will implement a sorted linked list that allows fast searching. How can we make searches faster? By implementing shortcuts! That it is, you will implement a sorted singly linked list with some shortcuts. This new data stucture allows skiping some nodes during searching, therefore leading to a better performance. To do a search in a normal singly-linked list of length n, we obviously need to look at n items in the worst case. To speed up this process, we can make a second-level list that contains roughly half the items from the original list. Now we can find a value x (let x = 8) in this structure using a two-stage algorithm. First, we scan for x in the shortcut list, If we find x, we're done. Otherwise, we reach some value w = 9 bigger than x and we know that x = 8 is not in the shortcut list. In the second phase, we scan for x in the original list, starting from the predecessor of w which in the above picture is 7. Now there is an obvious improvement - add shortcuts to the shortcuts, and repeat recursively. That's exactly how our fast linked lists are constructed. The picture below shows a fast linked list of 6 levels, where the
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.

Page1 / 4

lab_001 - Homework Assignment 3 Fast Linked Lists Overview:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online