Eat Study Love

먹고 공부하고 사랑하라

Programming 56

Heap Implementation [1]

Algorithm Part의 기본적인 Data Structure인 Heap에 대해서 Implementation 연습을 시작해본다. Heap의 경우 Priority Queue라고도 생각하면 되고, Max/Min Heap으로 구분된다. 특징으론 Max Heap을 예로 들었을 때, Heap Data 구조에 입력되는 Data는 크기가 큰 순서(Max)대로 우선순위를 갖은 체 저장된다. 이 말은, Heap에서 특정 Data를 꺼낼 때(Deque) 가장 크기가 큰 녀석이 추출되는 것이다. 일반적으로 우리가 아는 queue구조에서 우선 순위만 선입선출이 아닌, Data 크기에 따라 결정된다는 것을 알고 있으면 된다. 따라서, 내부에 저장된 Data를 임의로 Search 할 수는 없지만 우리가 정한 Logic( Max..

Find Minimum Diameter After Merging Two Trees(Tree,Depth-First Search,Breadth-First Search,Graph)

https://leetcode.com/problems/find-minimum-diameter-after-merging-two-trees/description/?envType=daily-question&envId=2024-12-24There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates that there is an edge be..

Coding_Practice 2024.12.24

Linked list with Stack Node 문제

이번 문제는 Linked list를 C 코드로 구현하는 것인데, 특이점은 각 Node가 Stack 구조라는 것이다.즉 아래와 같이 Linked list Node가 존재한다는 것!  다시 말하면, 밖에서 봤을 땐 하나의 커다란 Stack인데 이것들이 내부에선 Linked list로 구성이 되어 있다는 것이다.문제의 조건은 아래와 같다.   1. 각 Stack Node에는 Max-capacity가 존재하다. Max-capacity를 넘어서면 새로운 Stack Node를 만든다.   2. list_size() method를 구현하라. 현재 원소가 존재하는 List Node(stack)의 개수를 반환한다.   3. push() method를 구현하라.   4. pop() method를 구현하라. 원소가 Link..

SW 만학도/C 2024.12.23

Minimum Number of Operations to Sort a Binary Tree by Level(Tree,Breadth-First Search,Binary Tree)

https://leetcode.com/problems/minimum-number-of-operations-to-sort-a-binary-tree-by-level/description/?envType=daily-question&envId=2024-12-23You are given the root of a binary tree with unique values.In one operation, you can choose any two nodes at the same level and swap their values.Return the minimum number of operations needed to make the values at each level sorted in a strictly increasin..

Coding_Practice 2024.12.23