Skip to content

Commit 0b2acfc

Browse files
authored
Merge branch 'TecheerB:master' into master
2 parents f847993 + 5488138 commit 0b2acfc

File tree

17 files changed

+404
-11
lines changed

17 files changed

+404
-11
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
### 선택 정렬 (Selection Sort)
2+
3+
- 현재 인덱스에 저장될 값을 찾아 정렬하는 방식
4+
5+
- 현재 위치에 저장될 값의 크기가 작다면 최소 선택 정렬 : 오름차순 정렬
6+
- 현재 위치에 저장될 값의 크기가 크다면 최대 선택 정렬 : 내림차순 정렬
7+
8+
- 기본 로직
9+
10+
1. 인덱스 맨 앞부터 전부 돌면서 현재 이후 값들의 최소값을 찾는다
11+
2. 최소값 찾으면 현재 인덱스 값과 바꾼다
12+
3. 1,2를 반복한다
13+
14+
- 시간복잡도
15+
: 전체 비교 필요! O(n^2)
16+
17+
<br>
18+
19+
### 삽입 정렬 (Insertion Sort)
20+
21+
- 새로운 원소 값을 현재 인덱스 이후의 값들과 비교하여 들어갈 위치를 찾는 방식
22+
23+
- 배열의 재배열!
24+
- 정렬 대상을 하나씩 늘리며 비교 = 해당 위치 앞까지 비교
25+
26+
- 기본 로직
27+
28+
1. 두번째 인덱스부터 시작 - 현재 인덱스를 변수로 저장 & 비교 인덱스는 현재 인덱스-1
29+
2. 새로운 원소값과 비교 인덱스의 값을 비교
30+
2-1. 새로운 원소가 작다면 현재 인덱스에 비교 인덱스 값 저장 & 비교 인덱스 -1
31+
2-2. 새로운 원소가 크다면 비교 인덱스+1에 원소 저장
32+
33+
- 시간복잡도
34+
: 마지막 인덱스가 i라고 가정, i-1까지 올 때 최악
35+
: 즉 데이터 개수가 n개일 때 n-1번의 반복 필요
36+
: (n(n-2))/2 = O(n^2)
37+
38+
<br>
39+
40+
### 합병 정렬 (Merge Sort)
41+
42+
- 분할 정복 기법(Divide and Conquer) 사용
43+
44+
- 문제를 2개로 분할 -> 정렬 후 -> 각각을 합쳐서 해결하는 방식
45+
- 분할은 각 문제(배열)의 크기가 1보다 작거나 같을 때까지 반복
46+
47+
- 기본 로직
48+
49+
- 분할 : 제일 왼쪽 index = left, 제일 오른쪽 index = right
50+
1. 현재 배열을 2개로 분할한다. A 크기 : (mid-left+1) & B 크기 : (right-mid)
51+
2. mid = 0 || mid = 1까지 반복
52+
- 합병
53+
1. 분할된 두 배열을 처음부터 돌면서 각각의 인덱스 값을 비교한다. A[i], B[j]에서 시작
54+
2. 비교 후 더 작은 값을 새로운 배열 C에 저장한다
55+
3. 더 작은 값을 가진 배열의 인덱스를 증가시켜 다음 값과 다시 비교한다. Ex. A[i+2], B[j]
56+
4. i, j 중 하나가 각 배열의 끝에 도달할 때까지 1~3을 반복한다.
57+
- 재귀
58+
1. 배열의 중간값((left+right)/2)을 구한다
59+
2. A[left, mid]에서 Merge sorting을 수행한다
60+
3. A[mid+1, right]에서 Merge sorting을 수행한다
61+
4. A left, mid, right에 대해 Merge를 수행한다
62+
63+
- 시간복잡도
64+
: 2/n 사이즈 배열을 원소 한쌍씩 비교하니까 n
65+
: 순환 호출 - 합병은 트리 레벨이므로 log2n (밑이 2)
66+
: O(nlogn)
67+
68+
<br>
69+
70+
### 힙 정렬 (Heap Sort)
71+
72+
- 완전이진트리 자료구조 '힙'을 이용한 정렬
73+
74+
- 최대힙 또는 최소힙 만든 후 모으면 정렬된다
75+
- n개 요소로 완전이진트리 만들기 -> 최대힙 만들기 -> 하나씩 꺼내서 배열의 뒤부터 삽입(내림차순)
76+
77+
- 기본 로직
78+
79+
- 힙 정렬 알고리즘
80+
1. n개 요소로 완전이진트리 만들기
81+
2. 최대 힙 만들기
82+
3. 힙에서 하나씩 요소를 꺼내 배열의 뒤부터 삽입(내림차순)
83+
4. 힙에서 삭제는 최대값부터 삭제
84+
- 최대힙 구현
85+
1. 정렬할 n개 요소를 1차원 배열에 저장
86+
2. 최대 힙 삽입 : 새로운 노드를 마지막 노드에 저장한 후 부모 노드들과 비교 & 교환하면서 위치 찾기
87+
3. 최대 힙 삭제 : 최대 힙의 최대값은 항상 루트 노드 = 삭제된 루트 노드 위치에 힙의 마지막 노드를 가져온 후, 비교하며 힙 재구성
88+
89+
- 시간복잡도
90+
: 힙 재구성시 레빌 logN에 대해 N번 연산 필요
91+
: O(nlogn)
92+
93+
<br>
94+
95+
### 퀵 정렬 (Quick Sort)
96+
97+
- 분할 정복 기법(Divide and Conquer) 사용, 다른 원소와의 비교를 통해 정렬한다
98+
99+
- pivot point 기준값을 이용한 순환적 기법
100+
- 순환 호출이 진행될 때마다 최소 하나의 원소의 위치가 정해진다
101+
102+
- 기본 로직
103+
104+
- 분할
105+
1. 배열 안에서 한 요소(pivot point) 선택
106+
2. 피봇값과 배열값을 비교하면서 피봇 기준으로 작은건 왼쪽, 큰건 오른쪽으로 이동
107+
- 정복
108+
1. 피봇을 제외한 분할된 부분 배열, 왼쪽 배열과 오른쪽 배열에 대해 부분 배열의 크기가 0또는 1이 될 때까지 순환 호출로 각각 분할/정복 과정 반복
109+
- 결합
110+
1. 정렬된 부분 배열들을 하나의 배열로 합친다
111+
112+
- 시간복잡도
113+
: 원소 개수 n = 2^k일 때, 순환 호출의 깊이는 log2n (밑이 2)
114+
: 각 순환 호출마다 전체를 비교하므로 N
115+
: O(nlogn)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] solution(int[] array, int[][] commands) {
5+
int[] answer = new int[commands.length];
6+
7+
for(int i=0; i<commands.length; i++){
8+
int[] temp = new int[commands[i][1] - commands[i][0] + 1];
9+
for(int j=0; j<temp.length; j++){
10+
temp[j] = array[j+(commands[i][0]-1)];
11+
}
12+
Arrays.sort(temp);
13+
answer[i] = temp[commands[i][2]-1];
14+
}
15+
16+
return answer;
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public String solution(int[] numbers) {
5+
String answer = "";
6+
List<String> str = new ArrayList<>();
7+
8+
for(int i=0; i<numbers.length; i++){
9+
str.add(Integer.toString(numbers[i]));
10+
}
11+
12+
Collections.sort(str, (a,b) -> (b+a).compareTo(a+b));
13+
14+
if(str.get(0).equals("0")){
15+
return "0";
16+
}
17+
18+
for(String s : str){
19+
answer += s;
20+
}
21+
22+
return answer;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public String solution(String[] participant, String[] completion) {
5+
String answer = "";
6+
Map<String, Integer> map = new HashMap<>();
7+
8+
for(String str : participant){
9+
map.put(str, map.getOrDefault(str, 0)+1);
10+
}
11+
12+
for(String str : completion){
13+
map.put(str, map.get(str)-1);
14+
}
15+
16+
for(String key : map.keySet()){
17+
if(map.get(key) == 1){
18+
answer = key;
19+
}
20+
}
21+
22+
return answer;
23+
}
24+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public boolean solution(String[] phone_book) {
5+
boolean answer = true;
6+
Map<String, String> map = new HashMap<>();
7+
8+
Arrays.sort(phone_book);
9+
for(String phone_number : phone_book){
10+
map.put(phone_number, "1");
11+
}
12+
13+
for(String phone_number : phone_book){
14+
for(int i=0; i<phone_number.length(); i++){
15+
String str = phone_number.substring(0, i);
16+
if(map.containsKey(str)){
17+
return false;
18+
}
19+
}
20+
}
21+
22+
// Hash없이 푼다면 startsWith
23+
// Arrays.sort(phone_book);
24+
// for (int i=0; i<phone_book.length-1; i++) {
25+
// if (phone_book[i+1].startsWith(phone_book[i])) {
26+
// answer = false;
27+
// break;
28+
// }
29+
// }
30+
31+
return answer;
32+
}
33+
}

EunjiShin/eunji.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
3232
|일정|필수 주제|선택 주제|EASY|NORMAL|HARD|
3333
|:-:|:-:|:-:|:-:|:-:|:-:|
34-
|1주차 <br> (10.25 ~ 10.31)|정렬 <br> (정렬 알고리즘 <br> & 시간 복잡도)|스택/큐|[K 번째 수](https://programmers.co.kr/learn/courses/30/lessons/42748), <br> [수 정렬하기](https://www.acmicpc.net/problem/2750), [세 수 정렬](https://www.acmicpc.net/problem/2752)|[가장 큰 수](https://programmers.co.kr/learn/courses/30/lessons/42746), [H-Index](https://programmers.co.kr/learn/courses/30/lessons/42747), [시리얼 번호](https://www.acmicpc.net/problem/1431), <br> [공통 순열](https://www.acmicpc.net/problem/1622), [K번째 수 찾는 함수](https://www.acmicpc.net/problem/16455)|[전화번호 목록](https://www.acmicpc.net/problem/5052), <br> [버블 소트](https://www.acmicpc.net/problem/1377)|
35-
|2주차 <br> (11.01 ~ 11.07)|해시|||||
36-
|3주차 <br> (11.08 ~ 11.14)|완전 탐색|이분 탐색||||
37-
|4주차 <br> (11.15 ~ 11.21)|DFS/BFS|그래프||||
38-
|5주차 <br> (11.22 ~ 11.28)|DP|Greedy||||
34+
|1주차 <br> (10.25 ~ 11.7)|정렬 <br> (정렬 알고리즘 <br> & 시간 복잡도)|스택/큐|[K 번째 수](https://programmers.co.kr/learn/courses/30/lessons/42748), <br> [수 정렬하기](https://www.acmicpc.net/problem/2750), [세 수 정렬](https://www.acmicpc.net/problem/2752)|[가장 큰 수](https://programmers.co.kr/learn/courses/30/lessons/42746), [H-Index](https://programmers.co.kr/learn/courses/30/lessons/42747), [시리얼 번호](https://www.acmicpc.net/problem/1431), <br> [공통 순열](https://www.acmicpc.net/problem/1622), [K번째 수 찾는 함수](https://www.acmicpc.net/problem/16455)|[전화번호 목록](https://www.acmicpc.net/problem/5052), <br> [버블 소트](https://www.acmicpc.net/problem/1377)|
35+
|2주차 <br> (11.8 ~ 11.14)|해시||[완주하지 못한 선수](https://programmers.co.kr/learn/courses/30/lessons/42576), <br> [Duplicates](https://www.acmicpc.net/problem/15098)|[전화번호 목록](https://programmers.co.kr/learn/courses/30/lessons/42577), [위장](https://programmers.co.kr/learn/courses/30/lessons/42578), <br> [숫자 카드2](https://www.acmicpc.net/problem/10816), [듣보잡](https://www.acmicpc.net/problem/1764), [비밀번호 찾기](https://www.acmicpc.net/problem/17219)|[베스트 앨범](https://programmers.co.kr/learn/courses/30/lessons/42579), <br> [친구 네트워크](https://www.acmicpc.net/problem/4195)|
36+
|3주차 <br> (11.15 ~ 11.21)|완전 탐색|이분 탐색|[모의고사](https://programmers.co.kr/learn/courses/30/lessons/42840), [블랙잭](https://www.acmicpc.net/problem/2798), [분해합](https://www.acmicpc.net/problem/2231)|[소수 찾기](https://programmers.co.kr/learn/courses/30/lessons/42839), [카펫](https://programmers.co.kr/learn/courses/30/lessons/42842), [숫자야구](https://www.acmicpc.net/problem/2503), <br> [퇴사](https://www.acmicpc.net/problem/14501)|[테트로미노](https://www.acmicpc.net/problem/14500), [치킨배달](https://www.acmicpc.net/problem/15686)|
37+
|4주차 <br> (11.22 ~ 11.28)|DFS/BFS|그래프||||
38+
|5주차 <br> (11.29 ~ 12.5)|DP|Greedy||||
3939

4040
<br>
4141

@@ -45,10 +45,10 @@
4545
4646
| 참여자 | 1주차 | 2주차 | 3주차 | 4주차 | 5주차 |
4747
| --- | --- | --- | --- | --- | --- |
48-
| EunjiShin ||||||
49-
| RyanLee ||||||
48+
| EunjiShin |:white_check_mark:|:white_check_mark:||||
49+
| RyanLee |:white_check_mark:|||||
5050
| GnuPark ||||||
51-
| YoungjinShin ||||||
51+
| YoungjinShin |:white_check_mark:|:white_check_mark:||||
5252

5353
<br>
5454

RyanLee/Programmers/k번째.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Programmers;
2+
import java.util.*;
3+
public class k번째 {
4+
public int[] solution(int[] array, int[][] commands) {
5+
int[] answer = new int[commands.length];
6+
int order =0;
7+
for (int x=0; x <commands.length; x++){
8+
int i = commands[x][0];
9+
int j = commands[x][1];
10+
int k = commands[x][2];
11+
12+
int[] range = new int[j-i+1];
13+
14+
int z = 0;
15+
for(int y=i-1; y<j; y++){
16+
range[z++]=array[y];
17+
}
18+
Arrays.sort(range);
19+
answer[order++]=range[k-1];
20+
}
21+
return answer;
22+
}
23+
}

RyanLee/ryan.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

YoungjinShin/1주차/BOJ 16455.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
implemented with normal sort - bad time complexity
2+
the question is asking for a code that works in less than 0.2s.
3+
need to work with quick selection instead. - similar to quick sort.
4+
5+

0 commit comments

Comments
 (0)