What is the different between the insertion sort algorithm and bubble sort algorithm?
I have searched everywhere but I didn't find the exact answer
Insertion Sort divides your array in two parts, a sorted one and an unsorted one. The algorithm takes the first element of the unsorted part and inserts it in the correct place in the sorted part. Because it tries to place each element as they occur, the sorted part is possibly very often rewritten, which is rather costly.
Bubble Sort in contrast iterates over the array and compares two values at a time. The bigger (or smaller [depending on your implementation]) value gets pushed to the end of the array (it bubbles up) and then it looks at the next two values (the one it just bubbled up and the next one). When the algorithm worked through the array the biggest (or smallest) value is the last value in the array. It repeats this procedure (leaving sorted values at the end of the array untouched) until the array is sorted. If you don't swap the values each time, but just mark the biggest value, you can implement this with one swap each iteration.