Algorithm - Interview Questions and Answers for 'Sorting' | Search Java Interview Question - javasearch.buggybread.com

# Search Interview Questions

More than 3000 questions in repository.
There are more than 900 unanswered questions.
Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

Algorithm - Interview Questions and Answers for 'Sorting' - 13 question(s) found - Order By Rating

Q1. Explain In place sorting algorithm ?Algorithm2018-09-16 16:27:18

Help us improve. Please let us know the company, where you were asked this question :

sorting algorithm   in place sorting algorithm     Asked in 2 Companies

Q2. How to sort objects based on one of the field ?Core Java2018-07-04 16:23:09
Ans. Using comparable and comparator and sorted collections like TreeSet or TreeMap.

or

use stream api from java 8 onwards which internally refers to comparable and comparator through lambda expressions

Help us improve. Please let us know the company, where you were asked this question :

sort  sorting  comprator  comparable  treeset  treemap  sorting collections     Asked in 1 Companies      Basic        frequent

Q3. Write code to sort an array.Algorithm2018-07-04 16:15:16

Help us improve. Please let us know the company, where you were asked this question :

array  sorting     Asked in 16 Companies      basic        frequent

Q4. Write a program for bubble sort.2017-07-27 12:00:59
Ans. public class BubbleSort {
public static void main(String[] args){
int a[] = {1,3,4,5,7,8,2,6};

for(int i=0;i<a.length-1;i++){
for(int j=i;j<a.length;j++){
if(a[j] < a[j]){
int temporary = a[j];
a[j] = a[i];
a[i] = temporary;
}
}
}

for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
}

Help us improve. Please let us know the company, where you were asked this question :

sorting algorithm  Bubble sort

Q5. Write a Program for selection sort.2017-07-27 11:59:53
Ans. public class SelectionSort {
public static void main(String[] args){
int a[] = {1,3,4,5,7,8,2,6};

for(int i=0;i<a.length;i++){
for(int j=0;j<i;j++){
if(a[j] > a[j]){
int temporary = a[j];
a[j] = a[i];
a[i] = temporary;
}
}
}

for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
}

Help us improve. Please let us know the company, where you were asked this question :

sorting algorithm  selection sort

Q6. Explain bubble sort.Algorithm2017-03-03 14:28:51
Ans. array is traversed from first element to last element. Here current element is compared with next element. If current element is greater than next element it is swapped.

Help us improve. Please let us know the company, where you were asked this question :

sorting  bubble sort     Asked in 1 Companies

Q7. Write any sorting algorithm.Algorithm2017-01-25 13:41:50

Help us improve. Please let us know the company, where you were asked this question :

Algorithm  Sorting Algorithm     Asked in 4 Companies      basic        frequent

Q8. Write an algorithm / java program for Heap Sort ?Algorithm2017-01-19 15:36:18

Help us improve. Please let us know the company, where you were asked this question :

sorting  heap sort     Asked in 1 Companies        frequent

Q9. Explain various Searching and Sorting Algorithms ?Algorithm2017-01-11 16:05:54

Help us improve. Please let us know the company, where you were asked this question :

Search Algorithm  Sorting Algorithm     Asked in 2 Companies      basic        frequent

Q10. If I try to add Enum constants to a TreeSet, What sorting order will it use ?
Ans. Tree Set will sort the Values in the order in which Enum constants are declared.

Help us improve. Please let us know the company, where you were asked this question :

java   collections   set   treeset   enum   sorting   technical lead

Q11. Which sorting algorithm is used by Collections.sort() in Java ?Core Java
Ans. The sorting algorithm is a modified mergesort. This algorithm offers guaranteed n log(n) performance.

Help us improve. Please let us know the company, where you were asked this question :

java   algorithm   collections   collections.sort   sorting algorithm      expert

Try 1 Question(s) Test

Q12. Collections.sort can only be performed on ..

a. Set
b. List
c. Map
d. Any Collection implementation
Core Java
 Anonymous
Ans. List

Help us improve. Please let us know the company, where you were asked this question :

collections   java   sorting

Try 2 Question(s) Test

Q13. Write code to sort elements of a set

Help us improve. Please let us know the company, where you were asked this question :

set  collections  sorting  treeset  code  coding

## Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.