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

            堅(jiān)信:勤能補(bǔ)拙

            2011好題 - 尋找倆已排好序數(shù)組的中位數(shù)

            問(wèn)題:
            有兩個(gè)已排好序的數(shù)組A和B,長(zhǎng)度均為n,找出這兩個(gè)數(shù)組的中間元素。要求時(shí)間代價(jià)為O(logn)

            思路:
            a. 比較自然的思路是歸并算法,不過(guò)時(shí)間復(fù)雜度是O(n),無(wú)法滿足題目要求

            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 閱讀(454) 評(píng)論(0)  編輯 收藏 引用 所屬分類: R_找工復(fù)習(xí)2011

            導(dǎo)航

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲精品乱码久久久久66| 亚洲精品99久久久久中文字幕| 97久久精品无码一区二区| 久久精品一区二区| 污污内射久久一区二区欧美日韩| 国内高清久久久久久| 国产激情久久久久影院老熟女免费| 亚洲日韩欧美一区久久久久我| 亚洲va久久久噜噜噜久久狠狠| 国产精品亚洲美女久久久| 精品综合久久久久久98| 国产一区二区精品久久凹凸| 久久精品国产亚洲AV久| 日本久久久久久久久久| 久久久中文字幕| 久久人爽人人爽人人片AV| 久久综合色老色| 日韩影院久久| 亚洲午夜精品久久久久久app| 韩国三级中文字幕hd久久精品| 亚洲AV无码久久精品蜜桃| 99精品国产免费久久久久久下载| 2021国产成人精品久久| 国产欧美一区二区久久| 精品久久久久久久久午夜福利| 午夜人妻久久久久久久久| 久久久久青草线蕉综合超碰| 三级三级久久三级久久| 亚洲国产成人久久一区久久| 怡红院日本一道日本久久| 99精品久久久久中文字幕| 久久久无码精品亚洲日韩按摩| 久久天天躁狠狠躁夜夜躁2O2O | 久久久久亚洲av无码专区导航| 思思久久99热免费精品6| 久久国产精品无| 少妇熟女久久综合网色欲| 久久人人爽人人爽人人爽| 97精品国产97久久久久久免费| 97视频久久久| 人妻精品久久久久中文字幕69|