简历:The Google Resume: How to Prepare for a Career and Land a Job at Apple, Microsoft, Google, or any Top Tech Company
算法学习书籍:Introduction to Algorithms
编程珠玑:Programming Pearls (2nd Edition)
C++ 学习:The C++ Programming Language, 4th Edition
经典操作系统书籍,龙书:Operating System Concepts
创业:The Start-up of You: Adapt to the Future, Invest in Yourself, and Transform Your Career
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
两种办法,第一种很straight forward, 直接merge two sorted lists, 然后对于每一个lists,都如此合并,但时间复杂度消耗比较高。e.g, n lists, every list has k nodes. O(knn). 因为每次合并之后的lists长度都会变长。
第二种用min-heap来动态地给minimun node in all lists. time complexity is O(knlogk). (介个我不太会。。因为没咋建过堆)
第三种是我最稀饭的,用multiset来动态地保存当前最小的元素,然后比较完一个就把那个list的后面那个扔到multiset里面去。
Multisets are containers that store elements following a specific order, and where multiple elements can have equivalent values.
In a multiset, the value of an element also identifies it (the value is itself the key, of type T). The value of the elements in a multiset cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.
Internally, the elements in a multiset are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).
multiset containers are generally slower than unordered_multiset containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order.
Multisets are typically implemented as binary search trees.
It seems the multiset functions similarly as priority queue. Any difference between them? Some threads suggests differences in performance for some compilers.
ReplyDelete写的好,继续跪读中...
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete