Berkeley CSUA MOTD:Entry 52923
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/04 [General] UID:1000 Activity:popular
5/4     

2009/4/30-5/6 [Computer/Theory] UID:52923 Activity:nil
4/30    Sorting question!  I have n sorted arrays of doubles.  What's the
        fastest way to sort them into 1 big sorted array?
        \_ as mentioned below: you are describing one half of mergesort
        \_ You really have to ask this question?
           \_ You don't know either, huh?
        \_ If three are n sorted arrays of m doubles each, I think the fastest
           way is O(m * n log n).
              \_ Read up on mergesort, now do the logical next step.
                 \_ Mergesort doesn't take advantage of the arrays being
                    sorted.  You only need to consider the first unprocessed
                    value per array when choosing the next to insert.
                    \_ The second half of mergesort takes advantage of
                       the arrays being sorted.  That's the whole deal
                       with mergesort.  You merge two sorted lists, starting
                       with the trivial case of a single element list.
                       \_ If each sorted array has m doubles, is the complexity
                          for this O(n^2 * m)?  -- yuen
                          \_ No, it depends on you make your max function work.
                             I can think of a pretty simple way to do it
                             in O(mnlogn).
                             \_ Hell, you could just jam the lists together
                                and do a mergesort with the starting list
                                size of m (if the lists are all the same
                                length, add a null list terminator if that's
                                the case.)
                                There's tons of ways to do this all close
                                enough to the same big O that the ultimate
                                "fastest" is going to depend on real
                                limitations like is your data so large that
                                it spans multiple file systems.
              \_ I don't exctly have a pattern handy, but it should be pretty
                 easy.
        \_ http://en.wikipedia.org/wiki/Bogosort
2025/05/04 [General] UID:1000 Activity:popular
5/4     

You may also be interested in these entries...
2012/8/30-11/7 [Computer/SW/Apps, Computer/SW/Unix] UID:54470 Activity:nil
8/30    Is wall just dead? The wallall command dies for me, muttering
        something about /var/wall/ttys not existing.
        \_ its seen a great drop in usage, though it seems mostly functional.
            -ERic
        \_ Couldn't open wall log!: Bad file descriptor
           Could not open wall subscription directory /var/wall/ttys: No such file or directory
	...
2012/1/24-3/3 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Misc] UID:54296 Activity:nil
1/24    http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html
        Amusing "history" of computer science.
        \_ Where's the mentioning of Al Gore the inventor of AlGorithm?
	...
2011/11/20-2012/2/6 [Computer/Companies/Apple, Computer/SW/Unix] UID:54237 Activity:nil
11/20   Are there tools that can justify a chunk of plain ASCII text by
        replacing words with words of similar meaning and inserting/removing
        commas into the text?  I received a 40-line plain text mail where
        all the lines are justified on left and right.  Every word and comma
        is followed by only one space, and every period is followed by two
        spaces.  The guy is my kid's karate instructor which I don't think is
	...
2011/10/26-12/6 [Computer/SW/Unix] UID:54202 Activity:nil
10/24  What's an easy way to see if say column 3 of a file matches a list of
       expressions in a file? Basically I want to combine "grep -f <file>"
       to store the patterns and awk's $3 ~ /(AAA|BBB|CCC)/ ... I realize
       I can do this with "egrep -f " and use regexp instead of strings, but
       was wondering if there was some magic way to do this.
       \_ UNIX has no magic. Make a shell script to produce the ask or egrep
	...
Cache (2384 bytes)
en.wikipedia.org/wiki/Bogosort
deck of cards, it would consist of checking if the deck were in order, and if it were not, one would throw the deck into the air, pick the cards up at random, and repeat the process until the deck is sorted. It is named after the humorous term quantum bogodynamics and, ultimately, the word bogus. The expected number of swaps grows faster than the expected number of comparisons, because if the elements are not in order, this will usually be discovered after only a few comparisons no matter how many elements there are, but the work of shuffling the collection is proportional to its size. In the worst case, the number of comparisons and swaps are both unbounded, for the same reason that a tossed coin might turn up heads any number of times in a row. The best case occurs if the list as given is already sorted; For dealing with a list of two elements, this places Bogosort amongst the best sorting methods: one comparison, and then either it finishes, or else there is one swap and one more comparison. If that second comparison were omitted, then the best possible sequence would be attained. edit Bozo sort Bozo sort is another sorting algorithm based on random numbers. If the list is not in order, it picks two items at random and swaps them, then checks to see if the list is sorted. many-worlds interpretation of quantum physics, the quantum randomization spawns an infinite array of universes and some of these will be such that the single shuffle had produced the list in sorted order because the total number of distinct orderings, though large, is not infinite. The list is then tested for sortedness (requiring n-1 comparisons); should it be out of order, the computer triggers its "destroy universe" operation (typically accompanied by a dry observation that implementing this operation is left as an exercise to the reader). The only observers will then be in the surviving universes and will see that the randomization worked the first time and that the list is in sorted order. Note, however, that even here there is no free lunch - while this algorithm is O in time, permuting the list requires that we consume O(n log n) bits of quantum randomness. Sorting the Slow Way: An Analysis of Perversely Awful Randomized Sorting Algorithms, 4th International Conference on Fun with Algorithms, Castiglioncello, Italy, 2007, Lecture Notes in Computer Science 4475, pp.