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

            導航

            <2010年7月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产婷婷成人久久Av免费高清| 狠狠综合久久AV一区二区三区| 久久发布国产伦子伦精品 | 中文国产成人精品久久不卡 | 欧美久久综合性欧美| 久久男人AV资源网站| 久久久久久国产a免费观看黄色大片 | 久久精品国产亚洲av麻豆蜜芽| 色妞色综合久久夜夜| 精品水蜜桃久久久久久久| 亚洲精品无码久久毛片| 91精品国产高清久久久久久io| 日韩va亚洲va欧美va久久| 国产成年无码久久久久毛片| 国产农村妇女毛片精品久久| 午夜精品久久久久久久久| 国産精品久久久久久久| 亚洲av日韩精品久久久久久a| 国产福利电影一区二区三区,免费久久久久久久精 | 亚洲精品无码久久久| 99久久99久久精品国产片| 久久91精品国产91久| 久久精品一区二区| 新狼窝色AV性久久久久久| 久久久久国产一级毛片高清板| 国产精品久久久久影院嫩草| 久久综合国产乱子伦精品免费| 久久人人爽人人爽人人爽 | 亚洲日本va午夜中文字幕久久| 婷婷伊人久久大香线蕉AV | 久久无码AV中文出轨人妻| 韩国免费A级毛片久久| segui久久国产精品| 久久国产精品一区| 亚洲精品乱码久久久久久中文字幕| 亚洲国产精品无码久久一区二区| 久久国产色AV免费看| 欧美日韩成人精品久久久免费看| 要久久爱在线免费观看| 国产午夜久久影院| 久久亚洲日韩看片无码|