Overview

A linked list is a data structure that represents a sequence of nodes. In a singly linked list, each node points to the next node in the linked list. A doubly linked list gives each node pointers to both the next node and the previous node.

Untitled

Why?

Pros and Cons

Advantages

Disadvantages

Big O Analysis

Space Complexity: O(n)

Time Complexity

Operation Average Worst Explanation
Access θ(n) O(n) Traversing the length of the linked list
Search θ(n) O(n) Traversing the length of the linked list
Insertion θ(1) O(n) Adding to the head of the linked list takes constant time. To add to the end, you would need to traverse through all elements
Deletion θ(1) O(n) Deleting the head takes constant time. To delete the end, it would require traversal through all elements

Code Implementation

Node

class Node {
	constructor(element) {
			this.element = element;
			this.next = null;
	}
}

LinkedList

class LinkedList {
	constructor() {
			this.head = null;
			this.size = 0;
	}

	// functions to be implemented:
	// add(element)
	// insertAt(element,location)
	// removeFrom(location)
	// removeElement(element)

}