Advantages:
1. Faster access to the elements.
2. Implementation is super simple.
Advantages:
1. Faster access to the elements.
2. Implementation is super simple.
Disadvantages:
1. Arrays are static structures (fixed size).
2. Expensive in Insertion and Deletion.
A Linked list is a linear dynamic data structure
Data
Pointer
Node
A Linked list is a linear dynamic data structure
Data
Pointer
Node
A Linked list is a linear dynamic data structure
5
9
5
2
6
Linked List
5 => 9 => 2 => 6 => 1=>
5 => 9 => 2 => 6 => 1=>
Basic Operations
class Node():
def __init__(self, data):
self.data = data
self.next = None
# Creating a Node
n = Node(10)
Given a Linked List, write a function to insert
Given a Linked List, write a function to print the linked list.
Given a Linked List, write a function to search for an element in the linked list.
Given a Linked List, write a function to search for an element in the linked list.
Given a Linked List, write a function to delete
Given a Linked List, write a function to reverse the linked list.
Input
5 => 9 => 2 => 6 => 1=>
Output
1 => 6 => 2 => 9 => 5=>
5
9
5
2
6
1
Head
prev
next
curr
None
5
9
5
2
6
1
Head
prev
next
curr
None
5
9
5
2
6
1
Head
prev
curr
None
next
5
9
5
2
6
1
Head
prev
curr
None
next
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
None
prev
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
next
curr
5
9
5
2
6
1
Head
prev
None
None
next
curr
5
9
5
2
6
1
Head
prev
None
None
next
curr
5
9
5
2
6
1
Head
prev
None
None
next
curr
5
9
5
2
6
1
Head
prev
None
None
next
curr
5
9
5
2
6
1
Head
prev
None
None
next
curr
Given a Linked List, write a function to reverse the linked list.
Input
5 => 9 => 2 => 6 => 1=>
Output
1 => 6 => 2 => 9 => 5=>
Given a linked list, write a function to find the middle node.
Input
Output
2
5
9
5
2
6
1
Input
Output
6
5
9
5
2
6
1
7
Given two sorted linked lists, merge them into a new linked list.
Input
1-> 5 -> 7 -> 10 -> NULL
2-> 3 - > 6-> NULL
Output
1->2->3->5->6->7->10->NULL
1-> 5 -> 7 -> 10 -> NULL
2 -> 3 - > 6-> NULL
Given a linked list, write a function to sort the linked list using Merge Sort.
Input
3->2->1->6->5->4->8->7->NULL
Output
1->2->3->4->5->6->7->8->NULL
Input
First List: 5->6->3
Second List: 8->4->2
Output
Resultant list: 1->4->0->5
Given two numbers represented by two linked lists, write a function that returns the sum list. The sum list is linked list representation of the addition of two input numbers. It is not allowed to modify the lists
A Real Life Data Structures Application
User (Client)
Cache
Disk
Requests Apple
Cache
Disk
Request
Cache
Disk
Request 2 - Guava
Cache
Disk
Cache
Disk
Request-3 Mango
Cache
Disk
Cache
Disk
Request-4 Orange
Cache
Disk
Request
Cache
Disk
Request Banana
Cache
Disk
Request
Cache
Disk
Least Recently Used Item is removed from Cache
Request Mango Again
Cache
Disk
Cache - Mango exists, comes to the top again
Disk
Response is returned
Disk
Implement a data structure, for LRU Cache Implementation, which supports following operations in O(1) time.
Operations
insert (Key, Value) getValue(key) getMostRecentKey()
Also the class should have maxSize property which to set the size of cache. It represents the max number of key value pairs that can be stored inside cache at one time. If a key value pair is inserted in the cache when cache is full then the least recently used key-value pairs should be deleted and new one should be inserted. If the key already exists in the cache, then simple the value of the key can be updated with the new value.
Property
maxSize