Tag Archives: microsoft

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 »

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 »

Alternating merge of two linked lists

Alternating merge of two linked lists Problem statement for alternating merge of two linked lists: Given two singly linked lists, you have to merge two linked lists alternatively. Alternating merge of two linked lists Examples: Consider two singly linked lists where List 1 has lesser nodes: 1-> 8-> 3-> 7-> NULL 5-> 3-> 9-> 13->… Read More »

Sort linked list whose alternate nodes are in ascending and descending order

Sort list whose alternate nodes are in ascending and descending order without using sorting techniques Problem statement to sort list whose alternate nodes are in ascending and descending order: Given is a singly linked list whose alternate nodes are sorted in ascending and descending order i.e. nodes at odd positions form an ascending ordered linked list… Read More »

Insertion sort on a singly linked list

Insertion sort list Problem statement for insertion sort list (linked list): Given a singly linked list, you have to apply insertion sort on linked list. Insertion sort list Example: Consider a singly linked list 3-> 7-> 2-> 8-> 1-> 9-> 9-> 5-> 6-> NULL After insertion sort, the resultant list should be 1-> 2-> 3-> 5->… Read More »

Sorted insert in linked list

Sorted insert in linked list Problem statement for sorted insert in linked list: Given a sorted singly linked list, you have to insert nodes into the linked list in sorted order. Sorted insert in linked list Example: Consider a sorted singly linked list 1-> 2-> 6-> 19-> 28-> NULL After inserting, say 10, resultant linked… Read More »

Quicksort a linked list

Quicksort a linked list Problem statement to quicksort list: Given a singly linked list, you have to apply quicksort on the linked list. Quicksort list Example: Consider a singly linked list 23-> 3-> 1-> 9-> 10-> 8-> NULL Resultant list should be 1-> 3-> 8-> 9-> 10-> 23-> NULL Algorithm to quicksort list: Partition Select… Read More »

Binary Heaps: Introduction

Binary Heaps: Introduction A binary heap is a complete binary tree that satisfies the heap property. A heap can be classified further as either a max heap or a min heap. In a max heap, the keys of i.e. values held by parent nodes are always greater than or equal to those of the children and… Read More »