- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This is the worst case complexity. The average case complexity is O(n log n). All of worst case, average case and best case are formally defined, so I'm just pointing out that what you were writing is ambiguous.
Admin
Oh man, long time since I burst into laughter like this :). LOL!
CAPTCHA: atari, yay, brings back memories (ST ... I loved you)
Admin
Tell me, what's the replacement for java.util.Vector? Is it java.util.Vector<> (gosh I hope it is :))
CAPTCHA: stinky, not just yet! PS: Actually without thinking, I started using HashMap<> because it's seems more similar to std::map<> (I prefer templates in C++, no doubts there)
Admin
Yes you have to know how to program in Java, to eeehh...program in Java. Duh! And no, you don't need to know the exact implementation of framework functions to be able to program in Java. Where did you get that impression???
CAPTCHA: dreadlocks (how about deadlocks?)
Admin
Solution: use template containers from std namespace, and use iterators! And absurd amount of possible bugs due to bad memory management goes down the drain. At least, that is my experience. There are still a few gotcha's though, but far less than there used to be.
CAPTCHA: craaazy (that's really crazy =))
Admin
Since it already has built-in stupidity, so would built-in stupidity protection disable those portions of the language?
Admin
AMEN to that brother! My idea exactly!
CAPTCHA: gygax (Garry, are you there?)
Admin
Let me add to that:
Don't use a C# destructor (I prefer the term finalizer) unless you have allocated resources that aren't under C# control. In that case, you should write a C# destructor (finalizer) that frees the allocated resources if they weren't freed in Dispose. An example of such a resource could be a memory buffer you got from VirtualAlloc (kernel32).
All the other things that need to be freed, should be freed in Dispose. If you fail to free those resources in Dispose, then you better revisit your code.
CAPTCHA: bling (server: blong?)
Admin
Nope, Dispose is called when you call... Dispose! Or, at the end of a using statement. However, you can not know when the GC calls the finalizer! Big difference!
CAPTCHA: cognac (no thank you)
Admin
Tell me... What's wrong with:
InputStream s = new FileInputStream("filename"); try { /*do something */ } finally { s.close(); }
CAPTCHA: tesla...(had this one too much I'm afraid)
Admin
Que???
You write a fragment of code without any method signature (that could include a throws specification), and claim it doesn't compile? The fragment you originally post doesn't compile either, you failed to write a method body etc...
Where do you catch them? Whatever! Somewhere else obviously =)
sigh
CAPTCHA: quake (third time...bad omen)
Admin
O(F) is the order of an algorithm F (average efficiency). Order of quicksort is O(nlogn), no doubts there.
Formally O(n^2), what a load of crap. Worst case, yes, but that has nothing to do with the order of an algorithm which deals with average efficiency.
And to quote the wiki on Quicksort: Typically, quicksort is significantly faster in practice than other \mathcal{O}(n~\log~n) algorithms, because its inner loop can be efficiently implemented on most architectures, and in most real-world data it is possible to make design choices which minimize the possibility of requiring quadratic time.
For example... LMAO.
CAPTCHA: gotcha (oh no, not again!)
Admin
Nvm...found ArrayList, and sticking with it from now on. Thank you for this WTF :D!
CAPTCHA: dreadlocks (patience...patience...)
Admin
And best add explicitely, that if you require a finalizer (for the reasons I stated) you also should have a disposer (as I tend to call it) which disposes the unmanaged resources. The finalizer is a safe-guard for programmers that forget to dispose your object (which they shouldn't).
CAPTCHA: stinky (nope, still not stinking here)
Admin
Absolutely not. O(f(n)) is the class of functions that grows no quicker than f(n) asymptotically. In computer science, f(n) is usually assumed to be a function whose domain are the non-negative integers and whose value range is (a subset of) the non-negative real numbers. Two functions f(n) and g(n) are considered equal asymptotically if f(n) / g(n) converges to a positive number as n goes to infinity. For example, f(n) = 4n and g(n) = 105n + 1280 sqrt(n) + 10 are asymptotically equal as said fraction converges towards 4/105. In big O notation (sometimes, big Omicron notation is used, but the Omicron is virtually indistinguishable from O), that is: f(n) is in O(g(n)) and vice versa.
You can think of f(n) in O(g(n)) as sort of "f(n) is less than or equal to g(n), asymptotically". Analogously, small o notation means "less than", i.e. n is in o(10n²), but n² is not, ω (small omega) is used for "greater than", Ω (big omega) for "greater than or equal" and Θ (big theta) is used to mean "equal".
All this has nothing whatsoever to do with best case, average case or worst case time complexity of certain algorithms. The notation itself can be used to describe all of those and more (e.g. space complexity). The big-O-notation itself was introduced by the German mathematician Paul Bachmann in 1894. I don't know whether or not he meant O to mean Ordnung (the German word for order), but in any case his work has nothing to do with algorithmic time complexity.
Strictly speaking, all of the best case, average case and worst case time complexities of quicksort are in O(n²), as this basically means “quadratic time or faster”. The best and average case complexities are, however, also in o(n²), so they are not in Θ(n²). Only the worst case complexity is.
The average case complexity is in Θ(n log n). The best case complexity often is, too, but in some implementations it could also be in Θ(n).
Practically speaking, O is often used to mean the same thing as Θ, of course.
Admin
Lol, I was trying to put it easily.. Sure I have a MD in CS and could have made a lengthy explanation and a distinction between O and Θ (c/p'd Θ, wouldn't know how to get that character). But I don't think most can follow except if they have some form of mathematical education.
Anyway my point is that the Order of Quicksort is O(nlogn), meaning that the average computation time is of the order nlogn where n is the number of objects the algorithm processes. And usually, I don't care whether the worst case is n^2 and best case is n, at least not for quicksort.
Anyway, thanks for the recap :)
CAPTCHA: slashbot (a bot that produces slashes...yay a new invention)
Admin
Admin
I spend a lot of time bouncing between languages. If I'm thinking an idea through to get comfortable with the problem space, I don't want to get bogged down.
When I pass in an object, am I triggering a copy constructor? What's it doing to refcounts? If I pass a reference, will it sort based on the address of the reference or will it use the objects comparison operators? Am I going to trigger any problems with garbage collection? What else is that library loading? Will it conflict with anything I have in my quickly constructed prototype.
Before you get too picky, remember: I didn't say which language I was using, I didn't say which libraries were available, I didn't say what my memory requirements were, I didn't say anything what I was modelling. I didn't say how many things I was going to be sorting. (Maybe I know my tests are only going to have 6 objects during my tests)
Admin
No, not really.
Apart from the fact that method level synchronization is mostly worthless for collections (in most cases you have to control synchronized access on the whole collection, not only single operations, which calls for external synchronization anyway) there are helper methods to create synchronized wrappers around unsynchronized collections (see class java.util.Collections).
The main problem with using the old implementations are the old APIs. Most programmers that don't get OO completely and repeatedly read
Vector v = new Vector();
in other people's programs, books and examples, tend to absorb this bad habit. There's indeed nothing wrong with
List list = new Vector();
if you really need a synchronized list, though
List list = Collections.synchronizedList(new ArrayList());
is preferred. But
ArrayList list = new ArrayList();
is in fact equally dumb. I'm going so far as to say that using a concrete (class) type on a reference variable should be treated as an error. That's what interfaces where made for. There is nothing important that ArrayList can do which can't be done with the interface List. Vector even implements List, and so does Hashtable with Map!
So please all Java developers: do yourself and your fellow developers a favour and always (well, 99.9% of cases) use the collection API interfaces for all reference variables.
Admin
The more you use the old collection classes, the more likely you are going to see dumb things like
Vector v = new Vector();
The problem is not the implementation, it's the API.
List list = new Vector();
is basically ok. I'd still prefer the more consistent
List list = Collections.synchronizedList(new ArrayList());
An extra method call is never an argument. In another post someone was argumenting that in newer JDKs synchonized methods are nearly as efficient as unsynchronized ones.
This holds even much more true for wrappers (and therefore additional method calls): every decent JIT compiler is able to optimize that, and even if it is not - a single additional method call will never make your system slow.
Most, if not all, performance problems stem from not understanding the language or the architecture, and not from one additional indirection when calling a method.
Admin
Only if you drive an underpowered POS - it does cost extra fuel to use, though.
Admin
Phhhhhft one dimensional space....I don't even exist. Reality is really an illusion
Admin
There are coders and programmers. Colleges and Universities turn out coders. Companies hire these coders and spend years while the coder learns how to program.
There are a lot of highly qualified programmers who, if given the chance, could spend a couple of weeks learning how to code in some new language.
This guy is a coder, someday he may actually learn how to program, although I wouldn't bet on it.
Admin
I am still saying CS degrees are pointless; most people with such degrees they may not have an unknown unknown, but have instead learned to bullshit over their gaps. Self-taught programmers who have survived on their skills for some years at least get the job done, and most of them gladly accept (additional) knowledge if it comes their way.
Admin
("pointer" - good cue for a rant against Java)
Admin
Admin
I think the point is to enlighten him without making him feel like an undergraduate which has to go back to school before working on his project. So first, one has to try to understand what his point his, and if you are willing to try and not cling to just outsmart him, he has a point. Base implementations provided by the standard libraries are not always efficient to do the job you require. Maybe, the work with a callback interface to make them type independable, and other abstractions, but what you need is just a small, simple and very fast algorithm. That it can indeed be right to implement the data type from scratch.
Taking his point of view this into account, there are two possibilites. If he is right, which we can say only if we know much about the surrounding of the problem, then we should assist him to make his idea functional. If he is wrong, we should try to explain him why he should use the given standard hashtable instead doing his own thing. Never should we touch the dish and blame him for his point of view, because it is not wrong or right per default, and we should always treat our fellow developers with a minimal amount of respect.
Admin
Admin
Admin
Err..
You are suprised to get even worse implementations than your students? Happy, i wasnt one your students then..
Admin
tis good.... for a base LOL but too many functions dont make a slow program all that would be needed to avoid lots of functions is a root code just to skip the un necicary functions and go straight to the required.
lets take the D drive, the power button, the A drive, the speakers, the usb ports, and almost everything else out of the genisis computer im building sure itl be faster (except it wont turn on) but where dose the experience and quality go, sometimes speed must be compramised for the sake of experience and quality, or you can overclock then you win on all fronts
Admin
That is NOT the problem with that code.
Memory management, like the ptolemaic system, is one of those things that is good to know, but even better to be able to forget. It is an accidental, not an essential, part of computing.
Admin
Yes and no, I'm not sure what they're teaching for an undergraduate CS degree nowadays, but a thorough grounding in Data Structures and Algorithms doesn't seem to be part of it!
One of my standard sets of interview questions begins by asking the candidate to tell me what a Hashtable is and how to use it. Most can do this. Then I ask, how is it different from something like an ArrayList. Maybe half can dredge up something like it being much faster (some can even give the big-O relationships). Then I ask how you would implement a Hashtable if it weren't provided for you. Rarely does anyone come up with something different than the culprit in this WTF!
Admin
LOL what a noob. Obviously he should have wrapped it:
See? Much less code and still more efficient than just a HashMap because it only have three functions!!!Admin
On a serious note, why are you grouping people in self taught and educated people? Personally I am self taught AND educated, in fact I don't get why you would want to study the theory behind programming if you don't even know how to program in the first place.
At least this applies to Computer Science, because the only way to learn how to program there is on your own, since there are typically only one or two introductory courses in it. It is a major benefit to be able to program before you enroll, for many courses it is an implicit requirement.
Admin
i wish i knew something about programming to understand these ones i cant help but think of the simpsons episode where Prof Frink says "Pi is exactly three!" to get the attention of a crowd of braniacs.
Admin
No way dude, no such thing as too many functions?
Jiff www.privacy-tools.at.tc
Admin
I don't think you can implement Duff's device in C# because you need fall through in the switch statement. Still, it's only good for optimizing loops and still won't be faster than a hash table.
Admin
Self-taught is such a misnomer. People say that about me because I didn't go to college, but I say that this unfairly discounts the role mentors, books, help files, newsgroups, etc. played in my education.
One of the previous posters had a point, sometimes I'd find seemingly bizarre gaps in my knowledge. (seems bizarre after the fact of course)
Admin
I would have snapped and strangled that guy. Seriously.
And then it would be difficult to explain why I did that to my new jailmates... :)
Admin
Agreed 100%; I had the same thought when I read the original comment.
My academic background is physics/mathematics, only a handful of coding courses were involved, but I've had an easier time getting programming & database admin jobs than several of my CS friends for the exact reasons you specify: communication skills, ability to market oneself, and willingness to admint I don't know something (but would love to learn).
Many moons after entering the workforce I assumed some hiring resonsibilities, and it's now easy to see why things worked out as they did. I'd much rather hire a student w/ no official coding experience but has good communication skills, a positive personality, and a willingness to learn, than someone with a B.S. CS on paper but less ability to succeed in a team environment. Not saying CS majors lack these skills - many are quite good - but I see more C.S. applicants destroy their chance via. the interview than applicants coming from other sciences or even finance backgrounds.
Admin
Easily, the same way the dude made millions off the pet rock. It's not what you're selling, it's how you sell it that matters most. Only in acedemia is the reverse true.
Admin
lol :D :D :D :D :D :D
Admin
You mean sometimes people use the standard library's binary tree map instead of the hash table map?
Admin
There really are some people that should just not be allowed near code. Seriously, how do these people get through comp-sci programs with ridiculous ideas like that? Did this one even go to a comp-sci program?
On second thought, he must have gone through a comp-sci program. I've only ever known comp-sci students and PaulaBean wannabe's that come up with statements like that.