Articles for category: Data Structures and Algorithms

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

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