Articles for category: Data Structures and Algorithms

Program to Find Largest Element in an Array

Problem Statement You are given an array arr[] of size N, where N represents the number of elements in the array. The task is to write a program to find and determine the largest element within this array. Examples Example 1: Example 2: Example 3: Example Explanation In above all the examples, we are finding the largest element from the ...

Line Sweep Algorithm

The line sweep algorithm is based on the idea of using a vertical imaginary line that moves in the rightward direction upon the occurrences of certain events defined by the current problem at hand. The line sweep algorithm is used to solve problems such as closest pair, line segment intersections, the union of rectangles, convex hull, Manhattan ...

Isomorphic graph

This article explains the concept of isomorphism in graph data structures. A pair of given graphs are said to be isomorphic graphs if they are structurally equivalent. It means there exists a mapping(bijection) between the vertices of the two graphs. Using this mapping, one graph can be converted into the other by replacing its vertices ...

Job Sequencing Problem

Problem Statement You are given a set of N jobs, where each job is having a deadline and a profit associated with it. You can only earn a profit if you complete the job within its given deadline. You can perform the job either before the deadline or strictly on the deadline, not after that. Rules: Input Format: The jobs will be ...

Longest Common Prefix

The common prefix between the two most dissimilar strings is the longest common prefix for an array of strings. For instance, there is no common prefix in the array apple, ape, and zebra since the two most distinct strings in the array, “ape” and “zebra,” do not share any initial letters. In this article, we will learn about the ...

Largest Subarray with 0 Sum

Problem Statement Given the array $ar[]$ of size, $n$ has positive and negative integers. From the array $ar[]$, find the length of the largest subarray having a 0 sum. As we have to find the length of the largest subarray. So, first of all, it is required to understand what is a subarray Subarray :A ...

Merge K Sorted Arrays

Problem Statement k number of arrays are given, the task is to merge all the given integer arrays in such a manner that the resultant array is sorted in the runtime only. Note: arrays are of equal size. Example: Output: Explanation The array at the output is sorted by combining elements of all the three ...

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