Showing posts with label Java_Sorting_coding_Question. Show all posts
Showing posts with label Java_Sorting_coding_Question. Show all posts

Thursday, May 5, 2022

Question 85 : What is binary search? Can you write an algorithm to find an element in sorted array using binary search?

In this post, we will see how to perform binary search in java using divide and conquer method.When you want to find a value in sorted array, 

we use binary search and we will also see how to compute time complexity of binary search.

Question 84 : Implement Counting sort in java?

Counting sort is special sorting technique used to sort elements between specific range. Lets say elements belong to range 1 to K , then Counting sort can be used to sort elements in O(N) times.

Basic idea of counting sort to find number of elements less than X, so X can be put to its correct position

Question 83 : Implement shell sort in java?

Shell sort is in place comparison based sorting algorithm. It is generalization of insertion sort. It was invented by Donald shell.

It allows to sort elements which are far apart. In case of insertion sort, comparison happens between only adjacent elements but in shell sort, it avoid comparing adjacent elements until last steps. 

Last step of shell sort is ultimately insertion sort.
In short, it improves insertion sort by comparison and exchange elements that are far away.

Shell sort uses a sequence that can be referred as increment sequence. Shell sort makes multiple passes over array and sort number of equally sized array using insertion sort

Question 82 : Implement quick sort in java?

 In quick sort, we first choose a pivot and divide into two sublists,one will contain elements lower than pivot and other will have elements greater than pivot.

Question 81 : Do you know how to implement Heap sort?

 In this post, we will see how to implement heap sort in JAVA

I will divide heap sort in multiple parts to make it more understandable.

Question 80 : Can you write algorithm for merge sort and also do you know complexity of merge sort?

Merge sort is divide and conquer sorting algorithm. It is efficient, comparison based sorting algorithm.

Question 79 : Write an algorithm to implement selection sort sort?

Selection sort is an in-place comparison sorting algorithm. It is very simple to implement but it does not go well with a large number of inputs.

Question 78 : Write an algorithm to implement insertion sort?

Insertion sort  works by comparing values at index with all its prior elements.We place value at the index where there are no lesser value to the elements. So when you reach last element,we get a sorted array.

Tuesday, May 3, 2022

Question 77 : Write an algorithm to implement bubble sort?

 Bubble sort algorithm

Bubble sort works by iterating the first element to the last element, comparing two adjacent elements, and swapping them if they are not in the correct order. Each iteration places the next larger value in its correct place.

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS