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

            導航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲va久久久久| 亚洲成色999久久网站| 欧美黑人激情性久久| 99精品久久久久久久婷婷| 久久天天躁狠狠躁夜夜96流白浆| 国产精品久久久久久搜索| 久久精品中文字幕一区| 久久亚洲精品国产精品| 久久91精品综合国产首页| 亚洲国产精品一区二区久久hs | 日韩美女18网站久久精品| 97精品国产97久久久久久免费| 国产成人久久AV免费| 欧美性猛交xxxx免费看久久久| 久久综合狠狠综合久久| 久久99精品国产麻豆婷婷| 久久亚洲私人国产精品| 久久只有这精品99| 久久久艹| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久国产免费直播| 99久久国产热无码精品免费| 久久免费视频1| 青青青青久久精品国产h久久精品五福影院1421| 伊人色综合久久天天人手人婷| 久久精品亚洲福利| 久久久久国产精品麻豆AR影院| 久久久久久免费一区二区三区 | 久久久久亚洲精品男人的天堂| 99久久精品午夜一区二区| 无码人妻久久久一区二区三区 | 久久综合久久久| 久久国产精品久久| 久久91亚洲人成电影网站| 99久久99久久久精品齐齐| 青青草原精品99久久精品66| 亚洲午夜久久久久久噜噜噜| 伊人久久大香线蕉av不变影院 | 久久午夜夜伦鲁鲁片免费无码影视| 久久国产美女免费观看精品 | 亚洲国产成人久久一区WWW|