Linked List: Overview
Linked List: Overview
Linked List: Overview
Overview:
A Linked List is a linear data structure, where elements are stored at non-
contiguous locations. A Linked list is like a chain made of nodes and the links are
pointers.
Pointers are the connections that hold the pieces of linked structures together.
Pointers represent the address of a location in memory.
Doubly Linked List: each node has two pointer, this allows you to go
backwards and forward rather than one direction way in a linked list
Linked List 1
Dynamic Size (there is no need to Very Slow when it comes to
ever resize a linked list) Access and Search we have to
iterate over each element
Quick Insertion/ Deletion of Nodes
sequentially starting from the first
because you just change the
node
pointers of each node to
insert/delete Extra space for pointer
Big O Analysis
Big
Operation Explanation
O
Insertion O1 you just change the pointers of each node to insert
Deletion O1 you just change the pointers of each node to delete
Code Implementation
# https://www.codefellows.org/blog/implementing-a-singly-linked-list-in-python/
class Node(object):
def __init__(self, data=None, next_node=None):
self.data = data
self.next_node = next_node
def get_data(self):
return self.data
def get_next(self):
return self.next_node
class LinkedList(object):
def __init__(self, head=None):
Linked List 2
self.head = head
def insert_node():
new_node = Node(data)
new_node.set_next(self.head)
self.head = new_node
Techniques
Runner Technique: iterate through the linked list with two pointers
simultaneously, with one ahead of the other. The "fast" node might be ahead by a
fixed amount, or it might be hopping multiple nodes for each one node that the
"slow" node iterates through.
Linked List 3