问题
So im attempting the classic problem of finding the median in two AVL BST's in O(log(n)) time. Given two AVLs, with a combined size of n (integers are distributed randomly i.e. one may have n-1 elements with the other having 1). I am currently trying to come up with an algorithm to solve this. Each node, besides holding its integer value and pointers to its parent and child nodes, holds the size of the subtree for the subtree rooted at it. I've approached it by initially finding the number of elements n (we assume this to always be odd) via the subtree sizes of each AVL tree's root. Let the subtrees be A and B, where AL is the left subtree of A and AR is the right etc. I've begun by operating on the AVL tree of a larger size and then comparing AL and AR's sizes. With this approach im trying to rule out the existance of the median in one of the subtrees but im currently confused on how to do this. Any ideas? Thanks
来源:https://stackoverflow.com/questions/60927275/find-the-median-in-two-avl-bsts-in-ologn