Skip to content

rifkyachong/Sorting-Array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sorting-Array

BACKGROUND

After learning about data structures and algorithms, the owner of this self-project became aware of the time-complexity and a new way to create a more efficient code. For example, the sorting array. I used to think that the computational procedure to create an array sorting function is to find the minimum number within the array, and then move it to the lowest index of the unsorted part of the array. But, this algorithm creates a Big-O time complexity of n squared which is bad. The sorting array in this project has a Big-O time complexity of n log(n), which is way better than the previous one.

GOAL

This is the project about creating the function/procedure to sort a given array. The goal of this project is:

  1. To create a two array sorting function/procedure (sorting proc with n log(n) complexity, sorting proc with n^2)
  2. To compare the duration of both of the function/procedure to run, plus std::sort() built-in function (#include )

RESULT

Mysortarraynlogn (sorting array function/procedure with apparently n log(n) time complexity) is already in the source c++ code. Mysortarratnn (sorting array function/procedure with apparently n^n log(n) time complexity) is already in the source c++ code.

Duration (length of the array = 100000):

  • Mysortarraynlogn : 21 s
  • Mysortarraynn : 12 s
  • std::sort() : <0.1s

CONCLUSION

The duration result doesn't show time complexity pattern, and the std::sort() built-in function is way faster than mysortarray function. There is a several possible reasons:
  1. the length of the array is not big enough to be considered "worst case scenario"
  2. the sorting code still not efficient because the owner of this self-project doesn't know already about how things work within c++.

The second reason is the most possible reason because the built-in function shows it's far more efficient code.

MYPLAN

LEARN LEARN LEARN!!!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages