Algorithm-finding kth next element in an array

后端 未结 3 1751
别那么骄傲
别那么骄傲 2021-01-20 14:30

I couldn\'t solve a question can you please help?

For i=1 to i=n/2, if A[i]<=A[2i] and A[i]<=A[2i+1] A is called as a \"bst\" 

What\

3条回答
  •  孤独总比滥情好
    2021-01-20 14:51

    First, you mean "heap", not "bst" (the data structure you described is necessarily a heap and is not necessarily a bst).

    Second, it's not at all obvious that this problem is solvable in O(k) time -- it was not until 1992 that Frederickson gave an O(k)-time algorithm for this. I haven't read this paper all the way through, but it's 18 pages of intricate technical argument, and I'm flabbergasted that Olympiad organisers would expect students to essentially come up with it from scratch! (Or perhaps they expect them to already be familiar with the algorithm -- in which case I would say that (a) it's still asking quite a lot, and (b) it's not a very good question.)

提交回复
热议问题