![]() |
| | #61 |
| Ex scientia vera Join Date: Sep 2007
Posts: 426
|
__________________ "What's up, Doc?" "'Up' is a relative concept. It has no intrinsic value." |
| IceDane is offline | |
| | #62 |
| -AppearingOnThis.......... Join Date: May 2005 Location: Netherlands
Posts: 44
| I made this probably a year ago or so, and to be honest I can't really be bothered converting it's interface to the specifications. however, it may be of interest: it can easily calculate >200000 primes above 2^32 in less than 0.4 seconds. it compiles on gcc fine, using the unsigned long long type; not sure about visual c++. run it like: segprime2 minimum_value maximum_value output_file eg. segprime2 4294967296 4300000000 outfile.txt will generate 227027 primes http://sirnot.110mb.com/c/?f=segprime2.c it uses a 'work array' to maximize its range/number size while minimizing memory usage. Last edited by SirNot; 12-07-2008 at 06:57 AM. |
| SirNot is offline | |
| | #63 |
| Registered User Join Date: Jan 2005
Posts: 7,137
| >> while this one's is O(n/8) (I am using the O notation correctly, am I not?) Not exactly. O(n/8) is equivalent to O(n). In big-O notation all constants are ignored. As n increases, an O(n) running time will increase at the same rate as an O(n/8) running time would, which is why they are considered equivalent. |
| Daved is offline | |
| | #64 | |
| Ex scientia vera Join Date: Sep 2007
Posts: 426
| Quote:
__________________ "What's up, Doc?" "'Up' is a relative concept. It has no intrinsic value." | |
| IceDane is offline | |
| | #65 | |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,929
| Quote:
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet | |
| abachler is online now | |
| | #66 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Right, O(n) ~= O(n/8), it's more a case O(n) != O(log2 n) or O(n^2) - if n is 10000, and you divide by 8, you get 1250. Not a huge number, not a small number. O(log2 n) for n=10000 is about 13, O(n^2) is 100000000. And more importantly, if we double n, O(n) also doubles. O(n^2) is 4x larger, O(log2 n) is one larger. So the point about big-O is the ability to predict from a small run (low n), how a larger n will behave - this is a bit more difficult in modern machines with caches, virtual memory and other aspects, but we can still predict with some accuracy what will happen if we for example double the amount of data - will the time double or increase more/less than double? -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #67 |
| Registered User Join Date: Jan 2005
Posts: 7,137
| >> Only when it is specifically comparing the complexity to the size n of an arbitrary input can the constants be ignored. But is that not what big-O notation is intended for? If you want to compare running times (which of course is often a relevant endeavor), you shouldn't be using big-O notation. |
| Daved is offline | |
| | #68 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,929
| Except you arent always comparing actual runnign times, but computational complexity. So one algorithm may solve the problem in O(n log n) time, while another algorithm may solve it in O(n/2 log n) by discarding half the test cases based on some trivially computable feature. e.g. an algorithm that finds all prime numbers between 3 and n > 3 by testing every number, versus the same algorithm that only tests odd numbers between 3 and n > 3.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is online now | |
| | #69 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | |
| brewbuck is offline | |
| | #70 |
| Amazingly beautiful user. Join Date: Jul 2005 Location: If you knew I'd have to kill you
Posts: 251
| If I remember, O(f(x)) = g(x) if there exist constants c, d, and e such that c * f(x) + d >= g(x) for all x > e. Thus, O(n / 8) = O(n), because 8 * (n / 8) + 0 >= n, for all x > 0. (c = 8, d = 0, e = 0)
__________________ Programming Your Mom. http://www.dandongs.com/ |
| CrazyNorman is offline | |
| | #71 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Another way to put it is that lim [n -> infinity] f(n)/g(n) = k where k is some positive constant.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #72 |
| Registered User Join Date: Oct 2009
Posts: 1
| Greetings, folks. Congrats on the terrific submissions. I can't find who won - or abachler's source test code. Will someone help me out, please? Thanks! |
| deluge01 is offline | |
| | #73 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,366
| Sfel, probably.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #74 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,929
| Nothing like bumping a year old thread.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| xor linked list | adramalech | C Programming | 23 | 10-14-2008 10:13 AM |
| prime number program with function | mackieinva | C Programming | 17 | 09-20-2007 08:36 AM |
| Prime Number stops after 29, but why? | Daveo | C Programming | 22 | 09-17-2004 10:55 AM |
| Somewhat new to c++, adding Prime number and Sqrt featre to program... | thynksheraze | C++ Programming | 3 | 01-14-2003 10:34 PM |
| Random number generator | Caze | C++ Programming | 6 | 12-03-2002 08:10 AM |