0

let n, the size of the combined be trees be odd and assume that all the integers across the trees are distinct. Take these two AVL trees as input and find the median of the trees in O(log(n)) time.

I've tried and the best I can get is O(log²(n)) time. This is by using a solution algorithm that imitates this question but instead uses two sorted arrays U-tube: Binary Search : Median of two sorted arrays of different sizes.

Could someone please help me find a solution in O(log(n)), and if you provide code, python would be much appreciated!

Edit: Each node stores the size of the subtree rooted at that node.

greybeard
  • 2,015
  • 5
  • 20
  • 51
sam279
  • 11
  • 4
  • Do you have a reason to believe it's possible? – Kelly Bundy Apr 05 '20 at 15:24
  • see also: [Finding the median of 2 avl trees within O(logn) time](https://stackoverflow.com/q/60984920) - welcome to [the associated chat room](https://chat.stackoverflow.com/rooms/210781/median-in-two-augmented-avl-trees). – greybeard Apr 05 '20 at 16:19
  • Yes because my lecturer told us that it is possible with information we have. – sam279 Apr 05 '20 at 23:06

0 Answers0