Algorithm

김성렬 교수님의 알고리즘 수업 리뷰 + 알고리즘 문제풀이
📝 개요 (1) 자식 노드 갯수가 2개 이하로 (2) 왼쪽 자식은 모두 나보다 값이 작고 (3) 오른쪽 자식은 모두 나보다 값이 큰 그리고 모든 자식 노드 또한 위 3가지 성질을 갖는 자료구조. When to use? (1) Local Search getNextNode (next Largest key except myself) Range Search ex) 1~100 中 5~15 (2) Implements Data structure Set, Binary Heap, Priority Queue 👨‍💻 Impelment (C++) 왼쪽, 오른쪽 자식뿐만 아니라 부모노드와 연결도 킵 BST.h BST.cpp main.cpp Key Point (Delete Node) 가장 까다로운 부분이기 때문에 그림과 함께 정..
🔒 문제 💭 생각의 흐름 중복을 허용하지 않기 때문에 같은 Key 값을 발견하면 바로 root를 리턴한다. 최종 삽입위치에 노드를 생성하고 부모가 자식을 가리키는 포인터를 지정해야 하므로 자식 노드로 내려갈 때마다 부모 노드를 킵해야한다. 🔑 풀이 Node* insert(Node* root, int Key) { Node* parent = root; Node* tempNode = root; while (tempNode != nullptr) { parent = tempNode; if (Key == tempNode->data) return root; else tempNode = (Key data) ? tempNode->left : tempNode->right; } if (parent->d..
🔒 문제 🧠 생각의 흐름 입력값에 "위치가 같은 두 점은 없다" 라는 부분에서 중복 값 저장은 신경쓸 필요가 없다는 것을 알 수 있다. 총 2가지로 풀이할 수 있다. (1) 일단 모든 숫자를 리스트나 배열에 담고 정렬하자 y 기준 정렬 -> x 기준 정렬 (stable) (2) SortedSet을 사용하자 ✔️ => 애초에 담길 때 부터 우선순위에 의해 자동 정렬이 되는 자료구조로 정렬의 우선순위인 'comparator' 만 정의해주면 된다. 🔑 풀이 import java.io.BufferedReader import java.io.BufferedWriter import java.io.InputStreamReader import java.io.OutputStreamWriter import java.util..
🔒 문제 🔑 풀이 (C++) #include #include #include #define MIN_VALUE 0 #define MAX_VALUE 255 using namespace std; bool has_only_digits(const string s){ // dot(.) == "\000" return s.find_first_not_of( "0123456789" ) == string::npos && (s != "\000"); } /* The function returns 1 if IP string is valid else return 0 You are required to complete this method */ int isValid(string s) { if (count(s.begin(), s.en..
What's Iterator? Container를 순회하는 포인터. When To Use? Convenient Programming loop without [] operator or minding 'range' Reusabililty we can reuse iterator when to change data container Dynamic add & remove (1) ⭐ 범위 신경쓰기 싫다. index 극혐이다. #include #include using namespace std; int main() { // Declaring a vector vector v = { 1, 2, 3 }; // Declaring an iterator vector::iterator i; int j; cout
🔒 문제 구분자가 .이 아니라 ' ' 공백이 여러개 들어왔을 경우에 뒤집는 풀이 🔑 풀이 (C++) #include #include using namespace std; string reverseWords(string S) { int endIndex = S.length(); string result = ""; while (endIndex > 0) { while (endIndex > 0 && S[endIndex--] == ' '); int startIndex = endIndex; while (startIndex > 0 && S[--startIndex] != ' '); if (startIndex != 0) { string word = S.substr(startIndex + 1, endIndex - start..
M_Falcon
'Algorithm' 카테고리의 글 목록 (6 Page)