LRU Cache Implementation using Doubly Linked List
Last Updated :
12 Jul, 2025
Design a data structure that works like a LRU(Least Recently Used) Cache. The LRUCache class has two methods get() and put() which are defined as follows.
- LRUCache (Capacity c): Initialize LRU cache with positive size capacity c.
- get(key): returns the value of the key if it already exists in the cache otherwise returns -1.
- put(key, value): if the key is already present, update its value. If not present, add the key-value pair to the cache. If the cache reaches its capacity it should remove the key-value pair with the lowest priority.
Example:
Input: [LRUCache cache = new LRUCache(2) , put(1 ,1) , put(2 ,2) , get(1) , put(3 ,3) , get(2) , put(4 ,4) , get(1) , get(3) , get(4)]
Output: [1 ,-1, -1, 3, 4]
Explanation: The values mentioned in the output are the values returned by get operations.
- Initialize LRUCache class with capacity = 2.
- cache.put(1, 1): (key, pair) = (1,1) inserted and has the highest priority.
- cache.put(2, 2): (key , pair) = (2,2) inserted and has the highest priority.
- cache.get(1): For key 1, value is 1, so 1 returned and (1,1) moved to the highest priority.
- cache.put(3, 3): Since cache is full, remove least recently used that is (2,2), (3,3) inserted with the highest priority.
- cache.get(2): returns -1 (key 2 not found)
- cache.put(4, 4): Since the cache is full, remove least recently used that is (1,1). (4,5) inserted with the highest priority.
- cache.get(1): return -1 (not found)
- cache.get(3): return 3 , (3,3) will moved to the highest priority.
- cache.get(4): return 4 , (4,4) moved to the highest priority.
Thoughts about Implementation Using Arrays, Hashing and/or Heap
We use an array of triplets, where the items are key, value and priority
get(key) : We linearly search the key. If we find the item, we change priorities of all impacted and make the new item as the highest priority.
put(key): If there is space available, we insert at the end. If not, we linearly search items of the lowest priority and replace that item with the new one. We change priorities of all and make the new item as the highest priority.
Time Complexities of both the operations is O(n)
Can we make both operations in O(1) time? we can think of hashing. With hashing, we can insert, get and delete in O(1) time, but changing priorities would take linear time. We can think of using heap along with hashing for priorities. We can find and remove the least recently used (lowest priority) in O(Log n) time which is more than O(1) and changing priority in the heap would also be required.
Using Doubly Linked List and Hashing
The idea is to keep inserting the key-value pair at the head of the doubly linked list. When a node is accessed or added, it is moved to the head of the list (right after the dummy head node). This marks it as the most recently used. When the cache exceeds its capacity, the node at the tail (right before the dummy tail node) is removed as it represents the least recently used item.
Below is the implementation of the above approach:
C++
// C++ program to implement LRU Least Recently Used)
#include <bits/stdc++.h>
using namespace std;
struct Node {
int key;
int value;
Node *next;
Node *prev;
Node(int k, int v) {
key = k;
value = v;
next = nullptr;
prev = nullptr;
}
};
// LRU Cache class
class LRUCache
{
public:
// Constructor to initialize the cache with a given capacity
int capacity;
unordered_map<int, Node *> cacheMap;
Node *head;
Node *tail;
LRUCache(int capacity) {
this->capacity = capacity;
head = new Node(-1, -1);
tail = new Node(-1, -1);
head->next = tail;
tail->prev = head;
}
// Function to get the value for a given key
int get(int key) {
if (cacheMap.find(key) == cacheMap.end())
return -1;
Node *node = cacheMap[key];
remove(node);
add(node);
return node->value;
}
// Function to put a key-value pair into the cache
void put(int key, int value) {
if (cacheMap.find(key) != cacheMap.end()) {
Node *oldNode = cacheMap[key];
remove(oldNode);
delete oldNode;
}
Node *node = new Node(key, value);
cacheMap[key] = node;
add(node);
if (cacheMap.size() > capacity) {
Node *nodeToDelete = tail->prev;
remove(nodeToDelete);
cacheMap.erase(nodeToDelete->key);
delete nodeToDelete;
}
}
// Add a node right after the head
// (most recently used position)
void add(Node *node) {
Node *nextNode = head->next;
head->next = node;
node->prev = head;
node->next = nextNode;
nextNode->prev = node;
}
// Remove a node from the list
void remove(Node *node) {
Node *prevNode = node->prev;
Node *nextNode = node->next;
prevNode->next = nextNode;
nextNode->prev = prevNode;
}
};
int main(){
LRUCache cache(2);
cache.put(1, 1);
cache.put(2, 2);
cout << cache.get(1) << endl;
cache.put(3, 3);
cout << cache.get(2) << endl;
cache.put(4, 4);
cout << cache.get(1) << endl;
cout << cache.get(3) << endl;
cout << cache.get(4) << endl;
return 0;
}
Java
// Java program to implement LRU Least Recently Used)
import java.util.HashMap;
import java.util.Map;
class Node {
int key;
int value;
Node next;
Node prev;
Node(int key, int value) {
this.key = key;
this.value = value;
this.next = null;
this.prev = null;
}
}
class LRUCache {
private int capacity;
private Map<Integer, Node> cacheMap;
private Node head;
private Node tail;
// Constructor to initialize the cache with a given
// capacity
LRUCache(int capacity) {
this.capacity = capacity;
this.cacheMap = new HashMap<>();
this.head = new Node(-1, -1);
this.tail = new Node(-1, -1);
this.head.next = this.tail;
this.tail.prev = this.head;
}
// Function to get the value for a given key
int get(int key) {
if (!cacheMap.containsKey(key)) {
return -1;
}
Node node = cacheMap.get(key);
remove(node);
add(node);
return node.value;
}
// Function to put a key-value pair into the cache
void put(int key, int value) {
if (cacheMap.containsKey(key)) {
Node oldNode = cacheMap.get(key);
remove(oldNode);
}
Node node = new Node(key, value);
cacheMap.put(key, node);
add(node);
if (cacheMap.size() > capacity) {
Node nodeToDelete = tail.prev;
remove(nodeToDelete);
cacheMap.remove(nodeToDelete.key);
}
}
// Add a node right after the head (most recently used
// position)
private void add(Node node) {
Node nextNode = head.next;
head.next = node;
node.prev = head;
node.next = nextNode;
nextNode.prev = node;
}
// Remove a node from the list
private void remove(Node node) {
Node prevNode = node.prev;
Node nextNode = node.next;
prevNode.next = nextNode;
nextNode.prev = prevNode;
}
}
public class Main {
public static void main(String[] args) {
LRUCache cache = new LRUCache(2);
cache.put(1, 1);
cache.put(2, 2);
System.out.println(cache.get(1));
cache.put(3, 3);
System.out.println(cache.get(2));
cache.put(4, 4);
System.out.println(cache.get(1));
System.out.println(cache.get(3));
System.out.println(cache.get(4));
}
}
Python
# Python program to implement LRU Least Recently Used)
class Node:
def __init__(self, key, value):
self.key = key
self.value = value
self.prev = None
self.next = None
class LRUCache:
def __init__(self, capacity: int):
self.capacity = capacity
self.cache = {}
self.head = Node(-1, -1)
self.tail = Node(-1, -1)
self.head.next = self.tail
self.tail.prev = self.head
def _add(self, node: Node):
# Add a node right after the head
# (most recently used position).
next_node = self.head.next
self.head.next = node
node.prev = self.head
node.next = next_node
next_node.prev = node
def _remove(self, node: Node):
# emove a node from the
# doubly linked list.
prev_node = node.prev
next_node = node.next
prev_node.next = next_node
next_node.prev = prev_node
def get(self, key: int) -> int:
# Get the value for a given key
if key not in self.cache:
return -1
node = self.cache[key]
self._remove(node)
self._add(node)
return node.value
def put(self, key: int, value: int):
#Put a key-value pair into the cache.
if key in self.cache:
node = self.cache[key]
self._remove(node)
del self.cache[key]
if len(self.cache) >= self.capacity:
# Remove the least recently used item
# (just before the tail)
lru_node = self.tail.prev
self._remove(lru_node)
del self.cache[lru_node.key]
# Add the new node
new_node = Node(key, value)
self._add(new_node)
self.cache[key] = new_node
if __name__ == "__main__":
cache = LRUCache(2)
cache.put(1, 1)
cache.put(2, 2)
print(cache.get(1))
cache.put(3, 3)
print(cache.get(2))
cache.put(4, 4)
print(cache.get(1))
print(cache.get(3))
print(cache.get(4))
C#
// C# program to implement LRU Least Recently Used)
using System;
using System.Collections.Generic;
class Node {
public int Key;
public int Value;
public Node Prev;
public Node Next;
public Node(int key, int value) {
Key = key;
Value = value;
Prev = null;
Next = null;
}
}
class LRUCache {
private int capacity;
private Dictionary<int, Node> cache;
private Node head;
private Node tail;
// Constructor to initialize the
// cache with a given capacity
public LRUCache(int capacity){
this.capacity = capacity;
cache = new Dictionary<int, Node>();
head = new Node(-1, -1);
tail = new Node(-1, -1);
head.Next = tail;
tail.Prev = head;
}
// Add a node right after the head
//(most recently used position)
private void Add(Node node) {
Node nextNode = head.Next;
head.Next = node;
node.Prev = head;
node.Next = nextNode;
nextNode.Prev = node;
}
// Remove a node from the doubly linked list
private void Remove(Node node) {
Node prevNode = node.Prev;
Node nextNode = node.Next;
prevNode.Next = nextNode;
nextNode.Prev = prevNode;
}
// Get the value for a given key
public int Get(int key) {
if (!cache.ContainsKey(key)) {
return -1;
}
Node node = cache[key];
Remove(node);
Add(node);
return node.Value;
}
// Put a key-value pair into the cache
public void Put(int key, int value) {
if (cache.ContainsKey(key)) {
Node oldNode = cache[key];
Remove(oldNode);
cache.Remove(key);
}
if (cache.Count >= capacity) {
Node lruNode = tail.Prev;
Remove(lruNode);
cache.Remove(lruNode.Key);
}
Node newNode = new Node(key, value);
Add(newNode);
cache[key] = newNode;
}
}
class GfG {
static void Main() {
LRUCache cache = new LRUCache(2);
cache.Put(1, 1);
cache.Put(2, 2);
Console.WriteLine(cache.Get(1));
cache.Put(3, 3);
Console.WriteLine(cache.Get(2));
cache.Put(4, 4);
Console.WriteLine(cache.Get(1));
Console.WriteLine(cache.Get(3));
Console.WriteLine(cache.Get(4));
}
}
JavaScript
// Javascript program to implement LRU Least Recently Used)
class Node {
constructor(key, value) {
this.key = key;
this.value = value;
this.prev = null;
this.next = null;
}
}
class LRUCache {
constructor(capacity) {
this.capacity = capacity;
this.cache = new Map();
this.head = new Node(-1, -1);
this.tail = new Node(-1, -1);
this.head.next = this.tail;
this.tail.prev = this.head;
}
// Add a node right after the head
//(most recently used position)
add(node) {
const nextNode = this.head.next;
this.head.next = node;
node.prev = this.head;
node.next = nextNode;
nextNode.prev = node;
}
// Remove a node from the doubly linked list
remove(node) {
const prevNode = node.prev;
const nextNode = node.next;
prevNode.next = nextNode;
nextNode.prev = prevNode;
}
// Get the value for a given key
get(key) {
if (!this.cache.has(key)) {
return -1;
}
const node = this.cache.get(key);
this.remove(node);
this.add(node);
return node.value;
}
// Put a key-value pair into the cache
put(key, value) {
if (this.cache.has(key)) {
const node = this.cache.get(key);
this.remove(node);
this.cache.delete(key);
}
if (this.cache.size >= this.capacity) {
const lruNode = this.tail.prev;
this.remove(lruNode);
this.cache.delete(lruNode.key);
}
const newNode = new Node(key, value);
this.add(newNode);
this.cache.set(key, newNode);
}
}
const cache = new LRUCache(2);
cache.put(1, 1);
cache.put(2, 2);
console.log(cache.get(1));
cache.put(3, 3);
console.log(cache.get(2));
cache.put(4, 4);
console.log(cache.get(1));
console.log(cache.get(3));
console.log(cache.get(4));
Time Complexity : get(key) - O(1) and put(key, value) - O(1)
Auxiliary Space : O(capacity)
Using Inbuilt Doubly Linked List
The idea is to use inbuilt doubly linked list, it simplifies the implementation by avoiding the need to manually manage a doubly linked list while achieving efficient operations. Example - C++ uses a custom doubly linked list as std::list.
Note: Python's standard library does not include a built-in doubly linked list implementation. To handle use cases that typically require a doubly linked list, such as efficiently managing elements at both ends of a sequence, Python provides the collections.deque class. While deque stands for double-ended queue, it essentially functions as a doubly linked list with efficient operations on both ends.
Below is the implementation of the above approach:
C++
// C++ program to implement LRU Least Recently Used) using
//Built-in Doubly linked list
#include <bits/stdc++.h>
using namespace std;
class LRUCache {
public:
int capacity;
list<pair<int, int>> List;
// Map from key to list iterator
unordered_map<int, list<pair<int, int>>::iterator> cacheMap;
// Constructor to initialize the
//cache with a given capacity
LRUCache(int capacity) {
this->capacity = capacity;
}
// Function to get the value for a given key
int get(int key) {
auto it = cacheMap.find(key);
if (it == cacheMap.end()) {
return -1;
}
// Move the accessed node to the
//front (most recently used position)
int value = it->second->second;
List.erase(it->second);
List.push_front({key, value});
// Update the iterator in the map
cacheMap[key] = List.begin();
return value;
}
// Function to put a key-value pair into the cache
void put(int key, int value) {
auto it = cacheMap.find(key);
if (it != cacheMap.end()) {
// Remove the old node from the list and map
List.erase(it->second);
cacheMap.erase(it);
}
// Insert the new node at the front of the list
List.push_front({key, value});
cacheMap[key] = List.begin();
// If the cache size exceeds the capacity,
//remove the least recently used item
if (cacheMap.size() > capacity) {
auto lastNode = List.back().first;
List.pop_back();
cacheMap.erase(lastNode);
}
}
};
int main() {
LRUCache cache(2);
cache.put(1, 1);
cache.put(2, 2);
cout << cache.get(1) << endl;
cache.put(3, 3);
cout << cache.get(2) << endl;
cache.put(4, 4);
cout << cache.get(1) << endl;
cout << cache.get(3) << endl;
cout << cache.get(4) << endl;
return 0;
}
Java
// Java program to implement LRU Least Recently Used) using
// Built-in Doubly linked list
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
class LRUCache {
private int capacity;
// Stores key-value pairs
private Map<Integer, Integer> cacheMap;
// Stores keys in the order of access
private LinkedList<Integer> lruList;
// Constructor to initialize the cache with a given
// capacity
LRUCache(int capacity) {
this.capacity = capacity;
this.cacheMap = new HashMap<>();
this.lruList = new LinkedList<>();
}
// Function to get the value for a given key
public int get(int key) {
if (!cacheMap.containsKey(key)) {
return -1;
}
// Move the accessed key to the front (most recently
// used position)
lruList.remove(Integer.valueOf(key));
// Add key to the front
lruList.addFirst(key);
return cacheMap.get(key);
}
// Function to put a key-value pair into the cache
public void put(int key, int value) {
if (cacheMap.containsKey(key)) {
// Update the value
cacheMap.put(key, value);
// Move the accessed key to the front
lruList.remove(Integer.valueOf(key));
}
else {
// Add new key-value pair
if (cacheMap.size() >= capacity) {
// Remove the least recently used item
int leastUsedKey = lruList.removeLast();
cacheMap.remove(leastUsedKey);
}
cacheMap.put(key, value);
}
// Add the key to the front (most recently used
// position)
lruList.addFirst(key);
}
public static void main(String[] args) {
LRUCache cache = new LRUCache(2);
cache.put(1, 1);
cache.put(2, 2);
System.out.println(cache.get(1));
cache.put(3, 3);
System.out.println(cache.get(2));
cache.put(4, 4);
System.out.println(cache.get(1));
System.out.println(cache.get(3));
System.out.println( cache.get(4));
}
}
Python
# Python program to implement LRU Least Recently Used) using
# Built-in Doubly linked list
from collections import deque
class LRUCache:
def __init__(self, capacity: int):
self.capacity = capacity
# Dictionary to store key-value pairs
self.cache = {}
# Deque to maintain the order of keys
self.order = deque()
def get(self, key: int) -> int:
if key in self.cache:
# Move the accessed key to
# the front of the deque
self.order.remove(key)
self.order.appendleft(key)
return self.cache[key]
else:
return -1
def put(self, key: int, value: int):
if key in self.cache:
# Update the value and move
# the key to the front
self.cache[key] = value
self.order.remove(key)
self.order.appendleft(key)
else:
if len(self.cache) >= self.capacity:
# Remove the least recently used item
lru_key = self.order.pop()
del self.cache[lru_key]
# Add the new key-value pair
self.cache[key] = value
self.order.appendleft(key)
if __name__ == "__main__":
cache = LRUCache(2)
cache.put(1, 1)
cache.put(2, 2)
print(cache.get(1))
cache.put(3, 3)
print(cache.get(2))
cache.put(4, 4)
print(cache.get(1))
print(cache.get(3))
print(cache.get(4))
C#
using System;
using System.Collections.Generic;
class LRUCache {
private int capacity;
private Dictionary<int, LinkedListNode<KeyValuePair<int, int>>> cacheMap;
private LinkedList<KeyValuePair<int, int>> lruList;
// Constructor to initialize the cache with a given capacity
public LRUCache(int capacity) {
this.capacity = capacity;
this.cacheMap = new Dictionary<int, LinkedListNode<KeyValuePair<int, int>>>();
this.lruList = new LinkedList<KeyValuePair<int, int>>();
}
// Function to get the value for a given key
public int Get(int key) {
if (cacheMap.TryGetValue(key, out LinkedListNode<KeyValuePair<int, int>> node)) {
// Move the accessed node to the front (most recently used position)
lruList.Remove(node);
lruList.AddFirst(node);
return node.Value.Value;
} else {
return -1;
}
}
// Function to put a key-value pair into the cache
public void Put(int key, int value) {
if (cacheMap.TryGetValue(key, out LinkedListNode<KeyValuePair<int, int>> node)) {
// Remove the old node from the list and map
lruList.Remove(node);
cacheMap.Remove(key);
}
// Insert the new node at the front of the list
var newNode = new KeyValuePair<int, int>(key, value);
var listNode = new LinkedListNode<KeyValuePair<int, int>>(newNode);
lruList.AddFirst(listNode);
cacheMap[key] = listNode;
// If the cache size exceeds the capacity, remove the
// least recently used item
if (cacheMap.Count > capacity) {
var lastNode = lruList.Last;
lruList.RemoveLast();
cacheMap.Remove(lastNode.Value.Key);
}
}
}
class GfG {
static void Main() {
LRUCache cache = new LRUCache(2);
cache.Put(1, 1);
cache.Put(2, 2);
Console.WriteLine(cache.Get(1));
cache.Put(3, 3);
Console.WriteLine(cache.Get(2));
cache.Put(4, 4);
Console.WriteLine(cache.Get(1));
Console.WriteLine(cache.Get(3));
Console.WriteLine(cache.Get(4));
}
}
JavaScript
// Javascript program to implement LRU Least Recently Used)
// using Built-in Doubly linked list
class LRUCache {
constructor(capacity) {
this.capacity = capacity;
this.cache = new Map();
}
// Get the value for a given key
get(key) {
if (!this.cache.has(key)) {
return -1;
}
// Move the accessed key-value pair
// to the end to mark it as recently used
const value = this.cache.get(key);
this.cache.delete(key);
this.cache.set(key, value);
return value;
}
// Put a key-value pair into the cache
put(key, value) {
if (this.cache.has(key)) {
// Update the value and move the key to the end
this.cache.delete(key);
}
else if (this.cache.size >= this.capacity) {
// Remove the least recently used item (the
// first item in the Map)
this.cache.delete(this.cache.keys().next().value);
}
// Add the new key-value pair
this.cache.set(key, value);
}
}
const cache = new LRUCache(2);
cache.put(1, 1);
cache.put(2, 2);
console.log(cache.get(1));
cache.put(3, 3);
console.log(cache.get(2));
cache.put(4, 4);
console.log(cache.get(1));
console.log(cache.get(3));
console.log(cache.get(4));
Time Complexity : get(key) - O(1) and put(key, value) - O(1)
Auxiliary Space: O(capacity)
LRU Cache
Complete Tutorial on LRU Cache with Implementations
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem