본문 바로가기
반응형

#알고리즘 [Algorithm]47

[LeetCode] Valid Parentheses 📄 Vaild parentheses for Swift Source Code class Solution { func isValid(_ s: String) -> Bool { let confirm: [Character: Character] = ["(": ")", "{": "}", "[": "]"] var result: [Character] = [] for letter in s { if confirm.keys.contains(letter) { result.append(letter) continue } if let lastValue = result.last, let pair = confirm[lastValue], letter == pair { result.removeLast() continue } result.a.. 2021. 3. 21.
[Algorithm - Concept] AVL Tree (named after inventors Adelson-Velsky and Landis) [Algorithm - Concept] AVL Tree (named after inventors Adelson-Velsky and Landis) AVL 트리(AVL tree)는 가장 초기에 나온 균형 잡힌(balanced) 이진 탐색 트리이다. 1962년 G.M. Adelson-Velskii와 E.M. Landis 가 그들의 논문 "An algorithm for the organization of information" 을 통해 발표했고 그들의 이름을 따서 지어졌다. AVL 트리는 각각의 노드(node, 분기점)마다 왼쪽과 오른쪽 부분 트리(sub-tree)의 높이 차이에 대한 정보를 가지며 부분 트리의 높이 차이가 1보다 크지 않은 성질을 가진다. 균형 잡힌 AVL 트리는 n개의 원소가 있을 때 O(l.. 2019. 9. 4.
[탐색] 깊이 우선 탐색 (DFS, Depth First Search) [탐색] 깊이 우선 탐색 (DFS, Depth First Search) 깊이 우선 탐색(depth-first search: DFS)은 맹목적 탐색방법의 하나로 탐색트리의 최근에 첨가된 노드를 선택하고, 이 노드에 적용 가능한 동작자 중 하나를 적용하여 트리에 다음 수준(level)의 한 개의 자식노드를 첨가하며, 첨가된 자식 노드가 목표노드일 때까지 앞의 자식 노드의 첨가 과정을 반복해 가는 방식이다. Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as.. 2019. 8. 29.
[Algorithm - Concept] 플로이드-워셜 알고리즘 (Floyd-Warshall Algorithm) [Algorithm - Concept] 플로이드-워셜 알고리즘 (Floyd-Warshall Algorithm) 컴퓨터 과학에서, 플로이드-워셜 알고리즘(Floyd-Warshall Algorithm)은 변의 가중치가 음이거나 양인 (음수 사이클은 없는) 가중 그래프에서 최단 경로들을 찾는 알고리즘이다. 알고리즘을 한 번 수행하면 모든 꼭짓점 쌍 간의 최단 경로의 길이(가중치의 합)을 찾는다. 알고리즘 자체는 경로를 반환하지는 않지만, 알고리즘을 약간만 변형시키면 경로를 찾을 수 있다. 이 알고리즘의 일부 버전은 관계 R의 추이적 폐포를 찾거나, 가중 그래프의 모든 꼭짓점 쌍 간의 최대 폭 경로를 (슐츠 선거 제도와 결합해서) 찾는 것이 가능하다. In computer science, the Floyd–Wa.. 2019. 8. 29.
반응형