| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | A question |
Hi Neil. 17-May-04 22:41:00, Neil Heller wrote to All NH> The question: NH> Given an array of integers, write a function to return any NH> duplicated values. What is the the running time of this NH> algorithm? the best approach would probably be to qsort or radix-sort the array and then parse it for repeated values. NH> It seems to me that the ideal would be some sort of a hash NH> involving a second array, as long in bits as there are integer NH> numbers. Each integer would set a bit. If that bit had been NH> previously set, bingo, a duplicate. NH> It seems to me as though the big-O for that function is 1. Is NH> that correct? O(hash-table-size) + O(n) the hash-table-size could be the determining factor... note: many compilers won't let you make an array big enough to have one cell for each integer value, so you'll be playing with bitmaps this algorithmwill slow where physical memory is limited and also with small input data sets. if you sort the array and then parse it for dupes you can do that in O(n) time using a radix sort. and using hopefully mucn less memory (need space for 4 times the size of the array) qsort O(n.log(n)) could be faster than raiix sort for small arrays. -=> Bye <=- ---* Origin: Bushido does not mean what it sounds like. (3:640/1042) SEEN-BY: 633/267 270 @PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.