Adobe Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
1
of 1 vote

Look at what ExtractMin does:
- Extract the root, O(1) actual time;
- Replace it with the last element x in the heap and repair the heap by heap-down/up. This takes about O(logn), which is depth of the heap.

Thus, to get O(1) amortized time for ExtractMin, the last element x must have enough "potential" for repairing the heap. This potential of x must be in order of its depth, i.e. O(logn).

Set the weight Wk for the k-th element in the heap as its depth, i.e.:
Wk = log k;

Thus, the potential function Phi for the heap Hn of n element can be defined as:

Phi(Hn) = sum of all Wk, k = 1..n; (Note: Phi(H) never be negative.)

This can be expressed as Phi(Hn) = nlogn;

Analysis:

For Insert: "pay" a cost of 2 logn for : (1) pay actual cost of insert (logn); (2) raise potential for the new element (logn).

Then, for ExtractMin: O(1) amortized. To repair the heap, use the potential logn of the last element x, as mentioned above.

In a nutshell, when insert, potential increases, and this can be afforded by paying insert more (but not too much). When extract min, potential descreases by a right amount of the cost for repairing.

You can write mathematics expressions to clearly see that Insert is O(logn) amortized and ExtractMin is O(1) amortized.

- ninhnnsoc October 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sounds like - Fibonacci heap

- VJ October 27, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More