Binary trees are fundamental data structures in computer science and understanding their traversal is crucial for various applications. Traversing a binary tree means visiting all the nodes in a specific order. There are several traversal methods, each with its unique applications and benefits. This article will explore the main types of binary tree traversal: in-order, pre-order, post-order, and level-order.
Types of Binary Tree Traversal
In in-order traversal, the left child is visited first, followed by the node itself, and then the right child. This can be visualized as Left - Root - Right.
C++
#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* left;
Node* right;
Node(int item) {
data = item;
left = right = nullptr;
}
};
class GFG {
public:
static void inOrderTraversal(Node* root) {
if (root == nullptr) return;
// Traverse the left subtree
inOrderTraversal(root->left);
// Visit the root node
cout << root->data << " ";
// Traverse the right subtree
inOrderTraversal(root->right);
}
};
int main() {
Node* root = new Node(2);
root->left = new Node(1);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
cout << "In-Order Traversal: ";
GFG::inOrderTraversal(root);
cout << endl;
return 0;
}
C
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* left;
struct Node* right;
};
void inOrderTraversal(struct Node* root) {
if (root == NULL) return;
// Traverse the left subtree
inOrderTraversal(root->left);
// Visit the root node
printf("%d ", root->data);
// Traverse the right subtree
inOrderTraversal(root->right);
}
struct Node* newNode(int data) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
int main() {
struct Node* root = newNode(2);
root->left = newNode(1);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("In-Order Traversal: ");
inOrderTraversal(root);
printf("\n");
return 0;
}
Java
class Node {
int data;
Node left, right;
Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void inOrderTraversal(Node root) {
if (root == null) return;
// Traverse the left subtree
inOrderTraversal(root.left);
// Visit the root node
System.out.print(root.data + " ");
// Traverse the right subtree
inOrderTraversal(root.right);
}
public static void main(String[] args) {
Node root = new Node(2);
root.left = new Node(1);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
System.out.print("In-Order Traversal: ");
inOrderTraversal(root);
System.out.println();
}
}
Python
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def in_order_traversal(root):
if root is None:
return
# Traverse the left subtree
in_order_traversal(root.left)
# Visit the root node
print(root.data, end=" ")
# Traverse the right subtree
in_order_traversal(root.right)
if __name__ == "__main__":
root = Node(2)
root.left = Node(1)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
print("In-Order Traversal: ", end="")
in_order_traversal(root)
print()
C#
using System;
class Node {
public int data;
public Node left, right;
public Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void InOrderTraversal(Node root) {
if (root == null) return;
// Traverse the left subtree
InOrderTraversal(root.left);
// Visit the root node
Console.Write(root.data + " ");
// Traverse the right subtree
InOrderTraversal(root.right);
}
static void Main(string[] args) {
Node root = new Node(2);
root.left = new Node(1);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
Console.Write("In-Order Traversal: ");
InOrderTraversal(root);
Console.WriteLine();
}
}
JavaScript
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
function inOrderTraversal(root) {
if (root === null) return;
// Traverse the left subtree
inOrderTraversal(root.left);
// Visit the root node
console.log(root.data + " ");
// Traverse the right subtree
inOrderTraversal(root.right);
}
// Driver Code
let root = new Node(2);
root.left = new Node(1);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
// Perform inorder traversal
console.log("In-Order Traversal:");
inOrderTraversal(root);
OutputIn-Order Traversal: 4 1 5 2 3
Time Complexity: O(N)
Auxiliary Space: If we don’t consider the size of the stack for function calls then O(1) otherwise O(h) where h is the height of the tree.
Below are some important concepts in In-order Traversal:
In pre-order traversal, the node is visited first, followed by its left child and then its right child. This can be visualized as Root - Left - Right.
C++
#include <iostream>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
Node(int data) {
this->data = data;
this->left = nullptr;
this->right = nullptr;
}
};
void preOrderTraversal(Node* root) {
if (root == nullptr) return;
// Visit the root node
cout << root->data << " ";
// Traverse the left subtree
preOrderTraversal(root->left);
// Traverse the right subtree
preOrderTraversal(root->right);
}
int main() {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node* root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
cout << "Pre-Order Traversal: ";
preOrderTraversal(root);
cout << endl;
return 0;
}
C
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* left;
struct Node* right;
};
void preOrderTraversal(struct Node* root) {
if (root == NULL) return;
// Visit the root node
printf("%d ", root->data);
// Traverse the left subtree
preOrderTraversal(root->left);
// Traverse the right subtree
preOrderTraversal(root->right);
}
struct Node* newNode(int data) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
int main() {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
struct Node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("Pre-Order Traversal: ");
preOrderTraversal(root);
printf("\n");
return 0;
}
Java
class Node {
int data;
Node left, right;
// Constructor
Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void preOrderTraversal(Node root) {
if (root == null) return;
// Visit the root node
System.out.print(root.data + " ");
// Traverse the left subtree
preOrderTraversal(root.left);
// Traverse the right subtree
preOrderTraversal(root.right);
}
public static void main(String[] args) {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
System.out.print("Pre-Order Traversal: ");
preOrderTraversal(root);
System.out.println();
}
}
Python
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def pre_order_traversal(root):
if root is None:
return
# Visit the root node
print(root.data, end=" ")
# Traverse the left subtree
pre_order_traversal(root.left)
# Traverse the right subtree
pre_order_traversal(root.right)
if __name__ == "__main__":
# Create the following binary tree
# 1
# / \
# 2 3
# / \
# 4 5
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
print("Pre-Order Traversal: ", end="")
pre_order_traversal(root)
print()
C#
using System;
class Node {
public int data;
public Node left, right;
public Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void PreOrderTraversal(Node root) {
if (root == null) return;
// Visit the root node
Console.Write(root.data + " ");
// Traverse the left subtree
PreOrderTraversal(root.left);
// Traverse the right subtree
PreOrderTraversal(root.right);
}
static void Main(string[] args) {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
Console.Write("Pre-Order Traversal: ");
PreOrderTraversal(root);
Console.WriteLine();
}
}
JavaScript
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
function preOrderTraversal(root) {
if (root === null) return;
// Visit the root node
console.log(root.data + " ");
// Traverse the left subtree
preOrderTraversal(root.left);
// Traverse the right subtree
preOrderTraversal(root.right);
}
// Driver Code
let root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
console.log("Pre-Order Traversal:");
preOrderTraversal(root);
OutputPre-Order Traversal: 1 2 4 5 3
Time Complexity: O(N)
Auxiliary Space: If we don’t consider the size of the stack for function calls then O(1) otherwise O(h) where h is the height of the tree.
Below are some important concepts in Pre-Order Traversal:
In post-order traversal, the left child is visited first, then the right child, and finally the node itself. This can be visualized as Left - Right - Root.
C++
#include <iostream>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
Node(int data) {
this->data = data;
this->left = nullptr;
this->right = nullptr;
}
};
void postOrderTraversal(Node* root) {
if (root == nullptr) return;
// Traverse the left subtree
postOrderTraversal(root->left);
// Traverse the right subtree
postOrderTraversal(root->right);
// Visit the root node
cout << root->data << " ";
}
int main() {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node* root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
cout << "Post-Order Traversal: ";
postOrderTraversal(root);
cout << endl;
return 0;
}
C
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* left;
struct Node* right;
};
void postOrderTraversal(struct Node* root) {
if (root == NULL) return;
// Traverse the left subtree
postOrderTraversal(root->left);
// Traverse the right subtree
postOrderTraversal(root->right);
// Visit the root node
printf("%d ", root->data);
}
struct Node* newNode(int data) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
int main() {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
struct Node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("Post-Order Traversal: ");
postOrderTraversal(root);
printf("\n");
return 0;
}
Java
class Node {
int data;
Node left, right;
// Constructor
Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void postOrderTraversal(Node root) {
if (root == null) return;
// Traverse the left subtree
postOrderTraversal(root.left);
// Traverse the right subtree
postOrderTraversal(root.right);
// Visit the root node
System.out.print(root.data + " ");
}
public static void main(String[] args) {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
System.out.print("Post-Order Traversal: ");
postOrderTraversal(root);
System.out.println();
}
}
Python
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def post_order_traversal(root):
if root is None:
return
# Traverse the left subtree
post_order_traversal(root.left)
# Traverse the right subtree
post_order_traversal(root.right)
# Visit the root node
print(root.data, end=" ")
if __name__ == "__main__":
# Create the following binary tree
# 1
# / \
# 2 3
# / \
# 4 5
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
print("Post-Order Traversal: ", end="")
post_order_traversal(root)
print()
C#
using System;
class Node {
public int data;
public Node left, right;
public Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void PostOrderTraversal(Node root) {
if (root == null) return;
// Traverse the left subtree
PostOrderTraversal(root.left);
// Traverse the right subtree
PostOrderTraversal(root.right);
// Visit the root node
Console.Write(root.data + " ");
}
static void Main(string[] args) {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
Console.Write("Post-Order Traversal: ");
PostOrderTraversal(root);
Console.WriteLine();
}
}
JavaScript
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
function postOrderTraversal(root) {
if (root === null) return;
// Traverse the left subtree
postOrderTraversal(root.left);
// Traverse the right subtree
postOrderTraversal(root.right);
// Visit the root node
console.log(root.data + " ");
}
// Driver Code
let root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
console.log("Post-Order Traversal:");
postOrderTraversal(root);
OutputPost-Order Traversal: 4 5 2 3 1
Below are some important concepts in Post-Order Traversal:
In level-order traversal, the nodes are visited level by level, starting from the root node and then moving to the next level. This can be visualized as Level 1 - Level 2 - Level 3 - ....
C++
#include <iostream>
#include <queue>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
Node(int data) {
this->data = data;
this->left = nullptr;
this->right = nullptr;
}
};
void levelOrderTraversal(Node* root) {
if (root == nullptr) return;
queue<Node*> q;
q.push(root);
while (!q.empty()) {
Node* current = q.front();
q.pop();
// Visit the root node
cout << current->data << " ";
// Enqueue left child
if (current->left != nullptr) q.push(current->left);
// Enqueue right child
if (current->right != nullptr) q.push(current->right);
}
}
int main() {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node* root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
cout << "Level-Order Traversal: ";
levelOrderTraversal(root);
cout << endl;
return 0;
}
C
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* left;
struct Node* right;
};
struct QueueNode {
struct Node* treeNode;
struct QueueNode* next;
};
void enqueue(struct QueueNode** front, struct QueueNode** rear, struct Node* treeNode) {
struct QueueNode* newNode = (struct QueueNode*)malloc(sizeof(struct QueueNode));
newNode->treeNode = treeNode;
newNode->next = NULL;
if (*rear == NULL) {
*front = *rear = newNode;
return;
}
(*rear)->next = newNode;
*rear = newNode;
}
struct Node* dequeue(struct QueueNode** front, struct QueueNode** rear) {
if (*front == NULL) return NULL;
struct Node* treeNode = (*front)->treeNode;
struct QueueNode* temp = *front;
*front = (*front)->next;
if (*front == NULL) *rear = NULL;
free(temp);
return treeNode;
}
int isEmpty(struct QueueNode* front) {
return front == NULL;
}
void levelOrderTraversal(struct Node* root) {
if (root == NULL) return;
struct QueueNode* front = NULL;
struct QueueNode* rear = NULL;
enqueue(&front, &rear, root);
while (!isEmpty(front)) {
struct Node* current = dequeue(&front, &rear);
// Visit the root node
printf("%d ", current->data);
// Enqueue left child
if (current->left != NULL) enqueue(&front, &rear, current->left);
// Enqueue right child
if (current->right != NULL) enqueue(&front, &rear, current->right);
}
}
struct Node* newNode(int data) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
int main() {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
struct Node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("Level-Order Traversal: ");
levelOrderTraversal(root);
printf("\n");
return 0;
}
Java
import java.util.LinkedList;
import java.util.Queue;
class Node {
int data;
Node left, right;
// Constructor
Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void levelOrderTraversal(Node root) {
if (root == null) return;
Queue<Node> q = new LinkedList<>();
q.add(root);
while (!q.isEmpty()) {
Node current = q.poll();
// Visit the root node
System.out.print(current.data + " ");
// Enqueue left child
if (current.left != null) q.add(current.left);
// Enqueue right child
if (current.right != null) q.add(current.right);
}
}
public static void main(String[] args) {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
System.out.print("Level-Order Traversal: ");
levelOrderTraversal(root);
System.out.println();
}
}
Python
from collections import deque
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def level_order_traversal(root):
if root is None:
return
q = deque([root])
while q:
current = q.popleft()
# Visit the root node
print(current.data, end=" ")
# Enqueue left child
if current.left:
q.append(current.left)
# Enqueue right child
if current.right:
q.append(current.right)
if __name__ == "__main__":
# Create the following binary tree
# 1
# / \
# 2 3
# / \
# 4 5
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
print("Level-Order Traversal: ", end="")
level_order_traversal(root)
print()
C#
using System;
using System.Collections.Generic;
class Node {
public int data;
public Node left, right;
public Node(int item) {
data = item;
left = right = null;
}
}
class GFG {
public static void LevelOrderTraversal(Node root) {
if (root == null) return;
Queue<Node> q = new Queue<Node>();
q.Enqueue(root);
while (q.Count > 0) {
Node current = q.Dequeue();
// Visit the root node
Console.Write(current.data + " ");
// Enqueue left child
if (current.left != null) q.Enqueue(current.left);
// Enqueue right child
if (current.right != null) q.Enqueue(current.right);
}
}
static void Main(string[] args) {
// Create the following binary tree
// 1
// / \
// 2 3
// / \
// 4 5
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
Console.Write("Level-Order Traversal: ");
LevelOrderTraversal(root);
Console.WriteLine();
}
}
JavaScript
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
function levelOrderTraversal(root) {
if (root === null) return;
let queue = [root];
while (queue.length > 0) {
let current = queue.shift();
// Visit the root node
console.log(current.data + " ");
// Enqueue left child
if (current.left !== null) queue.push(current.left);
// Enqueue right child
if (current.right !== null) queue.push(current.right);
}
}
// Driver Code
let root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
console.log("Level-Order Traversal:");
levelOrderTraversal(root);
OutputLevel-Order Traversal: 1 2 3 4 5
Below are some important concepts in Level-Order Traversal:
Special Binary Tree Traversals
Quick Links :
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