프론트엔드/자료구조 알고리즘
-
자바스크립트로 구현한 Tree, BFS, DFS프론트엔드/자료구조 알고리즘 2022. 3. 12. 01:07
자바스크립트로 구현한 Tree, BFS, DFS Tree class Node{ constructor(data){ this.data = data; //노드의 정보 this.children = []; // 자식'노드'가 들어있는 배열 } addChild(data){ this.children.push(new Node(data)); } removeChild(data){ this.children = this.children.filter(child => child.data === data ? false: true); } } class Tree{ constructor(){ this.root = null; // root도 노드이다. } } const t = new Tree(); t.root = new Node('a')..
-
자바스크립트로 구현한 Max Heap프론트엔드/자료구조 알고리즘 2022. 3. 12. 00:42
자바스크립트로 구현한 Max Heap 힙(heap)은 최댓값 및 최솟값을 찾아내는 연산을 빠르게 하기 위해 고안된 완전이진트리(complete binary tree)를 기본으로 한 자료구조(tree-based structure)다. 힙에는 두가지 종류가 있으며, 부모노드의 키값이 자식노드의 키값보다 항상 큰 힙을 '최대 힙', 부모노드의 키값이 자식노드의 키값보다 항상 작은 힙을 '최소 힙'이라고 부른다. 출처 : https://ko.wikipedia.org/wiki/%ED%9E%99_(%EC%9E%90%EB%A3%8C_%EA%B5%AC%EC%A1%B0) 힙 (자료 구조) - 위키백과, 우리 모두의 백과사전 1부터 100까지의 정수를 저장한 최대 힙의 예시. 모든 부모노드들이 그 자식노드들보다 큰 값을 ..
-
자바스크립트로 구현한 hash table프론트엔드/자료구조 알고리즘 2022. 3. 11. 16:38
자바스크립트로 구현한 hash table hash table 키를 값에 매핑할 수 있는 구조인, 연관 배열 추가에 사용되는 자료 구조이다. 해시 테이블은 해시 함수를 사용하여 색인(index)을 버킷(bucket)이나 슬롯(slot)의 배열로 계산한다. 출처 : https://ko.wikipedia.org/wiki/%ED%95%B4%EC%8B%9C_%ED%85%8C%EC%9D%B4%EB%B8%94 해시 테이블 - 위키백과, 우리 모두의 백과사전 ko.wikipedia.org class HashTable{ constructor(table_length){ this.table = new Array(table_length); this.size = 0; } _hash(key){ let hash = 0; for(l..
-
단일연결리스트로 구현한 Stack, Queue프론트엔드/자료구조 알고리즘 2022. 3. 10. 11:52
단일연결리스트로 구현한 Stack, Queue Stack first in first out // 단일연결리스트로 구현한 stack class Node{ constructor(value, next){ this.value = value; this.next = next; } } class Stack{ _size = 0; constructor(){ this.head = null; // 가장 위에 있는(가장 나중에 있는) 노드 this._size = 0; } get size(){ return this._size; } push(value){ const new_node = new Node(value, this.head); this.head = new_node; this._size++; } pop(){ if(this...