230529_Mon

KH·2023년 5월 29일
0

TIL

목록 보기
3/58
post-thumbnail

Problems

  1. 웹개발 종합반 1강

  2. 백준 4949 균형잡힌 세상

  3. 백준 11279 최대 힙

Attempts

  1. VS Code 설정 및 HTML, CSS 입문

  2. Stack 클래스 사용
    스택을 사용했던 괄호 문제와 로직이 흡사함. 괄호 종류가 추가되어서 조건을 추가해줘야 함.

  3. PriorityQueue 클래스 사용
    우선순위 큐 자료구조를 잘 모르는 상태에서 PriorityQueue 클래스 메서드를 사용하기 위해 자료조사

source: https://cs.lmu.edu/~ray/notes/pqueues/
Heaps

A heap is a complete binary tree in which the value of a node is less than all the values in its subtrees. By convention, the smallest element is the one with the highest priority.

PriorityQueue is a specific use case of a Heap, which in turn is a specific use case of a BinaryTree

PriorityQueue Hierarchy

A priority queue in Java is a special type of queue wherein all the elements are ordered as per their natural ordering or based on a custom Comparator supplied at the time of creation.

A Comparator interface in Java helps you define how objects should be compared and sorted based on specific criteria, allowing you to customize the sorting behavior of Java's built-in sorting methods.

source: Googling Based on chatGPT's response(There could be some errors)

Results

  1. 1강 수강완료

  2. 조금 더 고민해서 스스로 풀 수도 있었을 텐데 조건문 로직을 검색하다가 알게 되어 아쉬웠음. 한편 팀원으로부터 stack.clear()메서드를 사용하면 스택을 루프마다 매번 생성하지 않아도 된다는 것을 알게 됨.

  3. Comparator 인터페이스를 구현하는 대신 Collections.reverseOrder()메서드를 사용하여 큐를 내림차순으로 설정하였다.

PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());

Insights

자료구조 지식이 부족하다는 점을 느꼈다. 스파르타 강의실에 자료구조 강의도 있는데 시간을 내서 들어야겠다.

profile
What, How, Why

0개의 댓글