Delete nodes which have a greater value on right side
Last Updated :
09 Sep, 2024
Given a singly linked list, the task is to remove all the nodes with any node on their right whose value is greater and return the head of the modified linked list.
Examples:
Input: head: 12->15->10->11->5->6->2->3
Output: 15->11->6->3
Explanation: Node with value 12 , 10, 5, and 2 will be deleted as the greater value is present on right side of nodes.
Input: head: 10->20->30->40->50->60
Output: 60
Explanantion: Node with value 10 , 20, 30, 40 and 50 will be deleted as the greater value is present on right side of nodes.
[Expected Approach - 1] Using Recursion - O(n) Time and O(n) Space
The idea is to recursively travese the list and compare the nextNode data with the current node while backtracking. If the current node value is less than the nextNode value, simply return the next node (as we need to skip the current node). Otherwise, we need to set curr->next = nextNode and return the current node.
Below is the implementation of the above approach:
C++
// C++ program to delete nodes
// which have a greater value on
// right side
#include <bits/stdc++.h>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int x) {
data = x;
next = nullptr;
}
};
// This function deletes nodes on the
// right side of the linked list
Node* deleteNodesOnRightSide(Node* head) {
// If next is NULL, then there is no node
// with greater value on right side.
if(head == nullptr || head->next == nullptr) {
return head;
}
// find the next node using recursion
// It will return the node with the
// greatest value on right side.
Node* nextNode = deleteNodesOnRightSide(head->next);
// if right node's value is greater than
// current node's value, then we can simply
// return the next node
if (nextNode->data > head->data) {
return nextNode;
}
// if current node's value is greater, then
// point it to the next node, and return the
// the current node.
head->next = nextNode;
return head;
}
void printList(Node* curr) {
while (curr != nullptr) {
cout << " " << curr->data;
curr = curr->next;
}
}
int main() {
// Create linked list
// 12->15->10->11->5->6->2->3
Node* head = new Node(12);
head->next = new Node(15);
head->next->next = new Node(10);
head->next->next->next = new Node(11);
head->next->next->next->next = new Node(5);
head->next->next->next->next->next = new Node(6);
head->next->next->next->next->next->next = new Node(2);
head->next->next->next->next->next->next->next = new Node(3);
head = deleteNodesOnRightSide(head);
printList(head);
return 0;
}
C
// C program to delete nodes
// which have a greater value on
// right side
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
// Function to delete nodes which have a
// greater value on the right side
struct Node *deleteNodesOnRightSide(struct Node *head) {
// If next is NULL, then there is no node
// with greater value on right side.
if (head == NULL || head->next == NULL) {
return head;
}
// find the next node using recursion
// It will return the node with the
// greatest value on right side.
struct Node *nextNode = deleteNodesOnRightSide(head->next);
// if right node's value is greater than
// current node's value, then we can simply
// return the next node
if (nextNode->data > head->data) {
return nextNode;
}
// if current node's value is greater, then
// point it to the next node, and return the
// the current node.
head->next = nextNode;
return head;
}
void printList(struct Node *curr) {
while (curr != NULL) {
printf(" %d", curr->data);
curr = curr->next;
}
printf("\n");
}
struct Node *createNode(int new_data) {
struct Node *new_node =
(struct Node *)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = NULL;
return new_node;
}
int main() {
// Create linked list:
// 12 -> 15 -> 10 -> 11 -> 5 -> 6 -> 2 -> 3
struct Node *head = createNode(12);
head->next = createNode(15);
head->next->next = createNode(10);
head->next->next->next = createNode(11);
head->next->next->next->next = createNode(5);
head->next->next->next->next->next = createNode(6);
head->next->next->next->next->next->next = createNode(2);
head->next->next->next->next->next->next->next = createNode(3);
head = deleteNodesOnRightSide(head);
printList(head);
return 0;
}
Java
// Java program to delete nodes
// which have a greater value on
// right side
class Node {
int data;
Node next;
Node(int data) {
this.data = data;
this.next = null;
}
}
public class GfG {
// This function deletes nodes on the
// right side of the linked list
static Node deleteNodesOnRightSide(Node head) {
// If next is NULL, then there is no node
// with greater value on right side.
if (head == null || head.next == null) {
return head;
}
// if right node's value is greater than
// current node's value, then we can simply
// return the next node
Node nextNode =
deleteNodesOnRightSide(head.next);
// if current node's value is greater, then
// point it to the next node, and return the
// the current node.
if (nextNode.data > head.data) {
return nextNode;
}
// Else point the current node to next node
// and return the head node
head.next = nextNode;
return head;
}
static void printList(Node curr) {
while (curr != null) {
System.out.print(" " + curr.data);
curr = curr.next;
}
}
public static void main(String[] args) {
// Create linked list
// 12->15->10->11->5->6->2->3
Node head = new Node(12);
head.next = new Node(15);
head.next.next = new Node(10);
head.next.next.next = new Node(11);
head.next.next.next.next = new Node(5);
head.next.next.next.next.next = new Node(6);
head.next.next.next.next.next.next = new Node(2);
head.next.next.next.next.next.next.next = new Node(3);
head = deleteNodesOnRightSide(head);
printList(head);
}
}
Python
# Python program to delete nodes
# which have a greater value on
# right side
class Node:
def __init__(self, data):
self.data = data
self.next = None
# This function deletes nodes on the
# right side of the linked list
def delete_nodes(node):
# If next is NULL, then there is no node
# with greater value on right side.
if node is None or node.next is None:
return node
# find the next node using recursion
# It will return the node with the
# greatest value on right side.
next_node = delete_nodes(node.next)
# if right node's value is greater than
# current node's value, then we can simply
# return the next node
if next_node.data > node.data:
return next_node
# if current node's value is greater, then
# point it to the next node, and return the
# the current node.
node.next = next_node
return node
def print_list(curr):
while curr is not None:
print(f" {curr.data}", end="")
curr = curr.next
print()
if __name__ == "__main__":
# Create a hard-coded linked list:
# 12 -> 15 -> 10 -> 11 -> 5 -> 6 -> 2 -> 3
head = Node(12)
head.next = Node(15)
head.next.next = Node(10)
head.next.next.next = Node(11)
head.next.next.next.next = Node(5)
head.next.next.next.next.next = Node(6)
head.next.next.next.next.next.next = Node(2)
head.next.next.next.next.next.next.next = Node(3)
head = delete_nodes(head)
print_list(head)
C#
// C# program to delete nodes
// which have a greater value on
// right side
using System;
class Node {
public int Data;
public Node Next;
public Node(int data) {
Data = data;
Next = null;
}
}
// This function deletes nodes on the
// right side of the linked list
class GfG {
static Node DeleteNodesOnRightSide(Node head) {
// If next is NULL, then there is no node
// with greater value on right side.
if (head == null || head.Next == null) {
return head;
}
// find the next node using recursion
// It will return the node with the
// greatest value on right side.
Node nextNode =
DeleteNodesOnRightSide(head.Next);
// if right node's value is greater than
// current node's value, then we can simply
// return the next node
if (nextNode.Data > head.Data) {
return nextNode;
}
// if current node's value is greater, then
// point it to the next node, and return the
// the current node.
head.Next = nextNode;
return head;
}
static void PrintList(Node curr) {
while (curr != null) {
Console.Write(" " + curr.Data);
curr = curr.Next;
}
Console.WriteLine();
}
static void Main() {
// Create linked list
// 12->15->10->11->5->6->2->3
Node head = new Node(12);
head.Next = new Node(15);
head.Next.Next = new Node(10);
head.Next.Next.Next = new Node(11);
head.Next.Next.Next.Next = new Node(5);
head.Next.Next.Next.Next.Next = new Node(6);
head.Next.Next.Next.Next.Next.Next = new Node(2);
head.Next.Next.Next.Next.Next.Next.Next = new Node(3);
head = DeleteNodesOnRightSide(head);
PrintList(head);
}
}
JavaScript
// JavaScript program to delete nodes
// which have a greater value on
// right side
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
// This function deletes nodes on the
// right side of the linked list
function deleteNodesOnRightSide(head) {
// If next is NULL, then there is no node
// with greater value on right side.
if (head === null ||
head.next === null) {
return head;
}
// find the next node using recursion
// It will return the node with the
// greatest value on right side.
let nextNode =
deleteNodesOnRightSide(head.next);
// if right node's value is greater than
// current node's value, then we can simply
// return the next node
if (nextNode.data > head.data) {
return nextNode;
}
// if current node's value is greater, then
// point it to the next node, and return the
// the current node.
head.next = nextNode;
return head;
}
function printList(curr) {
while (curr !== null) {
console.log(" " + curr.data);
curr = curr.next;
}
console.log();
}
// Create a hard-coded linked list:
// 12 -> 15 -> 10 -> 11 -> 5 -> 6 -> 2 -> 3
let head = new Node(12);
head.next = new Node(15);
head.next.next = new Node(10);
head.next.next.next = new Node(11);
head.next.next.next.next = new Node(5);
head.next.next.next.next.next = new Node(6);
head.next.next.next.next.next.next = new Node(2);
head.next.next.next.next.next.next.next = new Node(3);
head = deleteNodesOnRightSide(head);
printList(head);
Time complexity: O(n), where n is the number of nodes.
Auxiliary Space: O(n)
[Expected Approach - 2] By Reversing the list - O(n) Time and O(1) Space
The idea is to reverse the linked list and maintain the maximum value from left side. If value of current node is greater than maximum value, then update the max value and move to next node. Otherwise, delete the current node. Reverse the resultant list and return it.
Step-by-step implementation:
- Reverse the list so that we can easily maintain the maximum value from the left side.
- Initialize a pointer maxnode which points to the node with maximum value on left side (initially set to head).
- Traverse the list from head node. For each node, if its value is less than maxnode, then delete it. Otherwise, update the maxnode to current node.
- Reverse the list again to retain the original order.
- Return the head of the updated list.
Below is the implementation of the above approach:
C++
// C++ program to delete nodes
// which have a greater value on
// right side
#include <bits/stdc++.h>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int x) {
data = x;
next = nullptr;
}
};
Node* reverseList(Node* headref);
Node* delLesserNodes(Node* head);
// This function reverses the list
// & calls delLesserNodes
Node* delNodes(Node* head) {
// 1) Reverse the linked list
head = reverseList(head);
// 2) In the reversed list, delete nodes
// which have a node with greater value node
// on the left side.
head = delLesserNodes(head);
// 3) Reverse the linked list again to
// retain the original order
head = reverseList(head);
return head;
}
// Deletes nodes which have
// greater value node(s) on left side
Node* delLesserNodes(Node* head) {
Node* curr = head;
// Initialize max
Node* maxnode = head;
Node* temp;
while (curr != nullptr &&
curr->next != nullptr) {
// If curr is smaller than max,
// then delete curr
if (curr->next->data < maxnode->data) {
temp = curr->next;
curr->next = temp->next;
free(temp);
}
// If curr is greater than max,
// then update max and move curr
else {
curr = curr->next;
maxnode = curr;
}
}
return head;
}
Node* reverseList(Node* headref) {
Node* curr = headref;
Node* prev = nullptr;
Node* next;
while (curr != nullptr) {
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
void printList(Node* curr) {
while (curr != nullptr) {
cout << " " << curr->data;
curr = curr->next;
}
cout << "\n";
}
int main() {
// Create linked list
// 12->15->10->11->5->6->2->3
Node* head = new Node(12);
head->next = new Node(15);
head->next->next = new Node(10);
head->next->next->next = new Node(11);
head->next->next->next->next = new Node(5);
head->next->next->next->next->next = new Node(6);
head->next->next->next->next->next->next = new Node(2);
head->next->next->next->next->next->next->next = new Node(3);
head = delNodes(head);
printList(head);
return 0;
}
C
// C program to delete nodes
// which have a greater value on
// right side
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Function to reverse the list
struct Node* reverseList(struct Node* headref) {
struct Node* curr = headref;
struct Node* prev = NULL;
struct Node* next;
while (curr != NULL) {
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
// Function to delete nodes with a
// greater value node on the right side
struct Node* delLesserNodes(struct Node* head) {
struct Node* curr = head;
struct Node* maxnode = head;
struct Node* temp;
while (curr != NULL && curr->next != NULL) {
if (curr->next->data < maxnode->data) {
temp = curr->next;
curr->next = temp->next;
free(temp);
} else {
curr = curr->next;
maxnode = curr;
}
}
return head;
}
// This function reverses the list
// & calls delLesserNodes
struct Node* delNodes(struct Node* head) {
// 1) Reverse the linked list
head = reverseList(head);
// 2) In the reversed list, delete nodes
// which have a node with greater value node
// on the left side
head = delLesserNodes(head);
// 3) Reverse the linked list again to
// retain the original order
head = reverseList(head);
return head;
}
void printList(struct Node* curr) {
while (curr != NULL) {
printf(" %d", curr->data);
curr = curr->next;
}
printf("\n");
}
struct Node* createNode(int new_value) {
struct Node* newNode =
(struct Node*)malloc(sizeof(struct Node));
newNode->data = new_value;
newNode->next = NULL;
return newNode;
}
int main() {
// Create linked list:
// 12->15->10->11->5->6->2->3
struct Node* head = createNode(12);
head->next = createNode(15);
head->next->next = createNode(10);
head->next->next->next = createNode(11);
head->next->next->next->next = createNode(5);
head->next->next->next->next->next = createNode(6);
head->next->next->next->next->next->next = createNode(2);
head->next->next->next->next->next->next->next = createNode(3);
head = delNodes(head);
printList(head);
return 0;
}
Java
// Java program to delete nodes
// which have a greater value on
// right side
class Node {
int data;
Node next;
Node(int x) {
data = x;
next = null;
}
}
public class GfG {
// This function reverses the list
// & calls delLesserNodes
static Node delNodes(Node head) {
// 1) Reverse the linked list
head = reverseList(head);
// 2) In the reversed list, delete nodes
// which have a node with greater value
// node on the left side.
head = delLesserNodes(head);
// 3) Reverse the linked list again to
// retain the original order
head = reverseList(head);
return head;
}
// Deletes nodes which have
// greater value node(s) on left side
static Node delLesserNodes(Node head) {
Node curr = head;
Node maxnode = head;
Node temp;
while (curr != null && curr.next != null) {
// If curr is smaller than max,
// then delete curr
if (curr.next.data < maxnode.data) {
temp = curr.next;
curr.next = temp.next;
temp = null;
} else {
// If curr is greater than max,
// then update max and move curr
curr = curr.next;
maxnode = curr;
}
}
return head;
}
static Node reverseList(Node headref) {
Node curr = headref;
Node prev = null;
Node next;
while (curr != null) {
next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
static void printList(Node curr) {
while (curr != null) {
System.out.print(" " + curr.data);
curr = curr.next;
}
System.out.println();
}
public static void main(String[] args) {
// Create linked list
// 12->15->10->11->5->6->2->3
Node head = new Node(12);
head.next = new Node(15);
head.next.next = new Node(10);
head.next.next.next = new Node(11);
head.next.next.next.next = new Node(5);
head.next.next.next.next.next = new Node(6);
head.next.next.next.next.next.next = new Node(2);
head.next.next.next.next.next.next.next = new Node(3);
head = delNodes(head);
printList(head);
}
}
Python
# Python program to delete nodes which
# have a greater value on the right side
class Node:
def __init__(self, x):
self.data = x
self.next = None
def reverse_list(head):
curr = head
prev = None
while curr is not None:
next_node = curr.next
curr.next = prev
prev = curr
curr = next_node
return prev
def delNodes(head):
# 1) Reverse the linked list
head = reverse_list(head)
# 2) In the reversed list, delete nodes which
# have a node with greater value
# node on the left side
head = delLesserNodes(head)
# 3) Reverse the linked list again
# to retain the original order
head = reverse_list(head)
return head
def delLesserNodes(head):
curr = head
maxnode = head
while curr is not None and curr.next is not None:
# If curr is smaller than max, then delete curr
if curr.next.data < maxnode.data:
temp = curr.next
curr.next = temp.next
temp = None
else:
# If curr is greater than max,
# then update max and move curr
curr = curr.next
maxnode = curr
return head
def print_list(curr):
while curr is not None:
print(f" {curr.data}", end="")
curr = curr.next
print()
if __name__ == "__main__":
# Create a hard-coded linked list:
# 12 -> 15 -> 10 -> 11 -> 5 -> 6 -> 2 -> 3
head = Node(12)
head.next = Node(15)
head.next.next = Node(10)
head.next.next.next = Node(11)
head.next.next.next.next = Node(5)
head.next.next.next.next.next = Node(6)
head.next.next.next.next.next.next = Node(2)
head.next.next.next.next.next.next.next = Node(3)
head = delNodes(head)
print_list(head)
C#
// C# program to delete nodes
// which have a greater value on
// right side
using System;
class Node {
public int Data;
public Node Next;
public Node(int x) {
Data = x;
Next = null;
}
}
class GfG {
static Node ReverseList(Node head) {
Node curr = head;
Node prev = null;
Node next;
while (curr != null) {
next = curr.Next;
curr.Next = prev;
prev = curr;
curr = next;
}
return prev;
}
// This function reverses the list
// & calls delLesserNodes
static Node DelNodes(Node head) {
// 1) Reverse the linked list
head = ReverseList(head);
// 2) In the reversed list, delete nodes
// which have a node with greater value
// node on the left side
head = DelLesserNodes(head);
// 3) Reverse the linked list again
// to retain the original order
head = ReverseList(head);
return head;
}
// Deletes nodes which have greater
// value node(s) on left side
static Node DelLesserNodes(Node head) {
Node curr = head;
Node maxNode = head;
while (curr != null && curr.Next != null) {
if (curr.Next.Data < maxNode.Data) {
curr.Next = curr.Next.Next;
}
else {
curr = curr.Next;
maxNode = curr;
}
}
return head;
}
static void PrintList(Node curr) {
while (curr != null) {
Console.Write(" " + curr.Data);
curr = curr.Next;
}
Console.WriteLine();
}
static void Main() {
// Create a hard-coded linked list:
// 12 -> 15 -> 10 -> 11 -> 5 -> 6 -> 2 -> 3
Node head = new Node(12);
head.Next = new Node(15);
head.Next.Next = new Node(10);
head.Next.Next.Next = new Node(11);
head.Next.Next.Next.Next = new Node(5);
head.Next.Next.Next.Next.Next = new Node(6);
head.Next.Next.Next.Next.Next.Next = new Node(2);
head.Next.Next.Next.Next.Next.Next.Next = new Node(3);
head = DelNodes(head);
PrintList(head);
}
}
JavaScript
// JavaScript program to delete nodes
// which have a greater value
// on the right side
class Node {
constructor(x) {
this.data = x;
this.next = null;
}
}
function reverseList(head) {
let curr = head;
let prev = null;
let next;
while (curr !== null) {
next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
// This function reverses the list
// & calls delLesserNodes
function delNodes(head) {
// 1) Reverse the linked list
head = reverseList(head);
// 2) In the reversed list, delete
// nodes which have a node with
// greater value on the left side
head = delLesserNodes(head);
// 3) Reverse the linked list again
// to retain the original order
head = reverseList(head);
return head;
}
// Deletes nodes which have greater
// value node(s) on the left side
function delLesserNodes(head) {
let curr = head;
let maxNode = head;
while (curr !== null &&
curr.next !== null) {
if (curr.next.data < maxNode.data) {
// Delete curr.next
curr.next = curr.next.next;
} else {
curr = curr.next;
maxNode = curr;
}
}
return head;
}
function printList(curr) {
while (curr !== null) {
console.log(curr.data)
curr = curr.next;
}
}
// Create a hard-coded linked list:
// 12 -> 15 -> 10 -> 11 -> 5 -> 6 -> 2 -> 3
let head = new Node(12);
head.next = new Node(15);
head.next.next = new Node(10);
head.next.next.next = new Node(11);
head.next.next.next.next = new Node(5);
head.next.next.next.next.next = new Node(6);
head.next.next.next.next.next.next = new Node(2);
head.next.next.next.next.next.next.next = new Node(3);
head = delNodes(head);
printList(head);
Time complexity: O(n), where n is the number of nodes.
Space complexity: O(1)
Delete nodes having greater value on right | 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