Lecture 10
Learning objectives
After this class, you should be able to:
- Explain the limitations of vectors.
- Explain how linked lists help overcome some of these limitations.
- Explain the idea behind linked lists.
- Give a set of operations on a linked list, draw a figure that shows the state of the linked list.
- Analyze the time complexity of operations, and the space requirements for the linked list class.
- Implement the linked list class.
- Give applications where a linked list might be useful, other than those mentioned in class.
Reading assignment
- Chapter 3, up to (and including) section 3.2.
- Section 3.5, page 102 and 103.
Exercises and review questions
- Exercises and review questions on current lecture's material
- What is the asymptotic space requirement of a linked list, as a function of the number of items present in the list? How does this compare with that for a vector?
- What is the asymptotic time requirement to check for membership in a linked list? How does this compare with that for a vector?
- Draw a figure to show the state of a doubly linked list after we have performed the following operations on it:
- Pushback 'a'
- Pushback 'a'
- Pushfront 'b'
- Pushfront 'd'
- Remove 'b'
- If we used linked lists to represent sets of items (note that a set cannot have duplicate items, and so we first need to check if an item is present, before inserting it into the list), then give the asymptotic time complexity to insert an element into a linked list.
- If we used linked lists to represent sets of items, then give an algorithm to compute the union of two sets, and give the asymptotic time complexity. (If group_number % 6 = 0)
- If we used linked lists to represent sets of items, then give an algorithm to compute the intersection of two sets, and give the asymptotic time complexity. (If group_number % 6 = 1)
- If we used linked lists to represent sets of items, then give an algorithm to compute the difference of two sets, and give the asymptotic time complexity. (If group_number % 6 = 2)
- If we used linked lists to represent sets of items, then give an algorithm to compare two sets for equality, and give the asymptotic time complexity. (If group_number % 6 = 3)
- If you wanted to create a sorted linked list, then give an algorithm to perform insertion, and give its asymptotic time complexity?(If group_number % 6 = 4)
- Can binary search be performed on a sorted linked list? Justify your answer. (If group_number % 6 = 5)
- Give an application where linked lists would be preferable to vectors, and one where vectors would be preferable to linked lists. (All groups)
- Questions on next lecture's material
- In figure 3.18 c, what would the right hand side look like if we had accessed C instead of accessing D?
Last modified: 22 Sep 2004