Articles for category: Data Structures and Algorithms

Arithmetic Progression

A progression is a sequence of numbers that shows a pattern. The arithmetic progression is the most widely used mathematical progression, and it occurs when the difference between every two consecutive terms in a series is same. It is also known as an arithmetic sequence. Let’s say we have a series of even numbers (2, ...

Deterministic and Non-Deterministic Algorithms

An algorithm is a group of clearly defined steps used in programming to carry out certain tasks and produce desired results. When we refer to “a set of defined instructions” in this context, we mean that the user is aware of the results of those instructions if they are carried out as intended. Deterministic and ...

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 ...

Remove Duplicates from an Unsorted Linked List

Problem Statement Write a program to delete duplicate nodes present in an unsorted linked list. Print the original linked list, and the linked list obtained after the deletions. Example Consider the following linked list : After you remove duplicates from the linked list : Example Explanation The given unsorted linked list is : There are multiple occurrences ...

Subarray with Given Sum

Problem Statement An unsorted array nums and an integer sum k is given. Array has non- negative integers in it. Find out the continuous subarray which elements sums up to the given sum. There can be multiple such subarray with given sum, print out the first such subarray with given sum. If the subarray with ...

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 ...