This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = ["find", "union", "is_group"] | |
def find(node: int, parents: dict[int, int]) -> int: | |
if parents[node] != node: | |
parents[node] = find(parents[node], parents=parents) | |
return parents[node] | |
def union(n1: int, n2: int, parents: dict[int, int]) -> None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
- Greatest Common Divisor(최대공약수) by Euclidean algorithm(유클리드 호제법) | |
> Reference: Wiki(https://namu.wiki/w/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C%20%ED%98%B8%EC%A0%9C%EB%B2%95) | |
- Least Common Multiple(최소공배수): 두 수의 곱 / 최대공약수 | |
""" | |
__all__ = ['gcd_while', 'gcd_recursive', 'lcm'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Additional Info | |
- 제곱수(1, 4, 9, 16, 25, 100, 121, ...)의 약수의 갯수는 항상 홀수이다. | |
""" | |
__all__ = ['get_divisors', 'get_n_divisors'] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
__all__ = ['get_cos_sim', 'apply_svd'] | |
def get_cos_sim(v1:np.ndarray, v2:np.ndarray) -> np.float64: | |
cos_sim = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2)) | |
return cos_sim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Good site for sorting algorithm visualization | |
- https://visualgo.net/en/sorting | |
""" | |
__all__ = [ | |
'bubble_sort', 'insertion_sort', 'selection_sort', | |
'quick_sort', 'merge_sort', | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = ['dfs_recursive'] | |
visited = set() | |
visited_orders = list() | |
def dfs_recursive(start_node: str, graph: dict[str, list[str]]) -> None: | |
if start_node in visited: | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
* DFS(Depth First Search) | |
- Used Data Structure: Stack | |
- Time Complexity: O(V+E) | |
* BFS(Breadth First Search) | |
- Used Data Structure: Queue | |
- Time Complexity: O(V+E) | |
""" | |
from collections import deque |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Binary search must be preconditioned that arr is sorted(desc). | |
""" | |
__all__ = ['bin_search', 'binary_search', 'binary_search_recursive', 'binary_search_recursive2'] | |
def bin_search(arr: list[int], target: int) -> int: | |
"""Ref: https://www.acmicpc.net/blog/view/109 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
__all__ = ['nms'] | |
def nms(pred_boxes, iou_thr=0.7, eps=1e-6): | |
"""Non-Maximum Suppression | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
__all__ = ['letterbox'] | |
def letterbox(img_arr, target_size, boxes=None): | |
"""Image Letterboxing (or Pillarboxing) | |