• <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 閱讀(447) 評論(0)  編輯 收藏 引用 所屬分類: R_找工復習2011

            導航

            <2011年10月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            婷婷久久综合九色综合98| 精产国品久久一二三产区区别| 久久亚洲精精品中文字幕| 精品伊人久久大线蕉色首页| 久久99热只有频精品8| 国产亚洲精久久久久久无码| 国产亚州精品女人久久久久久| 久久久一本精品99久久精品88| 国产午夜精品久久久久免费视| 久久久久女教师免费一区| 天天躁日日躁狠狠久久| 天天做夜夜做久久做狠狠| 久久精品国产色蜜蜜麻豆| 狠狠狠色丁香婷婷综合久久五月| 久久久久亚洲AV无码专区首JN| 久久久久国色AV免费看图片| 久久中文娱乐网| 亚洲国产精品久久久久| 国产精品青草久久久久福利99| 久久久久久夜精品精品免费啦| 无码精品久久久久久人妻中字| 久久夜色精品国产网站| 72种姿势欧美久久久久大黄蕉| AAA级久久久精品无码片| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 精品久久久久国产免费| 亚洲Av无码国产情品久久| 色8久久人人97超碰香蕉987| 2020久久精品国产免费| 婷婷久久综合九色综合九七| 亚洲av伊人久久综合密臀性色| 精品久久久久久无码中文字幕一区| AAA级久久久精品无码区| 久久亚洲AV无码精品色午夜麻豆| 久久久亚洲欧洲日产国码aⅴ| 久久久久成人精品无码| 国内精品人妻无码久久久影院| 久久久久久久综合日本| 91精品国产高清久久久久久91| 国内高清久久久久久| 久久久久久久久久久精品尤物|