Construct an array from it’s pair sum array

Construct an array from it’s pair sum array In this post we deal with the problem of constructing the original array from the array in which the sum of all pairs that can be made from the input array are given. Construct an array from it’s pair sum array Problem Statement: Given a pair-sum array… Read More »

Swap two given nodes in linked list

Swapping given nodes in linked list Problem statement for swapping two nodes in linked list: Given a singly linked list and the data of any two nodes of the linked list, you have to swap the nodes of the linked list without swapping data. Swap nodes of linked list Example: Consider a singly linked list… Read More »

Swap data of adjacent nodes in a linked list

Pairwise swap data of adjacent nodes in a linked list Problem statement for swapping data of adjacent nodes in a linked list: Given a singly linked list, you have to swap the data of adjacent nodes without changing the links between the nodes. Pairwise swap data of adjacent nodes in a linked list Example: Consider a singly linked… Read More »

Remove duplicates in a Binary Search Tree

Remove duplicate nodes in a Binary Search Tree (BST). Problem statement to remove redundant nodes in a Binary Search Tree. Given a binary search tree (BST), remove the redundant nodes to obtain a tree without the duplicate elements. Example: INPUT: array: 1,5,8,10,10,12,15,20,20,20 OUTUT: 10(2) / \ 5 15 / \ / \ 1 8 12 20(3)… Read More »

Find number of pairs(x,y) in an array such that x^y > y^x

Find number of pairs(x,y) in an array such that xy > yx In this post we find solution to the problem of finding number of pairs in the given array such that they satisfy the condition that xy > yx. Find number of pairs(x,y) in an array such that xy > yx Problem Statement : Given… Read More »

Delete an Array Element(using one and two traversals)

Delete an Array Element In this post we deal with the common problem of deleting an element fro the array using not only two but one traversal too. Delete an Array Element Problem Statement: Given an array of n integers ,we need to delete a given element of the array. We can delete an array… Read More »

Rearrange a given linked list

Rearrange list in-place Problem statement to rearrange list: Given a singly linked list, rearrange list in-place, such that, starting from the last node, nodes are alternately placed in the beginning of list. Rearrange list Example: Consider a singly linked: 7-> 3-> 9-> 4-> 2-> 8-> 6-> NULL Resultant linked list should be 7-> 6-> 3->… Read More »

Swap adjacent nodes of linked list

Pairwise swap nodes of a linked list Problem statement for swapping adjacent nodes of linked list: Given a singly linked list, you have to swap each pair of nodes starting from the head node. Pairwise swapping nodes of linked list Example: Consider a singly linked list 2-> 8-> 1-> 9-> 6-> 5-> 3-> 7-> NULL… Read More »

Sorted Linked List to balanced Binary Search Tree

Sorted Linked List to balanced Binary Search Tree (BST). Problem statement to create a Binary Search Tree from a sorted linked list. Given a singly linked list in a sorted order, create a balanced binary search tree (BST). Example: INPUT: Linked List: 1->5->8->10->12->15->20 OUTUT: 10 / \ 5 15 / \ / \ 1 8 12 20 Create… Read More »

Print common nodes in two Binary Search Trees

Print common nodes in two Binary Search Trees Problem statement to print common nodes in two Binary Search Trees (BST). Given two binary search trees, print all the elements that are common in both the trees. Example: INPUT:Tree 1 10 / \ 5 15 / \ / \ 1 8 12 20 Tree 2 7… Read More »