• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            A Za, A Za, Fighting...

            堅信:勤能補拙

            2011好題 - 尋找倆已排好序數組的中位數

            問題:
            有兩個已排好序的數組A和B,長度均為n,找出這兩個數組的中間元素。要求時間代價為O(logn)

            思路:
            a. 比較自然的思路是歸并算法,不過時間復雜度是O(n),無法滿足題目要求

            b.
            http://www.binghe.org/2011/05/find-median/ )

            Say the two arrays are sorted and increasing, namely A and B.
            It is easy to find the median of each array in O(1) time.
            Assume the median of array A is m and the median of array B is n.
            Then,
            1′ If m=n, then clearly the median after merging is also m, the algorithm holds.
            2′ If m<n, then reserve the half of sequence A in which all numbers are greater than
            m, also reserve the half of sequence B in which all numbers are smaller than n.
            Run the algorithm on the two new arrays.
            3′ If m>n, then reserve the half of sequence A in which all numbers are smaller than
            m, also reserve the half of sequence B in which all numbers are larger than n.

            Run the algorithm on the two new arrays.

            Time complexity: O(logn)






            posted on 2011-10-16 18:38 simplyzhao 閱讀(451) 評論(0)  編輯 收藏 引用 所屬分類: R_找工復習2011

            導航

            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久免费小视频| 欧美色综合久久久久久| 久久精品国产91久久麻豆自制| 久久久久久久综合日本亚洲| 久久无码一区二区三区少妇| 久久无码人妻一区二区三区午夜| 国产真实乱对白精彩久久| 国产精品亚洲综合久久| 精品一区二区久久久久久久网站| 97精品伊人久久大香线蕉| 久久综合狠狠综合久久激情 | 亚洲精品无码久久久久去q| 国产成人精品久久亚洲高清不卡| 久久国内免费视频| 久久无码一区二区三区少妇| 久久国产一区二区| 久久久久无码精品国产不卡| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久最新免费视频| 久久久久久免费一区二区三区| 人妻无码精品久久亚瑟影视| 久久国产成人午夜AV影院| 欧美亚洲另类久久综合| 99久久久精品免费观看国产| 久久妇女高潮几次MBA| 老司机午夜网站国内精品久久久久久久久 | 中文国产成人精品久久不卡| 亚洲国产精品无码久久青草| 久久久久成人精品无码| 九九久久精品国产| 久久久精品国产Sm最大网站| 久久精品无码一区二区app| 999久久久免费国产精品播放| 精品午夜久久福利大片| 日本道色综合久久影院| 国产精品内射久久久久欢欢| 2021国产成人精品久久| 国产叼嘿久久精品久久| 久久久精品久久久久特色影视 | 久久久精品国产sm调教网站| 精品无码久久久久久午夜|