COMP2011 Tutorial Exercises 5, Week 6

Linked Lists

  1. C-4.11: Describe in pseudo-code a linear-time algorithm for reversing a singly linked list L, so that the ordering of the nodes becomes exactly opposite of what it was before.

  2. C-4.12: Give an algorithm for concatenating two singly linked lists L and M, with header sentinel nodes, into a single list L' that contains all the nodes of L (in their original order) followed by all the nodes of M (in their original order). What is the running time of this method, if we let n denote the number of nodes in L and we let m denote the number of nodes in M?

  3. C-4.13: Give an algorithm for concatenating two doubly linked lists L and M, with header and trailer sentinel nodes, into a new list L', as in the previous exercise. What is the running time of this method?

  4. C-4.15: Describe in pseudo-code how to swap two nodes x and y in a singly linked list L given references only to x and y. Repeat this exercise for the case when L is a doubly linked list. What are the running times of each of these methods in terms of n, the number of nodes in L?