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

            導航

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

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久久久中文字幕大豆网| 国产精品久久久99| 久久这里只有精品首页| 麻豆精品久久久久久久99蜜桃| 亚洲国产精品无码久久久蜜芽 | 久久精品www人人爽人人| 亚洲AV乱码久久精品蜜桃| 久久青草国产精品一区| 久久国产成人午夜AV影院| 怡红院日本一道日本久久| 久久精品免费大片国产大片| 久久久久av无码免费网| 久久免费国产精品一区二区| 亚洲人AV永久一区二区三区久久| 亚洲AV无码久久精品蜜桃| 中文精品久久久久国产网址 | 久久精品夜夜夜夜夜久久| 久久久久久噜噜精品免费直播| 亚洲国产另类久久久精品 | 国产精品99久久免费观看| 人人狠狠综合久久亚洲| 狠狠色丁香婷婷久久综合不卡| 一级女性全黄久久生活片免费| 久久久91精品国产一区二区三区 | 青青国产成人久久91网| 无码专区久久综合久中文字幕 | 久久天天躁狠狠躁夜夜躁2O2O | 精品久久久久久国产潘金莲 | 久久最新精品国产| 久久久久高潮毛片免费全部播放 | 777米奇久久最新地址| 人妻无码精品久久亚瑟影视| 日韩欧美亚洲国产精品字幕久久久| 久久亚洲美女精品国产精品| 欧美精品乱码99久久蜜桃| 亚洲精品国精品久久99热| 久久久久国色AV免费观看| 久久精品亚洲精品国产欧美| 91久久国产视频| 2020最新久久久视精品爱 | 久久久精品久久久久久 |