Articles for category: Data Structures and Algorithms

Diagonal Traversal of Binary Tree

Problem Statement Given a binary tree $A$ containing $n$ nodes, consider diagonals (lines with a slope of $-1$) passing between the nodes and print all the diagonal elements in the binary tree belonging to the same line. Note: The diagonals with a slope of $-45\text{ degree}$ angle, will be like a $\backslash$. This question has ...

Josephus problem

Problem Statement There is n number of people standing in a circle. Numbering starts from 1 to n and is in the fixed clockwise direction. In each step, we are supposed to eliminate a person which is at the $k^{th}$ position from the current position such that only one man remains at the end who ...

Inversion Count in an Array

The Inversion count in an array indicates the number of element pairs (i, j) where i < j and A[i] > A[j], serving as a measure of the array’s unsortedness. Understanding Inversion count in an Array is essential for analyzing sorting algorithms’ efficiency and optimizing them, making count inversion a key concept in algorithm design ...

DBMS MCQ

Question: What is the Full Form of DBMS? Options: Answer: b) Database Management System. Explanation:The DBMS full form is Database Management System. It is software that is used to store, manipulate, and query records stored in a certain database. We have several types of database management systems such as NoSQL database management systems (for example ...

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