java map 队列_优先级队列(PriorityQueue)vsTreeSet/Map

正版spring security实战编程与

54.9元

(需用券)

去购买 >

java map 队列_优先级队列(PriorityQueue)vsTreeSet/Map_第1张图片

当我们选择数据结构的时候我们已经考虑下面几点:

为什么要选择这种数据结构,数据结构的使用情况是什么(简而言之就是我们使用这种数据结构可以做到哪些优化), 进而我们需要考虑数据结构的接口,然后再考虑实现层面

1.数据结构里存储的数据形式是什么

2.为什么要使用这种数据结构

List of DataStructures:

ArrayList; LinkedList(Singly, Doubly); Queue(Circular Array, linkedList); Stack(array, singly LinkedList), Deque(Circular array, doubly linked list);

Tree(Balanced BST, augmented BST, segment Tree)

PriorityQueue vs TreeSet/Map

PriorityQueue:

O(1) for getting min/max heap

O(logn) for heap to offer;

O(logn) for remove

apis:

heapify(O(n)); percolateUp; percolateDown; poll; offer; peek;

The reason why we want to use tree set/map instead of heap is because the update index(which is not min/max) function in heap is difficult, and we should keep track of a hashmap to record the value and index.

优先队列的优势:get max/min, peek() is O(1)

TreeMap/Set的优势: update or delete 任意number是O(logn)

If some problems can be solved by using priorityQueue, it must be solved by using treeset/map

TopKProblems

1.k Largest/Smallest Element in unsorted array

2.k smallest/largest element in unsorted array

3.The k closest points in 3-d space to point of (0,0,0)

原文链接:https://segmentfault.com/a/1190000012945769

java 11官方入门(第8版)教材

79.84元

包邮

(需用券)

去购买 >

f0f3f55624fb396b1764d42d6df88864.png

你可能感兴趣的:(java,map,队列)