home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.theory
- Path: sparky!uunet!wupost!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watdragon.uwaterloo.ca!abrodnik
- From: abrodnik@watdragon.uwaterloo.ca
- Subject: Re: Generic sorting functions
- Message-ID: <BtGtup.F55@watdragon.uwaterloo.ca>
- Organization: University of Waterloo
- References: <9208212151.AA44579@cs90code.csv-tgsc.amex-trs.com>
- Date: Mon, 24 Aug 1992 02:06:24 GMT
- Lines: 68
-
- In article <9208212151.AA44579@cs90code.csv-tgsc.amex-trs.com> gonzalod@amex-trs.com (Gonzalo Diethelm) writes:
- >
- >A very generic question. Given a set S of n strings (the `|' characters
- >are used as delimiters):
- >
- > s1 |dunno|
- > s2 |I'd rather have a bottle in front of me than a frontal lobotomy|
- > s3 |eschew clever rules|
- > ... ...
- > sn |bzzzzt!|
- >
- >and an ordering sequence O:
- >
- > {s4, s1, s6, s2, sn, s3, ... s7}
- >
- >is there any way to determine a fixed, hopefully cheap function
- >
- > f(): SxS -> integers
- >
- >with the property that
- >
- > if si comes before sj in O, f(si, sj) < 0
- > if si comes after sj in O, f(si, sj) > 0
- >
- >that is, could be used to sort the strings in the given sequence?
-
- If I understnd this correctly, you are asking the following question:
-
- o you are given a total ordering (not known how to efectively
- compute relations among elements)
- o make a comparison function for this ordering.
-
- If your function can use O(S) space, your total running time is
-
- O(S*c + n*c),
-
- where n is the number of queries to it. The c represents the time to
- fetch the internal table.
-
- At first query f simply runs through the sequence O until it finds the
- right key (it can't do better -- apply a simple adversay argument,
- because you don't know efective function to describe it). As it
- searches for the right key, it assigns proper indices to the internal
- table. This table will be later used to map from key --> itsOrder. The
- assumption here is that the set of keys {s_i} is known in advance.
-
- Each searching for the index in the table takes O(c) time (you can
- take here O(log S) for tree or binary search, or O(1) for perfect
- hashing).
-
- The first search takes O(S*c) time, but each subsequent search will
- take then O(c) time what gives us the above bound.
-
- Even more, because of the adversary argument the lower bound on the
- first search is also _O_(S*c) and simple reasoning will also show that
- the mentioned upper bound matches the lower bound.
-
- The overall assumption here is that the set {s_i | i=1..S} is known in
- advance. I think that it is feasible especially because the only way
- to order elements is through the sequence O. It's an interresting
- question if the space can be decreased. Again (because of the
- adversary argument) it seems that the time will increase immediately.
-
- This are my 2 pence.
-
- Best regards,
-
- Andrej
-