Delete middle of linked list
Last Updated :
14 Aug, 2024
Given a singly linked list, the task is to delete the middle node of the list.
- If the list contains an even number of nodes, there will be two middle nodes. In this case, delete the second middle node.
- If the linked list consists of only one node, then return NULL.
Example:
Input: LinkedList: 1->2->3->4->5
Output: 1->2->4->5
Explanation:
Input: LinkedList: 2->4->6->7->5->1
Output: 2->4->6->5->1
Explaination:
Input: LinkedList: 7
Output: <empty linked list>
[Naive Approach] Using Two-Pass Traversal - O(n) Time and O(1) space
The basic idea behind this approach is to first traverse the entire linked list to count the total number of nodes. Once we know the total number of nodes, we can calculate the position of the middle node, which is at index n/2 (where n is the total number of nodes). Then go through the linked list again, but this time we stop right before the middle node. Once there, we modify the next pointer of the node before the middle node so that it skips over the middle node and points directly to the node after it,
Below is the implementation of the above approach:
C++
// C++ program to delete middle of a linked list
#include <bits/stdc++.h>
using namespace std;
struct Node {
int data;
Node* next;
Node(int x){
data = x;
next = nullptr;
}
};
// Function to delete middle node from linked list.
Node* deleteMid(Node* head) {
// Edge case: return nullptr if there is only
// one node.
if (head->next == nullptr)
return nullptr;
int count = 0;
Node *p1 = head, *p2 = head;
// First pass, count the number of nodes
// in the linked list using 'p1'.
while (p1 != nullptr) {
count++;
p1 = p1->next;
}
// Get the index of the node to be deleted.
int middleIndex = count / 2;
// Second pass, let 'p2' move toward the predecessor
// of the middle node.
for (int i = 0; i < middleIndex - 1; ++i)
p2 = p2->next;
// Delete the middle node and return 'head'.
p2->next = p2->next->next;
return head;
}
void printList(Node* head) {
Node* temp = head;
while (temp != nullptr) {
cout << temp->data << " -> ";
temp = temp->next;
}
cout << "nullptr" << endl;
}
int main() {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5.
Node* head = new Node(1);
head->next = new Node(2);
head->next->next = new Node(3);
head->next->next->next = new Node(4);
head->next->next->next->next = new Node(5);
cout << "Original Linked List: ";
printList(head);
// Delete the middle node.
head = deleteMid(head);
cout << "Linked List after deleting the middle node: ";
printList(head);
return 0;
}
C
// C program to delete middle of a linked list
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Function to delete middle node from linked list.
struct Node* deleteMid(struct Node* head) {
// Edge case: return NULL if there is only
// one node.
if (head->next == NULL)
return NULL;
int count = 0;
struct Node *p1 = head, *p2 = head;
// First pass, count the number of nodes
// in the linked list using 'p1'.
while (p1 != NULL) {
count++;
p1 = p1->next;
}
// Get the index of the node to be deleted.
int middleIndex = count / 2;
// Second pass, let 'p2' move toward the predecessor
// of the middle node.
for (int i = 0; i < middleIndex - 1; ++i)
p2 = p2->next;
// Delete the middle node and return 'head'.
p2->next = p2->next->next;
return head;
}
void printList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
struct Node* newNode(int x) {
struct Node* temp =
(struct Node*)malloc(sizeof(struct Node));
temp->data = x;
temp->next = NULL;
return temp;
}
int main() {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5.
struct Node* head = newNode(1);
head->next = newNode(2);
head->next->next = newNode(3);
head->next->next->next = newNode(4);
head->next->next->next->next = newNode(5);
printf("Original Linked List: ");
printList(head);
// Delete the middle node.
head = deleteMid(head);
printf("Linked List after deleting the middle node: ");
printList(head);
return 0;
}
Java
// Java program to delete middle of a linked list
class Node {
int data;
Node next;
Node(int x) {
data = x;
next = null;
}
}
public class GfG {
// Function to delete middle node from linked list.
public static Node deleteMid(Node head) {
// Edge case: return null if there is only
// one node.
if (head.next == null)
return null;
int count = 0;
Node p1 = head, p2 = head;
// First pass, count the number of nodes
// in the linked list using 'p1'.
while (p1 != null) {
count++;
p1 = p1.next;
}
// Get the index of the node to be deleted.
int middleIndex = count / 2;
// Second pass, let 'p2' move toward predecessor
// of the middle node.
for (int i = 0; i < middleIndex - 1; ++i)
p2 = p2.next;
// Delete the middle node and return 'head'.
p2.next = p2.next.next;
return head;
}
public static void printList(Node head) {
Node temp = head;
while (temp != null) {
System.out.print(temp.data + " -> ");
temp = temp.next;
}
System.out.println("null");
}
public static void main(String[] args) {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5.
Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head.next.next.next = new Node(4);
head.next.next.next.next = new Node(5);
System.out.print("Original Linked List: ");
printList(head);
// Delete the middle node.
head = deleteMid(head);
System.out.print
("Linked List after deleting the middle node: ");
printList(head);
}
}
Python
# Python3 program to delete middle of a linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
# Function to delete middle node from linked list.
def deleteMid(head):
# Edge case: return None if there is only
# one node.
if head.next is None:
return None
count = 0
p1 = head
p2 = head
# First pass, count the number of nodes
# in the linked list using 'p1'.
while p1 is not None:
count += 1
p1 = p1.next
# Get the index of the node to be deleted.
middleIndex = count // 2
# Second pass, let 'p2' move toward the predecessor
# of the middle node.
for i in range(middleIndex - 1):
p2 = p2.next
# Delete the middle node and return 'head'.
p2.next = p2.next.next
return head
def printList(head):
temp = head
while temp is not None:
print(temp.data, end=" -> ")
temp = temp.next
print("None")
if __name__ == "__main__":
# Create a static hardcoded linked list:
# 1 -> 2 -> 3 -> 4 -> 5.
head = Node(1)
head.next = Node(2)
head.next.next = Node(3)
head.next.next.next = Node(4)
head.next.next.next.next = Node(5)
print("Original Linked List:", end=" ")
printList(head)
# Delete the middle node.
head = deleteMid(head)
print("Linked List after deleting the middle node:", end=" ")
printList(head)
C#
// C# program to delete middle of a linked list
using System;
class Node {
public int data;
public Node next;
public Node(int x) {
data = x;
next = null;
}
}
class GfG {
// Function to delete middle node from linked list.
static Node deleteMid(Node head) {
// Edge case: return null if there is only
// one node.
if (head.next == null)
return null;
int count = 0;
Node p1 = head, p2 = head;
// First pass, count the number of nodes
// in the linked list using 'p1'.
while (p1 != null) {
count++;
p1 = p1.next;
}
// Get the index of the node to be deleted.
int middleIndex = count / 2;
// Second pass, let 'p2' move toward the predecessor
// of the middle node.
for (int i = 0; i < middleIndex - 1; ++i)
p2 = p2.next;
// Delete the middle node and return 'head'.
p2.next = p2.next.next;
return head;
}
static void printList(Node head) {
Node temp = head;
while (temp != null) {
Console.Write(temp.data + " -> ");
temp = temp.next;
}
Console.WriteLine("null");
}
static void Main(string[] args) {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5.
Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head.next.next.next = new Node(4);
head.next.next.next.next = new Node(5);
Console.Write("Original Linked List: ");
printList(head);
// Delete the middle node.
head = deleteMid(head);
Console.Write
("Linked List after deleting the middle node: ");
printList(head);
}
}
JavaScript
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
// Function to delete middle node from linked list.
function deleteMid(head) {
// Edge case: return null if there is only
// one node.
if (head.next === null)
return null;
let count = 0;
let p1 = head, p2 = head;
// First pass, count the number of nodes
// in the linked list using 'p1'.
while (p1 !== null) {
count++;
p1 = p1.next;
}
// Get the index of the node to be deleted.
let middleIndex = Math.floor(count / 2);
// Second pass, let 'p2' move toward the predecessor
// of the middle node.
for (let i = 0; i < middleIndex - 1; ++i)
p2 = p2.next;
// Delete the middle node and return 'head'.
p2.next = p2.next.next;
return head;
}
function printList(head) {
let temp = head;
while (temp !== null) {
console.log(temp.data + " -> ");
temp = temp.next;
}
console.log("null");
}
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5.
let head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head.next.next.next = new Node(4);
head.next.next.next.next = new Node(5);
console.log("Original Linked List: ");
printList(head);
// Delete the middle node.
head = deleteMid(head);
console.log("Linked List after deleting the middle node: ");
printList(head);
OutputOriginal Linked List: 1 -> 2 -> 3 -> 4 -> 5 -> nullptr
Linked List after deleting the middle node: 1 -> 2 -> 4 -> 5 -> nullptr
Time Complexity: O(n). Two traversals of the linked list are needed
Auxiliary Space: O(1). No extra space is needed.
[Expected Approach] One-Pass Traversal with Slow and Fast Pointers - O(n) Time and O(1) Space
The above solution requires two traversals of the linked list. The middle node can be deleted using one traversal. The idea is to use two pointers, slow_ptr, and fast_ptr. The fast pointer moves two nodes at a time, while the slow pointer moves one node at a time. When the fast pointer reaches the end of the list, the slow pointer will be positioned at the middle node. Next, you need to connect the node that comes before the middle node (prev) to the node that comes after the middle node. This effectively skips over the middle node, removing it from the list.
Below is the implementation of the above approach
C++
// C++ program to delete middle of a linked list
#include <bits/stdc++.h>
using namespace std;
struct Node {
int data;
Node* next;
Node(int x){
data = x;
next = nullptr;
}
};
// Function to delete middle node from linked list
struct Node* deleteMid(struct Node* head) {
// If the list is empty, return NULL
if (head == NULL)
return NULL;
// If the list has only one node,
// delete it and return NULL
if (head->next == NULL) {
delete head;
return NULL;
}
struct Node* prev = NULL;
struct Node* slow_ptr = head;
struct Node* fast_ptr = head;
// Move the fast pointer 2 nodes ahead
// and the slow pointer 1 node ahead
// until fast pointer reaches end of the list
while (fast_ptr != NULL && fast_ptr->next != NULL) {
fast_ptr = fast_ptr->next->next;
// Update prev to hold the previous
// slow pointer value
prev = slow_ptr;
slow_ptr = slow_ptr->next;
}
// At this point, slow_ptr points to middle node
// Bypass the middle node
prev->next = slow_ptr->next;
// Delete the middle node
delete slow_ptr;
// Return the head of the modified list
return head;
}
void printList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
cout << temp->data << " -> ";
temp = temp->next;
}
cout << "NULL" << endl;
}
int main() {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5
Node* head = new Node(1);
head->next = new Node(2);
head->next->next = new Node(3);
head->next->next->next = new Node(4);
head->next->next->next->next = new Node(5);
cout << "Original Linked List: ";
printList(head);
// Delete the middle node
head = deleteMid(head);
cout << "Linked List after deleting the middle node: ";
printList(head);
return 0;
}
C
// C program to delete middle of a linked list
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Function to delete middle node from linked list
struct Node* deleteMid(struct Node* head) {
// If the list is empty, return NULL
if (head == NULL)
return NULL;
// If the list has only one node,
// delete it and return NULL
if (head->next == NULL) {
free(head);
return NULL;
}
struct Node* prev = NULL;
struct Node* slow_ptr = head;
struct Node* fast_ptr = head;
// Move the fast pointer 2 nodes ahead
// and the slow pointer 1 node ahead
// until fast pointer reaches end of the list
while (fast_ptr != NULL && fast_ptr->next != NULL) {
fast_ptr = fast_ptr->next->next;
// Update prev to hold the previous
// slow pointer value
prev = slow_ptr;
slow_ptr = slow_ptr->next;
}
// At this point, slow_ptr points to middle node
// Bypass the middle node
prev->next = slow_ptr->next;
// Delete the middle node
free(slow_ptr);
// Return the head of the modified list
return head;
}
void printList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
struct Node* newNode(int x) {
struct Node* temp =
(struct Node*)malloc(sizeof(struct Node));
temp->data = x;
temp->next = NULL;
return temp;
}
int main() {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5.
struct Node* head = newNode(1);
head->next = newNode(2);
head->next->next = newNode(3);
head->next->next->next = newNode(4);
head->next->next->next->next = newNode(5);
printf("Original Linked List: ");
printList(head);
// Delete the middle node.
head = deleteMid(head);
printf("Linked List after deleting the middle node: ");
printList(head);
return 0;
}
Java
// Java program to delete the middle of a linked list
class Node {
int data;
Node next;
Node(int x) {
data = x;
next = null;
}
}
class GfG {
// Function to delete middle node from linked list
static Node deleteMid(Node head) {
// If the list is empty, return null
if (head == null)
return null;
// If the list has only one node,
// delete it and return null
if (head.next == null) {
return null;
}
Node prev = null;
Node slow_ptr = head;
Node fast_ptr = head;
// Move the fast pointer 2 nodes ahead
// and the slow pointer 1 node ahead
// until fast pointer reaches end of list
while (fast_ptr != null
&& fast_ptr.next != null) {
fast_ptr = fast_ptr.next.next;
// Update prev to hold the previous
// slow pointer value
prev = slow_ptr;
slow_ptr = slow_ptr.next;
}
// At this point,slow_ptr points to middle node
// Bypass the middle node
prev.next = slow_ptr.next;
// Return the head of the modified list
return head;
}
static void printList(Node head) {
Node temp = head;
while (temp != null) {
System.out.print(temp.data + " -> ");
temp = temp.next;
}
System.out.println("NULL");
}
public static void main(String[] args) {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5
Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head.next.next.next = new Node(4);
head.next.next.next.next = new Node(5);
System.out.print("Original Linked List: ");
printList(head);
// Delete the middle node
head = deleteMid(head);
System.out.print
("Linked List after deleting the middle node: ");
printList(head);
}
}
Python
# Python program to delete the middle of a linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
# Function to delete middle node from linked list
def deleteMid(head):
# If the list is empty, return None
if head is None:
return None
# If the list has only one node,
# delete it and return None
if head.next is None:
return None
prev = None
slow_ptr = head
fast_ptr = head
# Move the fast pointer 2 nodes ahead
# and the slow pointer 1 node ahead
# until fast pointer reaches end of the list
while fast_ptr is not None and fast_ptr.next is not None:
fast_ptr = fast_ptr.next.next
# Update prev to hold the previous
# slow pointer value
prev = slow_ptr
slow_ptr = slow_ptr.next
# At this point, slow_ptr points to middle node
# Bypass the middle node
prev.next = slow_ptr.next
# Return the head of the modified list
return head
def printList(head):
temp = head
while temp:
print(temp.data, end=" -> ")
temp = temp.next
print("NULL")
if __name__ == "__main__":
# Create a static hardcoded linked list:
# 1 -> 2 -> 3 -> 4 -> 5
head = Node(1)
head.next = Node(2)
head.next.next = Node(3)
head.next.next.next = Node(4)
head.next.next.next.next = Node(5)
print("Original Linked List: ", end="")
printList(head)
# Delete the middle node
head = deleteMid(head)
print("Linked List after deleting the middle node: ", end="")
printList(head)
C#
// C# program to delete middle of a linked list
using System;
class Node {
public int data;
public Node next;
public Node(int x) {
data = x;
next = null;
}
}
class GfG {
// Function to delete middle node from linked list
public static Node deleteMid(Node head) {
// If the list is empty, return null
if (head == null)
return null;
// If the list has only one node,
// delete it and return null
if (head.next == null) {
return null;
}
Node prev = null;
Node slow_ptr = head;
Node fast_ptr = head;
// Move the fast pointer 2 nodes ahead
// and the slow pointer 1 node ahead
// until fast pointer reaches end of the list
while (fast_ptr != null && fast_ptr.next != null) {
fast_ptr = fast_ptr.next.next;
// Update prev to hold the previous
// slow pointer value
prev = slow_ptr;
slow_ptr = slow_ptr.next;
}
// At this point, slow_ptr points to middle node
// Bypass the middle node
prev.next = slow_ptr.next;
// Return the head of the modified list
return head;
}
// Function to print the linked list
public static void printList(Node head) {
Node temp = head;
while (temp != null) {
Console.Write(temp.data + " -> ");
temp = temp.next;
}
Console.WriteLine("NULL");
}
public static void Main(string[] args) {
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5
Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head.next.next.next = new Node(4);
head.next.next.next.next = new Node(5);
Console.Write("Original Linked List: ");
printList(head);
// Delete the middle node
head = deleteMid(head);
Console.Write
("Linked List after deleting the middle node: ");
printList(head);
}
}
JavaScript
// javascript program to delete middle of a linked list
class Node {
constructor(data)
{
this.data = data;
this.next = null;
}
}
// Function to delete the middle node from the linked list
function deleteMid(head)
{
// If the list is empty, return null
if (head === null) {
return null;
}
// If the list has only one node, delete it and return
// null
if (head.next === null) {
return null;
}
let prev = null;
let slow_ptr = head;
let fast_ptr = head;
// Move the fast pointer 2 nodes ahead
// and the slow pointer 1 node ahead
// until the fast pointer reaches the end of the list
while (fast_ptr !== null && fast_ptr.next !== null) {
fast_ptr = fast_ptr.next.next;
// Update prev to hold the previous slow pointer
// value
prev = slow_ptr;
slow_ptr = slow_ptr.next;
}
// At this point, slow_ptr points to the middle node
// Bypass the middle node
prev.next = slow_ptr.next;
// Return the head of the modified list
return head;
}
function printList(head)
{
let temp = head;
while (temp !== null) {
process.stdout.write(temp.data + " -> ");
temp = temp.next;
}
console.log("null");
}
// Create a static hardcoded linked list:
// 1 -> 2 -> 3 -> 4 -> 5
let head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head.next.next.next = new Node(4);
head.next.next.next.next = new Node(5);
process.stdout.write("Original Linked List: ");
printList(head);
// Delete the middle node
head = deleteMid(head);
process.stdout.write(
"Linked List after deleting the middle node: ");
printList(head);
OutputOriginal Linked List: 1 -> 2 -> 3 -> 4 -> 5 -> NULL
Linked List after deleting the middle node: 1 -> 2 -> 4 -> 5 -> NULL
Time Complexity: O(n). Only one traversal of the linked list is needed
Auxiliary Space: O(1). As no extra space is needed.
Related Article:
Delete Middle of Linked List | DSA Problem
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