Articles for category: Data Structures and Algorithms

Delete a Node without Head Pointer

Problem Statement You are given a singly linked list and the reference to the node to be deleted in the linked list, write a program to delete that node from linked list. There is no information provided about the head pointer or any other node. The normal deletion would fail here as the linked list we ...

kth Largest Element in BST

Problem Statement We are provided with a Binary Search tree and the task is to find the $k^{th}$ largest element in BST (Binary Search Tree). Refer to the Example and Example Explanation sections for more details and the Approach section to understand how to find the $k^{th}$ largest element in bst. Example Example 1: The ...

Parenthesis Checker

Problem Statement A string expression of parenthesis with the letters "(", ")", "{", "}", "[", "]" is supplied to you. The expression is called balanced with respect to the parenthesis ifthe same type of closing brackets )", "}", "]" is used to close open brackets "(", "{", "[". The correct sequence in which they appear ...

Boundary Traversal of Binary Tree

Problem Statement A binary tree will be given in the problem and we need to find the boundary traversal of that binary tree.Boundary traversal of a binary tree means traversing the binary tree along the boundary. The boundary includes the left boundary, right boundary and leaf nodes. Therefore in the boundary traversal of binary trees ...

Next Greater Element

Problem Statement We are given an array of integers, and we need to find the next greater element of every array elements. So, we need to find and print the next greater element of every array element. Note: Refer to the Example and Example Explanation sections for more details and the Approach section to understand how to find the next greater ...

Find the Middle Element in Linked List

Problem Statement You are given the head of a linked list, write a program to Find middle element in linked list. When there are even number of nodes in linked list, then there would be two middle nodes, return the second middle node. Example Input-1 Output-1 Explanation Here, 3 is the middle node of the ...

Application of Queue in Data Structure

A Queue is an abstract linear data structure serving as a collection of elements that are inserted (enqueue operation) and removed (dequeue operation) according to the First in First Out (FIFO) approach. Takeaways Introduction to Queue A queue is a linear sequence of items arranged in an ordered fashion. It is based on the FIFO (First In First Out) i.e.i.e. item can only be inserted at ...

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