Skip to content

The program is required to implement insertion, bubble, quick and radix sort algorithms on a list of words in lexicographic order

Notifications You must be signed in to change notification settings

SHAODOO/CPT212-2022_assignment1

 
 

Repository files navigation

CPT212-2022_assignment1


The program is required to implement insertion, bubble, quick and radix sort algorithms on a list of words in lexicographic order

1. BUBBLE SORT

1.1 Result

2022-07-03 15_51_38-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

1.2 Graph

2022-07-03 15_51_53-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

1.3 Time Complexity

2022-07-03 15_52_04-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

According to the graph from our experimental result, the best case time complexity of bubble sort is obtained under the condition that all the elements in the array list are sorted in alphabetical order while the average case time complexity of bubble sort is obtained under the condition that all the elements in the array list are arranged randomly. Then, the worst case time complexity of bubble sort is obtained under the condition that all the elements in the array list are sorted in descending alphabetical order.

From the graph, the curve of the worst case and average case show quadratic growth. Hence, we can say that the time complexity of the worst case and average for bubble sort is O(n2). On the other hand, the curve of the best case grows linearly in the beginning of the graph. However, the curve grows in quadratic manner after a certain point due to the number of inputs exceeding the best case possibility. Therefore, we conclude that the time complexity of the best case for bubble sort is O(n2) too.

2. QUICK SORT

2.1 Result

2022-07-03 15_55_20-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

2.2 Graph

2022-07-03 15_55_32-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

2.3 Time Complexity

2022-07-03 15_55_44-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

According to the graph, the first element has been selected as pivot in the quick sort. The best case time complexity of quick sort is obtained under the condition that all the elements in the array list are arranged randomly while the average case time complexity of quick sort is obtained under the condition that all the elements in the array list are sorted in alphabetical order. Then, the worst case time complexity of quick sort is obtained under the condition that all the elements in the array list are sorted in descending alphabetical order.

As we can see, the curve of the best case and average case grow in the way of log-linear in the graph. Hence, we can say that the time complexity of the best case and average case for quick sort is O(n*logn). On the other hand, the curve of the worst case shows quadratic growth in the graph. Therefore, we can conclude that the worst case time complexity for quick sort is O(n2).

3. INSERTION SORT

3.1 Result

2022-07-03 16_01_11-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 12 more pages - Personal -

3.2 Graph

2022-07-03 16_01_21-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 12 more pages - Personal -

3.3 Time Complexity

2022-07-03 16_01_33-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 12 more pages - Personal -

According to the result obtained from the graph, the best case time complexity of insertion sort is obtained under the condition that all the elements in the array list are sorted in alphabetical order. The average case time complexity of insertion sort is obtained under the condition that all the elements in the array list are arranged in random order. Then, the worst case time complexity of insertion sort is obtained under the condition that all the elements in the array list are sorted in descending alphabetical order. After that, n - 1 number of comparisons will be performed for every nth element as each element will have to compare with each other.

As we can see, the curve of the worst case and average case shows quadratic growth in the graph. Hence, we can say that the time complexity of the worst case and average case for bubble sort is O(n2). On the other hand, the curve of the best case grows linearly in the graph. Therefore, we can conclude that the best case time complexity for bubble sort is O(n).

4. RADIX SORT

4.1 Result

2022-07-03 16_05_21-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

4.2 Graph

2022-07-03 16_05_29-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

4.3 Time Complexity

2022-07-03 16_05_39-CPT212_ASSIGNMENT1_LSD_LZX_KKR_LPS - Google Docs and 11 more pages - Personal -

Based on the graph from our experiment, the best case time complexity of radix sort is obtained under the condition that all the elements in the array list are sorted in alphabetical order. The average case time complexity of radix sort is obtained under the condition that all the elements in the array list are arranged in random order. Then, the worst case time complexity of radix sort is obtained under the condition that all the elements in the array list are sorted in descending alphabetical order.

From the graph, the curves of three cases of radix sort exhibit the same pattern in the graph. As we can see from the graph, the curve for best case, worst case and average case grow linearly. Therefore, we can conclude that the best case, worst case and average case time complexity for radix sort is O(n + k).


Thank you

About

The program is required to implement insertion, bubble, quick and radix sort algorithms on a list of words in lexicographic order

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%