트리란?

트리 이미지

트리 이미지

이진 트리의 장점)

SET

Untitled

MAP

Untitled

<aside> 🔥 unordered_set과 unordered_map 은 속도는 빠를지언정 충돌이 얼마나 빈번한가에 따라서 속도 저하가 발생하기에 set과 map을 사용하는 것이 좋다.

이분탐색이나 정렬보다는 좀 더 느린 O(lgN)의 시간 복잡도를 가진다.

</aside>

이진 검색 트리 연습 문제

BOJ 7662 : 이중 우선순위 큐

#include <bits/stdc++.h>

using namesapce std;

int main(){
	int t;
	cin >> t;
	while(t--){
		int k;
		cin >> k;
		multiset<int> ms;
		while(k--){
			char com;
			cin >> com;
			if(com == 'D'){
				int q;
				cin >> q;
				if(ms.empty()) continue;
				if(q == l) ms.erase(prev(ms.end()));
				else ms.erase(ms.begin());
			}
			else{
				int q;
				cin >> q;
				ms.insert(q);
			}
		}
		if(ms.empty()) cout << "EMPTY\\n";
		else{
			cout << *prev(ms.end()) << ' ' << * ms.begin() << '\\n';
		}
	}