Articles for category: Data Structures and Algorithms

Intersection of Two Arrays

Intersection Of Two Arrays Given two arrays Arr1[] and Arr2[] of length n and m, respectively. The task is to find the intersection of elements of Arr1 and Arr2. The intersection is the list of common and distinct elements between Arr1 and Arr2. The intersection list can be in any order. Example Input: Output: Explanation: Common elements between Arr1 and Arr2 is 1, 2, 3, 4, 5. So, [1, ...

Median of Array

Problem Statement An unsorted array of size n is given. write a program to find the median of an array. The median of array is the middle element of a sorted array in case of odd number of elements in an array and average of middle two elements when the number of elements in an array is even. Example Input-1 Output-1 ...

How to Sort a Stack ?

Sort a stack involves the task of arranging the elements within a stack in a specific order, either ascending or descending, using only a limited set of stack operations like push, pop, and peek. The goal is to achieve this sorting without utilizing extra data structures, such as arrays or lists. The challenge lies in ...

Huffman Coding

When you want to send files or store the files on a computer, if the size is very huge we generally compress it and store it. One way of compressing these files is using Huffman Coding which is a greedy-based algorithm that is also known as variable-length coding or lossless data compression technique. Introduction to ...

Directed Graph

A graph is a non-linear data structure. It consists of several nodes, also referred to as vertices. The nodes of a graph are connected through edges. A graph in which there’s associated a sense of a specific direction with each edge is referred to as a directed graph. Directed graphs, from graph theory, are extensively used ...

Fizz Buzz Program

The FizzBuzz problem, a common coding exercise, involves iterating from 1 to n. For each integer, print “Fizz” if it’s a multiple of 3, “Buzz” if a multiple of 5, “FizzBuzz” if divisible by both 3 and 5, and the number itself if none of these conditions apply. Creating a FizzBuzz program efficiently handles these ...

How to Move All Zeroes to End of Array?

Given an array of random numbers and zeros, arrange the array such that all the numbers restoring their order are moved in front and move all zeros to end of array. There are so many ways to solve this problem. We can make use of additional arrays, pointers, partitions, etc. Example to Understand Let us ...

Graph Algorithms

Graph algorithms are vital for analyzing interconnected data structures, enabling tasks like pathfinding and connectivity analysis in social networks and GPS systems. From route optimization to recommendation engines, they drive insights and optimizations across various domains. Their applications extend to fields like bioinformatics and logistics, showcasing their broad relevance in modern computing and problem-solving. What ...