나를 위한 면접 (ALL)
실무에 치이느라 기본적인 걸 까먹을까봐 정리해보자 정보처리 에서 컴퓨터 기초를 보면 되고. 지극히 주관적이라 정답이 아닐 수 있습니다
수학
미적분
편미분까진 안물어보더라
베이지안 확률
사후확률 = 가능도 * 사전확률 / 증거
// 붉은 점이 얼굴에 보일 때 수두 환자일 확률은 어떻게 구할까?
P(수두 | 붉은점) = P(붉은 점 | 수두) * P(수두) / P(붉은점)
자료구조
B Tree
m-원 트리의 단점임 한쪽으로 편중된 트리를 생성되는 경우를 보완하고자 루트노드로부터 리프노드의 레벨을 같도록 유지한 트리
BASIS FOR COMPARISON | B-TREE | BINARY TREE |
---|---|---|
Essential constraint | A node can have at max M number of child nodes(where M is the order of the tree). | A node can have at max 2 number of subtrees. |
Used | It is used when data is stored on disk. | It is used when records and data are stored in RAM. |
Height of the tree | logM N (where m is the order of the M-way tree) | log2 N |
Application | Code indexing data structure in many DBMS. | Code optimization, Huffman coding, etc. |
space complexity B-tree is O(n). Insertion and deletion time complexity is O(logn).
B+ Tree
B+은 index node와 data node로 구성
B* Tree
B-tree의 경우에 각 노드가 최소한 반 이상 차 있어야 하는 조건을 각 노드가 최소한 2/3이상 차있어야 한다로 변경하면 이것이 B*tree이다
공간 활용도를 높일 수 있다. 출처
Binary Tree
모든 노드의 차수가 2 이상을 넘지 않는 트리를 말한다, 왼쪽자식노드는 부모노드의 값보다 작 이야하며 오른쪽 자식노드는 부모노드의 값보다 커야한다.
Binary Search Tree
이진탐색(binary search)과 연결리스트(linked list)를 결합한 자료구조의 일종입니다. 이진탐색의 효율적인 탐색 능력을 유지하면서도, 빈번한 자료 입력과 삭제를 가능하게끔 고안됐습니다.
- 모든 원소는 서로 다른 유일한 키를 가짐
- 왼쪽 서브트리에 있는 원소들의 값은 그 루트의 값보다 작음
- 오른쪽 서브트리에 있는 원소의 값들은 그 루트의 값보다 큼
- 왼쪽 서브트리와 오른쪽 서브트리도 이진 탐색 트리임
O(n), 완전 이진 트리에 가까울 수록 O(log2(n))
Insertion Sort
앞에서부터 하나씩 비교하여 위치를 삽입
O(n^2)
function insertionSort(unsortedList) {
const len = unsortedList.length;
for (let i = 1; i < len; i++) {
// Copy of the current element.
const tmp = unsortedList[i];
// Check through the sorted part and compare with the number in tmp. If large, shift the number
for (var j = i - 1; j >= 0 && unsortedList[j] > tmp; j--) {
// Shift the number
unsortedList[j + 1] = unsortedList[j];
}
// Insert the copied number at the correct position
// in sorted part.
unsortedList[j + 1] = tmp;
}
}
Selection Sort
하나씩 뒤로 비교하여 최소값을 맨 앞으로 삽입
O(n^2)
function selectionSort(items) {
const length = items.length;
for (let i = 0; i < length - 1; i++) {
// Number of passes
// min holds the current minimum number position for each pass; i holds the Initial min number
let min = i;
// Note that j = i + 1 as we only need to go through unsorted array
for (let j = i + 1; j < length; j++) {
// Compare the numbers
if (items[j] < items[min]) {
// Change the current min number position if a smaller num is found
min = j;
}
}
if (min != i) {
// After each pass, if the current min num != initial min num, exchange the position.
// Swap the numbers
const tmp = items[i];
items[i] = items[min];
items[min] = tmp;
}
}
}
Quick Sort
pivot을 하나 뽑는다 보통 list.length / 2 -1 을 선택한다. pivot 앞에는 pivot보다 작게, pivot 뒤에는 pivot보다 크게 값을 바꿔치고 재귀를 돌린다
최악 O(n^2), 평균 O(nlogn)
const quickSort = (list) => {
if (list.length < 2) {
return list;
}
const pivot = list[0];
// const pivot = list[Math.floor(list.length / 2)];
const smaller = list.filter((item) => item < pivot);
const bigger = list.filter((item) => item > pivot);
return [...quickSort(smaller), pivot, ...quickSort(bigger)];
};