Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Would it be incorrect to insert into whatever heap is smaller in size, and then ...

Pete Stenger

Aug 27, 2022

Would it be incorrect to insert into whatever heap is smaller in size, and then swap the tops of the heap if they are unordered?

0

0

Comments
Comments
J
Jimmy 2 years ago

What do you mean by unordered? If you're always inserting into the heap with the smaller size, you're essentially doing round robin insertion between the two heaps. That's incorrect since you're not checking which heap the number should go to.

On this page