Showing posts with label heap. Show all posts
Showing posts with label heap. Show all posts

Dec 29, 2008

How do you merge n sorted lists with average length K in O(nklogn) time?

How do you merge n sorted lists with average length K in O(nklogn) time?

Use heap to find the min or max value, the complexity is O(nklogn)
Take root and insert a new node in the root, shift down the new root to proper position, we need O(2logn) complexity. (compare two child nodes and compare parent node with one max or min child node)

Dec 21, 2008

What's the difference between process and thread? What kind of information does thread maintain? its own stack? heap?

What's the difference between process and thread? What kind of information does thread maintain? its own stack? heap?

process is a execution of a program and process contains data segment, code segment, heap and stack but thread is a single sequence stream within the process. Threads can share memory space of defferent threads belonging to the same process, process cannot. Thread maintains own stack, shares heap with others