Articles for category: Data Structures and Algorithms

Applications of Stack in Data Structure

A Stack is a linear data structure that processes elements in a last in first out (LIFO) manner, with the most recent element always on top. Push() and pop() operations are usually supported. Applications of stack in data structure includes expression evaluation, backtracking, recursion and the implementation of other data structures such as queues. Applications of Stack ...

Advanced Data structures

Data structures are fundamental components in data science, enabling efficient storage, organization, and manipulation of information. Mastery of advanced data structures is vital for programmers, as they underpin the design and implementation of effective algorithms and software systems. The efficiency of algorithms often hinges on the choice and implementation of data structures, influencing both time ...

Majority Element in an Array

Problem Statement You are given an array arr[] containing n integers including duplicates. Write a program to find the majority element in an array if it is present. Else print no Majority Element Found. An element is called a majority element when it appears more than n/2 times in an array of length n. Example Input-1 Output-1 Explanation 9 appears 5 times which is ...

Time and Space Complexity of Binary Search

Binary Search is an efficient algorithm designed for searching within a sorted list of items. Its approach involves iteratively dividing the search space in half, until the target element found in the array. The time complexity of the Binary Search Algorithm is $O(log_2{n})$, Where n is the size of the sorted linear array. It means ...

Types of Trees in Data Structures

A tree represents a hierarchical arrangement of nodes, forming a non-linear data structure. Each node in the tree holds a value and points to its child nodes, creating a branching structure akin to a natural tree. This hierarchical organization facilitates efficient storage and retrieval of data. Types of Trees in Data Structure According to the ...

How to Reverse a Stack Using Recursion?

Given a stack, write a program to reverse the order of the elements inside the stack using recursion. The element at the top should be moved to the bottom and so on. This program must use only standard stack operations – push(item), pop(), top(), size(), and isEmpty(). Example: Input: $23, 56, 82, 90$ Output: $90, ...

Strassen’s Matrix Multiplication

Problem Statment Consider two matrices X and Y each of the size N*N. We want to calculate the resultant matrix Z which is formed by multiplying the given two matrices i.e, X and Y. Example Let’s consider the below matrices for multiplication. Matrix A has a size N*M and matrix B has a size A*B. ...

Suffix Arrays

Suffix arrays are very powerful data structures in terms of their applications in the field strings and string algorithms like pattern searching, string matching algorithms, the longest common prefix of two strings, counting the number of substrings, and in the field of biology some problems like DNA sequencing which uses suffix arrays to efficiently find the ...