[Java] Quick Sort Algorithm

Quick sort is a very fast sort algorithm, which it’s used “divide and conquer strategy” to sort the data. On the average and best case, it has O(n log n) time complexity, on worst case, it has O(n^2) time complexity. And it is unstable sorting.

閱讀更多[Java] Quick Sort Algorithm

(Visited 14 times, 1 visits today)

[Java] Selection Sort Algorithm

Time complexity of Selection Sort Algorithm in best case , worst case and average are all O(n^2) and need O(1) extra space. Selection sort can be implemented in stable sort or not.

閱讀更多[Java] Selection Sort Algorithm

(Visited 22 times, 1 visits today)

[Java] 100 – The 3n + 1 problem

題目連結:UVa Online Judge

本來中間的if/else判斷是用

if(n%2 == 1)
    int number = (3 * n) + 1;
else
    n = n/2;

閱讀更多[Java] 100 – The 3n + 1 problem

(Visited 21 times, 1 visits today)

[Java] Binary search algorithm

Binary search algorithm time complexity is O(log2(n)), and this algorithm requires that source array is sorted in order to work correct.

Algorithm is quite simple. It can be done either recursively or iteratively:

1.get the middle element;
2.if the middle element equals to the searched value, the algorithm stops;
3.otherwise, two cases are possible:
   (1)searched value is less, than the middle element. In this case, go to the step 1 for the part of the array, before middle element.
   (2)searched value is greater, than the middle element. In this case, go to the step 1 for the part of the array, after middle element.

閱讀更多[Java] Binary search algorithm

(Visited 25 times, 1 visits today)