Algorithm Study #5 (Sort)

jakeseo_me·2019년 3월 8일
0

java algorithm study

목록 보기
13/18

Sort

  • there are a lot of sort algorithms
  • selection, bubble, insertion, quick, heap and merge sort ...
  • use sort algorithm which has time complexity of O(NlgN)
  • it's better to use sort in STL than making myself
  • sort(begin, end)
    - it sorts between begin and right before the end
    • function that sorts begin, end
  • it is usually used for sorting before solving problems
  • implementation code in C++

Sort Numbers 2

  • boj.kr/2751
  • sorting the number of N
  • sort in Java (using built-in sort algorithm)

Sort Coordinates

  • boj.kr/11650
  • solution in Java

Sort coordinates 2

  • boj.kr/11651
  • solution is almost the same as above one

Stable Sorting

  • When there are some cards like this
    - 7♠, 5♥, 2♥, 5♠
    ♦ ♣
  • When cards are sorted in the order in which numbers are increasing
    - how would be the order of 5♥ and 5♠
    - it can be like
    - 2♥, 5♥, 5♠, 7♠
    - it retains the order of input (Stable)
    - 2♥, 5♠, 5♥, 7♠
    - it doesn't retain the order of input (Unstable)
    - we couldn't expect what would be the first between heart and spade
  • An alignment algorithm that retains the order before sorting when there is the same thing is called a Stable Sorting algorithm.
  • Stable Sort Algorithm
    - Merge Sort
    • STL stable_sort

Order by age

  • boj.kr/10814
  • code in Java
  • java doesn't have basic stable sort. so i just added order to class
  • in C++, we can use tuple and make this with only one line of code

Korean English Mathematics

  • sort but more complicated conditions
  • code in java
profile
대전에 있는 (주) 아이와즈에서 풀스택 웹개발자로 일하고 있는 서진규입니다. 주로 Jake Seo라는 닉네임을 많이 씁니다.

0개의 댓글