CodeByAkram: Sorting Algorithm
Showing posts with label Sorting Algorithm. Show all posts
Showing posts with label Sorting Algorithm. Show all posts
undefined 201

How to Sort a Stack using Merge Sort?

Interviewer may ask you this question if you have more than 3 years of experience in java development. So lets have a look, how to sort a stack using merge sort? Lets see sample input and output for better understanding: Algorithm For this we will follow these below two steps, 1. Break the stack into two parts...
undefined 201

Heap Sort in Java

Before looking into Heap Sort, let's understand what is Heap and how it helps in sorting. What is Complete Binary Tree? A Complete binary tree is a binary tree in which every node other than the leaves has two children. In complete binary tree at every level, except possibly the last, is completely filled, and all nodes...
undefined 201

Merge sort in Java

Related questions: Sort Linked List using Merge Sort, Given a Linked list, Sort it using Merge Sort Algorithm. Merge sort is preferred algorithm for sorting a linked list, lets see why, The way linked list is structured which doesn't allow random access makes some other algorithms like Quicksort perform poorly,...
undefined 201

Insertion Sort in Java

Given a array of integers, Sort it using Insertion sort. Lets understand what is the input and the expected output. Example Assume 5 persons of different heights are visiting at your office each at 5 minutes interval and you need to make them stand according to their heights(smaller to higher). How you will do? Below...
undefined 201

Selection Sort in Java

Selection Sort in Java The selection sort is the improvement over bubble sort by making only one exchange for every pass through the list. In this algorithm, find the smallest element from an unsorted list in each iteration and place that element at beginning of the list. Or find the largest element...
undefined 201

Bubble Sort

Bubble Sort The bubble sort makes multiple passes through a list and sometimes referred to as sinking sort. It is a simple sorting algorithm that compare the adjacent elements and swap their position if they are nor in intended order. Each pass through the list places the next largest value in its proper...