Articles for category: Data Structures and Algorithms

Flattening a Linked List

Problem Statement Given a Linked List of size N, where every node of the linked list has either of the two pointer or can have both pointer. The sublinked(vertical linked list) and the horizontal linked list is in sorted order.Flatten this linked list such that all the nodes appear in a single level(horizontally) and the ...

Leaders in an Array

Problem Statement Given an array arr of size n with all unique elements. Print all Leaders in the array in any order. Note: A leader is an element of the array if it is greater than all the elements to its right side in the array. The rightmost element is always a leader in an ...

Maximum Sum Increasing Subsequence

Problem Statement An array of positive integers of size n is given. write a program to find the maximum sum increasing subsequence in the given array. The maximum sum increasing subsequence is a subsequence of an integer array where the sum is maximum and all of the elements are sorted in non decreasing order. Example ...

Prims and Kruskal Algorithm

Overview Prim’s algorithm and Kruskal’s algorithm are greedy algorithms used to find the minimum spanning tree in a weighted graph. Prim’s and Kruskal’s algorithms have many use cases they are used in solving traveling salesman problems, LAN networks, TV networks, and in general for any network where we need to find the least cost subset ...

Longest Palindromic Substring

Problem Statement The Longest Palindrome in a String in one of the most classic problems in DSA. The problem statement goes like this: Given a string, find the maximum length substring of it that is a palindrome. Input: String Output: String Before we move on to examples and the solution to this problem, make a note of the ...

Introduction to Logarithms

Overview In this article, we are going to learn about Logarithms in programming. Before getting started with the topic, let us get a short overview of what is Logarithms. Logarithms: In mathematics, the inverse of an exponential function is called the logarithmic function. In simple terms, the logarithm is the exponent or power of any ...

Merge Sort for Linked Lists

Problem Statement Given a singly linked list, use the merge sort algorithm to sort the list in the ascending order of their node’s values. Example Input Output Example Explanation The nodes in the input are not arranged in any particular order, while they are arranged in ascending order of their value in the output. Constraints ...

Merge Two Sorted Linked Lists

Problem Statement Given two linked lists which are sorted in increasing order. Merge both lists into a single linked list which is also sorted in increasing order. Example Input : Output: Explanation As we can see that if we merge both lists and arrange them in increasing order, it will become 1->2->3->4->4->6->7->8->9. Constraints $1 <= ...

kth Largest Element in an Array

Problem Statement Given an integer k and an array of size n consisting of unique integers. Find the kth largest element in this array. Examples Input : 1 Output : 1 Input : 1 Output: 2 Explanation Constraints All the elements of the array are unique Approach – 1 : Sorting In this approach, we ...

What is the Hamiltonian Graph

Overview The hamiltonian graph is the graph having a Hamiltonian path in it i.e. a path that visits each and every vertex of the graph exactly once, such graphs are very important to study because of their wide applications in real-world problems. Hamiltonian graphs are used for finding optimal paths, Computer Graphics, and many more ...