I
I
isxaker2014-10-08 15:34:48
Time Management
isxaker, 2014-10-08 15:34:48

What will be the running time of building a heap?

How long will it take to build a heap if you just add all n elements to the heap sequentially?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Petrigo, 2014-10-12
@isxaker

Most likely the answers are
Ω(nlogn)
O(nlogn)
Since it will take O(n) time to create an empty array and put elements sequentially there, maintaining the properties of the heap (the sifting process) will take O(logn) in the worst case.
But since it is required to select all suitable options, then:
Ω(n) - since the function will grow no slower.
And O(n^2) since the function is limited to n^2 from above.

M
Mrrl, 2014-10-08
@Mrl

O(N*log(N)). For each of the last N/2 elements, approximately log(N) operations are needed.
Here it is possible to build a heap by rearranging the elements of an already filled array in O (N) operations.

T
throughtheether, 2014-10-10
@throughtheether

How long will it take to build a heap if you just add all n elements to the heap sequentially?

I need to select all correct options from the following
O(n)
Ω(n2)
Ω(n)
O(n2)
Ω(nlogn)
O(nlogn)

If we sequentially add elements (there are n in total ) to the heap (binary heap) and each time restore the heap property (upper complexity bound O( logn ), lower bound Ω( 1 )), then the upper bound on the total complexity will be O( nlogn ), lower - Ω( n ). The correct options, in my opinion:
Ω(n) , O(n2) (if you mean O(n*n)), O(nlogn)

O
overmes, 2014-10-08
@overmes

complexity will be N

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question