0% found this document useful (0 votes)
3 views15 pages

Lecture - 5

my lecture

Uploaded by

vinayakzutshi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

Lecture - 5

my lecture

Uploaded by

vinayakzutshi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

COL106 - Data Structures

and Algorithms
Work Involved in Grow – Strategy 1
Work Involved to Grow – Strategy 2
Linked List
Linked List
Singly Linked and Doubly Linked List
Singly Linked and Doubly Linked List
Singly Linked and Doubly Linked List
Single Linked and Double Linked List
Java (JDK) LinkedList implementation
public class LinkedList<E> implements List<E>...{
int size;
Node<E> first;
Node<E> last;
private static class Node<E> {
E item;
Node<E> prev; Node<E> next;
Node (Node<E> prev, E element, Node<E> next) {
this.item = element;
this.prev = prev;
this.next = next;
}
}
...
}
Append an Element to Doubly Linked List
Unlinking a Position from the List
E unlink(Node<E> x){ } else {
E element = x.item; next.prev = prev;
Node<E> next = x.next; x.next = null
Node<E> prev = x.prev; }
if (prev == null){ x.item = null;
first = next; size--;
} else { return element;
prev.next = next; }
x.prev = null;
}
if (next == null) {
last = prev;
Array vs LinkedList Implementation of List
ADT
Feature Array LinkedList
Space Usage O (N) – N is the maximum O(n) – number of elements in the
possible size list
Even in growable arrays there is
wasted space
Given integer position, get the O(1) – allows random access O(i) - for locating an element at
element integer position I
Inserting an element in the O(n) – copy all the subsequent O(1)
middle (given the position) elements
Deleting an element in the O(n) – copy all subsequent O(1)
middle (given the position) elements
What drives the choice of implementation?

You might also like