What is insertion sorting?



What is insertion sorting?..

Answer / Md Irshadur Rahman

Insertion Sort is a simple sorting algorithm that sorts an array by repeatedly taking one element from the unsorted part of the array and inserting it into the correct position in the already sorted part. It is most efficient when the input is nearly sorted.nnExample:nvoid insertionSort(int arr[], int n) {n for (int i = 1; i < n; i++) {n int key = arr[i];n int j = i-1;n while (j >= 0 && arr[j] > key) {n arr[j+1] = arr[j];n j--;n }n arr[j+1] = key;n }n}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What do you mean by abstraction. Explain your answer?

5 Answers  


What is binary object model?

1 Answers  


Can a constructor return a value?

2 Answers  


Explain the difference between c++ and java.

1 Answers  


What is pure virtual function? Or what is abstract class?

1 Answers  


What are static member functions?

1 Answers  


When is the destructor called?

1 Answers  


What is a sequence in c++?

1 Answers  


Explain the virtual inheritance in c++.

1 Answers  


What is the exit function in c++?

1 Answers  


What do you mean by abstraction in C++?

1 Answers  


Why do we use constructor?

1 Answers  


Categories