Remove consecutive vowels from string
Last Updated :
30 Nov, 2023
Given a string s of lowercase letters, we need to remove consecutive vowels from the string
Note : Sentence should not contain two consecutive vowels ( a, e, i, o, u).
Examples :
Input: geeks for geeks
Output: geks for geks
Input : your article is in queue
Output : yor article is in qu
Approach: Iterate string using a loop and check for the repetitiveness of vowels in a given sentence and in case if consecutive vowels are found then delete the vowel till coming next consonant and printing the updated string.
Implementation:
C++
// C++ program for printing sentence
// without repetitive vowels
#include <bits/stdc++.h>
using namespace std;
// function which returns True or False
// for occurrence of a vowel
bool is_vow(char c)
{
// this compares vowel with
// character 'c'
return (c == 'a') || (c == 'e') ||
(c == 'i') || (c == 'o') ||
(c == 'u');
}
// function to print resultant string
void removeVowels(string str)
{
// print 1st character
printf("%c", str[0]);
// loop to check for each character
for (int i = 1; str[i]; i++)
// comparison of consecutive characters
if ((!is_vow(str[i - 1])) ||
(!is_vow(str[i])))
printf("%c", str[i]);
}
// Driver Code
int main()
{
char str[] = " geeks for geeks";
removeVowels(str);
}
// This code is contributed by Abhinav96
Java
// Java program for printing sentence
// without repetitive vowels
import java.io.*;
import java.util.*;
import java.lang.*;
class GFG
{
// function which returns
// True or False for
// occurrence of a vowel
static boolean is_vow(char c)
{
// this compares vowel
// with character 'c'
return (c == 'a') || (c == 'e') ||
(c == 'i') || (c == 'o') ||
(c == 'u');
}
// function to print
// resultant string
static void removeVowels(String str)
{
// print 1st character
System.out.print(str.charAt(0));
// loop to check for
// each character
for (int i = 1;
i < str.length(); i++)
// comparison of
// consecutive characters
if ((!is_vow(str.charAt(i - 1))) ||
(!is_vow(str.charAt(i))))
System.out.print(str.charAt(i));
}
// Driver Code
public static void main(String[] args)
{
String str = "geeks for geeks";
removeVowels(str);
}
}
Python3
# Python3 implementation for printing
# sentence without repetitive vowels
# function which returns True or False
# for occurrence of a vowel
def is_vow(c):
# this compares vowel with
# character 'c'
return ((c == 'a') or (c == 'e') or
(c == 'i') or (c == 'o') or
(c == 'u'));
# function to print resultant string
def removeVowels(str):
# print 1st character
print(str[0], end = "");
# loop to check for each character
for i in range(1,len(str)):
# comparison of consecutive
# characters
if ((is_vow(str[i - 1]) != True) or
(is_vow(str[i]) != True)):
print(str[i], end = "");
# Driver code
str= " geeks for geeks";
removeVowels(str);
# This code is contributed by mits
C#
// C# program for printing sentence
// without repetitive vowels
using System;
class GFG
{
// function which returns
// True or False for
// occurrence of a vowel
static bool is_vow(char c)
{
// this compares vowel
// with character 'c'
return (c == 'a') || (c == 'e') ||
(c == 'i') || (c == 'o') ||
(c == 'u');
}
// function to print
// resultant string
static void removeVowels(string str)
{
// print 1st character
Console.Write(str[0]);
// loop to check for
// each character
for (int i = 1; i < str.Length; i++)
// comparison of
// consecutive characters
if ((!is_vow(str[i - 1])) ||
(!is_vow(str[i])))
Console.Write(str[i]);
}
// Driver Code
static void Main()
{
string str = "geeks for geeks";
removeVowels(str);
}
}
// This code is contributed
// by Manish Shaw(manishshaw1)
JavaScript
<script>
// JavaScript program for printing sentence
// without repetitive vowels
// function which returns True or False
// for occurrence of a vowel
function is_vow(c)
{
// this compares vowel with
// character 'c'
return (c == 'a') || (c == 'e') ||
(c == 'i') || (c == 'o') ||
(c == 'u');
}
// function to print resultant string
function removeVowels(str)
{
// print 1st character
document.write(str[0]);
// loop to check for each character
for (let i = 1; i<str.length; i++)
// comparison of consecutive characters
if ((!is_vow(str[i - 1])) ||
(!is_vow(str[i])))
document.write(str[i]);
}
// Driver Code
let str = " geeks for geeks";
removeVowels(str);
// This code is contributed by shinjanpatra
</script>
PHP
<?php
// PHP implementation for printing
// sentence without repetitive vowels
// function which returns True or False
// for occurrence of a vowel
function is_vow($c)
{
// this compares vowel with
// character 'c'
return ($c == 'a') || ($c == 'e') ||
($c == 'i') || ($c == 'o') ||
($c == 'u');
}
// function to print resultant string
function removeVowels($str)
{
// print 1st character
printf($str[0]);
// loop to check for each character
for ($i = 1; $i < strlen($str); $i++)
// comparison of consecutive
// characters
if ((!is_vow($str[$i - 1])) ||
(!is_vow($str[$i])))
printf($str[$i]);
}
// Driver code
$str= " geeks for geeks";
removeVowels($str);
// This code is contributed by mits
?>
Time Complexity: O(n), where n is the length of the string
Space Complexity: O(n), where n is the length of the string
Another approach:- here's another approach in C++ to remove consecutive vowels from a string using a stack:
- Define a function named isVowel that takes a character as input and returns a boolean value indicating whether the character is a vowel.
- Define a function named removeConsecutiveVowels that takes a string as input and returns a string with all consecutive vowels removed.
- Create a stack named stk to store the characters of the input string.
- Get the length of the input string.
- Loop through each character of the input string by using a for loop.
- Check if the current character is a vowel by calling the isVowel function.
- If the current character is a vowel, check if the stack is not empty and the top of the stack is also a vowel.
- If the conditions in step 8 are satisfied, pop all consecutive vowels from the stack.
- Push the current character onto the stack.
- Construct the result string by popping all elements from the stack.
- Return the result string.
Below is the implementation of the above approach:
C++
#include <iostream>
#include <string>
#include <stack>
using namespace std;
bool isVowel(char c) {
// check if a character is a vowel
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
string removeConsecutiveVowels(string str) {
stack<char> stk;
int len = str.length();
for (int i = 0; i < len; i++) {
// if current character is a vowel
if (isVowel(str[i])) {
// check if the stack is not empty and the top of the stack is also a vowel
if (!stk.empty() && isVowel(stk.top())) {
// pop all consecutive vowels from the stack
while (!stk.empty() && isVowel(stk.top())) {
stk.pop();
}
}
}
// push the current character onto the stack
stk.push(str[i]);
}
// construct the result string by popping all elements from the stack
string result = "";
while (!stk.empty()) {
result = stk.top() + result;
stk.pop();
}
return result;
}
int main() {
string str = " geeks for geeks";
cout << removeConsecutiveVowels(str) << endl; // expected output: "ltcdsccmmntyfrcdrs"
return 0;
}
Java
import java.util.Stack;
public class RemoveConsecutiveVowels {
public static boolean isVowel(char c) {
// check if a character is a vowel
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
public static String removeConsecutiveVowels(String str) {
Stack<Character> stk = new Stack<>();
int len = str.length();
for (int i = 0; i < len; i++) {
// if current character is a vowel
if (isVowel(str.charAt(i))) {
// check if the stack is not empty and the top of the stack is also a vowel
if (!stk.empty() && isVowel(stk.peek())) {
// pop all consecutive vowels from the stack
while (!stk.empty() && isVowel(stk.peek())) {
stk.pop();
}
}
}
// push the current character onto the stack
stk.push(str.charAt(i));
}
// construct the result string by popping all elements from the stack
StringBuilder result = new StringBuilder();
while (!stk.empty()) {
result.insert(0, stk.peek());
stk.pop();
}
return result.toString();
}
public static void main(String[] args) {
String str = " geeks for geeks";
System.out.println(removeConsecutiveVowels(str)); // expected output: "ltcdsccmmntyfrcdrs"
}
}
// This code is contributed by Prajwal Kandekar
Python3
def is_vowel(c):
# check if a character is a vowel
return (c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' or
c == 'A' or c == 'E' or c == 'I' or c == 'O' or c == 'U')
def remove_consecutive_vowels(s):
stack = []
for c in s:
# if current character is a vowel
if is_vowel(c):
# check if the stack is not empty and the top of the stack is also a vowel
if stack and is_vowel(stack[-1]):
# pop all consecutive vowels from the stack
while stack and is_vowel(stack[-1]):
stack.pop()
# push the current character onto the stack
stack.append(c)
# construct the result string by popping all elements from the stack
result = ""
while stack:
result = stack.pop() + result
return result
# test the function
s = " geeks for geeks"
print(remove_consecutive_vowels(s))
C#
using System;
using System.Collections.Generic;
public class Program {
static bool IsVowel(char c)
{
// check if a character is a vowel
return (c == 'a' || c == 'e' || c == 'i' || c == 'o'
|| c == 'u' || c == 'A' || c == 'E'
|| c == 'I' || c == 'O' || c == 'U');
}
static string RemoveConsecutiveVowels(string str)
{
Stack<char> stk = new Stack<char>();
int len = str.Length;
for (int i = 0; i < len; i++) {
// if current character is a vowel
if (IsVowel(str[i])) {
// check if the stack is not empty and the
// top of the stack is also a vowel
if (stk.Count > 0 && IsVowel(stk.Peek())) {
// pop all consecutive vowels from the
// stack
while (stk.Count > 0
&& IsVowel(stk.Peek())) {
stk.Pop();
}
}
}
// push the current character onto the stack
stk.Push(str[i]);
}
// construct the result string by popping all
// elements from the stack
string result = "";
while (stk.Count > 0) {
result = stk.Peek() + result;
stk.Pop();
}
return result;
}
public static void Main()
{
string str = " geeks for geeks";
Console.WriteLine(RemoveConsecutiveVowels(
str)); // expected output: " gks fr gks"
}
}
// This code is contributed by user_dtewbxkn77n
JavaScript
function isVowel(c) {
// check if a character is a vowel
return (c === 'a' || c === 'e' || c === 'i' || c === 'o' || c === 'u' ||
c === 'A' || c === 'E' || c === 'I' || c === 'O' || c === 'U');
}
function removeConsecutiveVowels(str) {
let stk = [];
let len = str.length;
for (let i = 0; i < len; i++)
{
// if current character is a vowel
if (isVowel(str[i]))
{
// check if the stack is not empty and the top of the stack is also a vowel
if (stk.length > 0 && isVowel(stk[stk.length - 1]))
{
// pop all consecutive vowels from the stack
while (stk.length > 0 && isVowel(stk[stk.length - 1])) {
stk.pop();
}
}
}
// push the current character onto the stack
stk.push(str[i]);
}
// construct the result string by popping all elements from the stack
let result = "";
while (stk.length > 0) {
result = stk[stk.length - 1] + result;
stk.pop();
}
return result;
}
let str = " geeks for geeks";
console.log(removeConsecutiveVowels(str));
Time Complexity: O(n), where n is the length of the string
The time complexity of the removeConsecutiveVowels function is O(n), where n is the length of the input string. This is because each character of the input string is processed once in the for loop, and all operations inside the loop are constant time operations.
Space Complexity: O(n), where n is the length of the string
The space complexity of the function is O(n), where n is the length of the input string. This is because the size of the stack can be at most the length of the input string, and the result string can also be of the same size as the input string in the worst case.
Another Approach:
This approach works by iterating over the input string and checking each character. If the current character is a vowel, it checks whether the previous character is also a vowel. If the previous character is not a vowel, it appends the current character to the result string. If the previous character is a vowel, it skips over the current character and continues iterating. If the current character is not a vowel, it simply appends it to the result string.
This approach does not use a stack, which can make it simpler and easier to understand. However, it may be slightly less efficient than the stack-based approach, since it needs to check the previous character at each iteration.
C++
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char c) {
// check if a character is a vowel
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
string removeConsecutiveVowels(string str) {
string result = "";
int len = str.length();
for (int i = 0; i < len; i++) {
// if current character is a vowel
if (isVowel(str[i])) {
// check if the previous character is also a vowel
if (i == 0 || !isVowel(str[i - 1])) {
// if not, append the current character to the result string
result += str[i];
}
} else {
// if the current character is not a vowel, append it to the result string
result += str[i];
}
}
return result;
}
int main() {
string str = " geeks for geeks";
cout << removeConsecutiveVowels(str) << endl; // expected output: " ltcdsccmmntyfrcdrs"
return 0;
}
Java
import java.io.*;
import java.util.HashSet;
public class GFG {
static boolean isVowel(char c) {
// Check if a character is a vowel
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
static String removeConsecutiveVowels(String str) {
String result = "";
int len = str.length();
for (int i = 0; i < len; i++) {
// If current character is a vowel
if (isVowel(str.charAt(i))) {
// Check if the previous character is also a vowel
if (i == 0 || !isVowel(str.charAt(i - 1))) {
// If not, append the current character to the result string
result += str.charAt(i);
}
} else {
// If the current character is not a vowel, append it to the result string
result += str.charAt(i);
}
}
return result;
}
public static void main(String[] args) {
String str = " geeks for geeks";
System.out.println(removeConsecutiveVowels(str)); // expected output: " ltcdsccmmntyfrcdrs"
}
}
// THIS CODE IS CONTRIBUTED BY YASH AGARWAL(YASHAGARWAL2852002)
Python3
def isVowel(c):
# Check if a character is a vowel
return c in ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
def removeConsecutiveVowels(string):
result = ''
length = len(string)
for i in range(length):
# If current character is a vowel
if isVowel(string[i]):
# Check if the previous character is also a vowel
if i == 0 or not isVowel(string[i - 1]):
# If not, append the current character to
# the result string
result += string[i]
else:
# If the current character is not a vowel,
# append it to the result string
result += string[i]
return result
# Driver code
string = ' geeks for geeks'
print(removeConsecutiveVowels(string))
# THIS CODE IS CONTRIBUTED BY KANCHAN AGARWAL
C#
using System;
class Program {
static bool IsVowel(char c)
{
// Check if a character is a vowel
return (c == 'a' || c == 'e' || c == 'i' || c == 'o'
|| c == 'u' || c == 'A' || c == 'E'
|| c == 'I' || c == 'O' || c == 'U');
}
static string RemoveConsecutiveVowels(string str)
{
string result = "";
int len = str.Length;
for (int i = 0; i < len; i++) {
// If the current character is a vowel
if (IsVowel(str[i])) {
// Check if the previous character is also a
// vowel
if (i == 0 || !IsVowel(str[i - 1])) {
// If not, append the current character
// to the result string
result += str[i];
}
}
else {
// If the current character is not a vowel,
// append it to the result string
result += str[i];
}
}
return result;
}
static void Main(string[] args)
{
string str = " geeks for geeks";
Console.WriteLine(RemoveConsecutiveVowels(
str)); // Expected output: " ltcdsccmmntyfrcdrs"
}
}
JavaScript
function isVowel(c) {
// Check if a character is a vowel
return (
c === 'a' ||
c === 'e' ||
c === 'i' ||
c === 'o' ||
c === 'u' ||
c === 'A' ||
c === 'E' ||
c === 'I' ||
c === 'O' ||
c === 'U'
);
}
function removeConsecutiveVowels(str) {
let result = '';
const len = str.length;
for (let i = 0; i < len; i++) {
// If current character is a vowel
if (isVowel(str[i])) {
// Check if the previous character is also a vowel
if (i === 0 || !isVowel(str[i - 1])) {
// If not, append the current character to the
// result string
result += str[i];
}
} else {
// If the current character is not a vowel, append it
// to the result string
result += str[i];
}
}
return result;
}
// Driver code
const str = ' geeks for geeks';
console.log(removeConsecutiveVowels(str));
// Expected output: " ltcdsccmmntyfrcdrs"
Output:
geks for geks
Time Complexity: O(n), where n is the length of the input string.
Space Complexity: O(n), where n is the length of the input string.
Constant Space Approach:
The algorithm of the constant space approach for removing repetitive vowels from a sentence is as follows:
- Initialize an empty string called result to store the modified string without repetitive vowels.
- Add the first character of the input string str to the result string.
- Iterate through the remaining characters of the input string from the second character onward.
- For each character at index i in the input string:
- Check if the current character str[i] and the previous character str[i-1] are both vowels using the is_vowel function.
If both characters are vowels, skip adding the current character to the result string, as it is a repetitive vowel.
If either the current character or the previous character is not a vowel, add the current character to the result string.
After iterating through all the characters in the input string, the result string will contain the modified string without repetitive vowels. - Print the result string as the output.
Here is the code of above approach:
C++
#include <iostream>
using namespace std;
bool is_vowel(char c) {
// Convert character to lowercase for case-insensitive comparison
c = tolower(c);
return (c == 'a') || (c == 'e') ||
(c == 'i') || (c == 'o') ||
(c == 'u');
}
void removeVowels(string str) {
// Initialize the result string with the first character of the input string
string result = "";
result += str[0];
// Loop to check for each character starting from the second character
for (int i = 1; i < str.length(); i++) {
// Comparison of consecutive characters
if ((!is_vowel(str[i - 1])) || (!is_vowel(str[i])))
result += str[i];
}
// Print the resultant string
cout << result << endl;
}
int main() {
string str = "geeks for geeks";
removeVowels(str);
return 0;
}
Java
// Java code for the above approach
public class GFG {
// Function to check if a character is a vowel
public static boolean isVowel(char c)
{
// Convert character to lowercase for
// case-insensitive comparison
c = Character.toLowerCase(c);
return (c == 'a') || (c == 'e') || (c == 'i')
|| (c == 'o') || (c == 'u');
}
// Function to remove vowels from a string
public static void removeVowels(String str)
{
// Initialize the result string with the first
// character of the input string
StringBuilder result = new StringBuilder();
result.append(str.charAt(0));
// Loop to check for each character starting from
// the second character
for (int i = 1; i < str.length(); i++) {
// Comparison of consecutive characters
if ((!isVowel(str.charAt(i - 1)))
|| (!isVowel(str.charAt(i)))) {
result.append(str.charAt(i));
}
}
// Print the resultant string
System.out.println(result);
}
// Driver code
public static void main(String[] args)
{
String str = "geeks for geeks";
removeVowels(str);
}
}
// This code is contributed by Susobhan Akhuli
Python3
# Python code for the above approach
def is_vowel(c):
# Convert character to lowercase for case-insensitive comparison
c = c.lower()
return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'
def removeVowels(string):
# Initialize the result string with the first character of the input string
result = string[0]
# Loop to check for each character starting from the second character
for i in range(1, len(string)):
# Comparison of consecutive characters
if (not is_vowel(string[i - 1])) or (not is_vowel(string[i])):
result += string[i]
# Print the resultant string
print(result)
if __name__ == "__main__":
string = "geeks for geeks"
removeVowels(string)
# This code is contributed by Susobhan Akhuli
C#
using System;
class Program
{
// Function to check if a character is a vowel
static bool IsVowel(char c)
{
// Convert character to lowercase for case-insensitive comparison
c = char.ToLower(c);
return (c == 'a') || (c == 'e') ||
(c == 'i') || (c == 'o') ||
(c == 'u');
}
// Function to remove vowels from a string
static void RemoveVowels(string str)
{
// Initialize the result string with the first character of the input string
string result = "" + str[0];
// Loop to check for each character starting from the second character
for (int i = 1; i < str.Length; i++)
{
// Comparison of consecutive characters
if ((!IsVowel(str[i - 1])) || (!IsVowel(str[i])))
result += str[i];
}
// Print the resultant string
Console.WriteLine(result);
}
static void Main()
{
string str = "geeks for geeks";
RemoveVowels(str);
}
}
JavaScript
function isVowel(c) {
// Convert character to lowercase for case-insensitive comparison
c = c.toLowerCase();
return (c === 'a') || (c === 'e') ||
(c === 'i') || (c === 'o') ||
(c === 'u');
}
function removeVowels(str) {
// Initialize the result string with the first character of the input string
let result = str[0];
// Loop to check for each character starting from the second character
for (let i = 1; i < str.length; i++) {
// Comparison of consecutive characters
if ((!isVowel(str[i - 1])) || (!isVowel(str[i]))) {
result += str[i];
}
}
// Print the resultant string
console.log(result);
}
// Driver code
let str = "geeks for geeks";
removeVowels(str);
Time Complexity: O(n), where n is the length of the input string.
Auxiliary Space: O(1).
Remove consecutive vowels from string
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