• <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)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品一本到99热免费| 久久午夜电影网| 久久久亚洲裙底偷窥综合| 精品国产日韩久久亚洲| 亚洲欧美伊人久久综合一区二区 | 久久精品无码一区二区无码| 老色鬼久久亚洲AV综合| 国产免费久久精品99久久| 精品伊人久久久| 99久久亚洲综合精品成人| 久久久综合香蕉尹人综合网| 狠狠综合久久AV一区二区三区| 国产精品久久久久久久久鸭 | 伊色综合久久之综合久久| 91久久婷婷国产综合精品青草| 武侠古典久久婷婷狼人伊人| 久久99国产亚洲高清观看首页| 久久只有这里有精品4| 久久99精品国产99久久6| 国产精品国色综合久久| 久久人人爽人人爽人人片AV不| 婷婷综合久久中文字幕| 精品久久久久香蕉网| 久久久久免费精品国产| 日韩欧美亚洲国产精品字幕久久久| 久久青草国产手机看片福利盒子| 色偷偷88888欧美精品久久久| 伊人伊成久久人综合网777| 久久国产精品国语对白| 国产精品无码久久四虎| 97精品久久天干天天天按摩| 久久中文骚妇内射| 亚洲精品国精品久久99热一 | 久久综合综合久久97色| 久久精品aⅴ无码中文字字幕重口| 亚洲AV无码久久精品成人| 狠狠色婷婷久久综合频道日韩 | 国产情侣久久久久aⅴ免费| 久久亚洲欧美国产精品| 久久精品亚洲精品国产色婷| 精品国产乱码久久久久久1区2区|