/SortingMethod_Project

Learning and implementing insertion sort and compareTo method

Primary LanguageJavaMIT LicenseMIT

SortingMethods

Learned and implemented sorting algorthims such as collection, selection, bubble, insertion, merge, quick, and bucket sort.

Selection sort:

  • iterative comparison
  • loop until the condition is satisfied

Bubble sort:

  • iterative comparison, compariong data-set from one end to other
  • compares adjacent pairs of elements
  • loop until one traversal step is finished and repeats array length times

Insertion sort:

  • iterastive sorting method, repeats until no input elements remain
  • removes one element from the array list and finds the best location to insert it

Merge sort:

  • divide and conquer
  • divides array into two arrays and compare
  • when array list is sorted, merge sorted arrays together
  • common way is using resurive divide and conquer method

Quick sort:

  • uses pointers, numbers used to compare and sort
  • left pointer used to scan rightward of arraylist
  • right pointer used to scan leftward of arraylist

Bucket sort:

  • method is not generic because it is restricted for specific data
  • avoids comparison by creating and distributing elements into buckets
  • treats elements as if they were strings of the same length
  • group elements by a specific digit or character oof a string
  • placed into buckets based on the matching key

Used generic and comparable for sorting methods.

Used System.arraycopy() method to copy the content of initial array with pre-set size.

Compared the execution time of an Integer type dataset.

image image image