Itsy Bitsy Data Structures – Simplified examples of many common data structures
github.com
github.com
I think a lot of people that are in this thread went into this project with the complete wrong state of mind.
I'm not trying to teach people how a hash table or linked list implementation works. I'm not trying to make a library that is useful to anyone.
What I'm trying to do is connect the dots between a bunch of different important concepts in data structures.
People can go read things about each of these individual topics to great length and I encourage them too, but in general there are a lot of great computer science resources for just piecing a lot of related topics together for beginners.
Sure you can read a 600 page book that will cover things from end to end, but those are very intimidating when you have no prior knowledge of the topic and sometimes you don't get as much out of them if you don't know the basics.
If I can provide people with just a quick highlight reel of essential knowledge of data structures then I've done what I set out to do.
I hope Hacker News can appreciate that, I don't expect it to, but I can hope.
Also, there is no TOC to gloss over, the ascii, cute as it is, is harder to fly over than legit text with embedded code snippets.
But then again I don't know why you thought your opinion mattered if you didn't even read it. I guess that is the quality feedback I do expect from Hacker News commentors though.
self.i +=1
if self.i > len(self.a)/2:
self.a[:self.i] = []
self.i = 0
I didn't test the above code, and I am only 50% sure it is bug-free. I'm 99% sure the leaky version is bug-free. Memory leaks are not a bug if I document them, right? ;)But yes, periodically deleting the wasted space is still easier than trying to do the usual thing with circular buffers and stuff :)
He's just saying that the hash table is pretty useless if two random keys could access the same memory.
That is already mentioned in the document itself. Also mentioned is that a proper implementation would have to deal with collisions.
As to it being useless.. the value of content is in its explanation of simple concepts, not in some imagined production-quality requirement that people want to assume it must have.
The value of an explanation of simple concepts is in their simple AND adequate explanation.
You can cut the implementation details, but can't cut essential properties to simplify, because then you're not explaining the original concept at all.
For a hash table, the general "promise" is that you map a very large space of keys (e.g. all strings) to a very small space of indexes using a simple function. Common sense might tell you that this shouldn't be possible ("how can you put something big into something small?") - and of course actual hash tables solve the conundrum by acknowledging collisions and defining ways to deal with them.
But by saying "let's assume no collisions" the reader is asked to just ignore the logical contradiction instead of solving it. That can lead to frustration in the best case or to serious misconceptions in the worst case.
Of course there is nothing wrong with saying "let's ignore those points for now, I'll explain later". Also I guess it depends very much on the learning style of the reader. But bad simplification can be very annoying for some learners.
Well, AFAICT there is no mention of any of this in the document. No "promise" or any such thing has been said or implied. Please stick to what the author has actually said rather than what you imagine people are thinking about when reading the document.
>. Common sense might tell you that this shouldn't be possible ("how can you put something big into something small?")
No, it doesn't tell me that at all, because that point is not brought up in the document. But is that how you think most people learn? Using common sense?
>But by saying "let's assume no collisions" the reader is asked to just ignore the logical contradiction instead of solving it.
Sure, you think those are the logical contradictions in the readers' minds. Can you actually establish that?
> But bad simplification can be very annoying for some learners.
A list of what is annoying for "some" learners is quite possibly very very large. Lets not....
--
Anyway, we can go down this rabbit hole, but it isn't actually productive, and quite boring to be honest. My point is that every-time someone tries simplify something for beginners, people seem to relish that opportunity to show everyone how "smart" they are about trivial data-structures. Yes, if you want somebody to make an expository article for beginners with the detail of something like TAOCP, then yeah, you're going to be disappointed. But, you can and should learn Newtonian physics, even if its "wrong", before you move on to Einstein.
I'm not sure you got the parent's comment. What you wrote about is true -- and that's what's wrong with the document. That it doesn't mention such a promise, not it describe an actual hash table implementation (where collisions are inevitable and should be dealt with).
>Please stick to what the author has actually said rather than what you imagine people are thinking about when reading the document.
Again, the problem is that people sticking with "what the author has actually said" will not learn how hash tables actually work.
>No, it doesn't tell me that at all, because that point is not brought up in the document. But is that how you think most people learn? Using common sense?
Now you're just being contradictory to be contradictory. Or trolling.
Yes, people use common sense to learn -- and to understand what they are learning. How is this not obvious?
>Sure, you think those are the logical contradictions in the readers' minds. Can you actually establish that?
I'm a reader, and immediately jumped to see the same logical contradiction.
Not even sure what you're trying to defend exactly. Sloppy examples?
Huh? People are complaining about the implementation not having collision detection. The author clearly lays out what collisions are, why they are required and also that they need to be dealt with. Did you read the article?
>Yes, people use common sense to learn -- and to understand what they are learning. How is this not obvious?
It would help if you didn't change the context and scope of what I have said. I am not talking about some random topic that you can derive through first principles or common sense or other logical means. To me its obvious you didn't understand what I meant or what I was replying to. Its pointless to argue further and derail the thread.
>Not even sure what you're trying to defend exactly. Sloppy examples?
Not to sound gratuitously rude, but if you don't know what my point is, why not ask me first?
Eh, for a certain definition of "algorithm". Plenty of signal processing algorithms, for instance, have nothing to do with data structures.
It has nothing to do with the theory of the algorithm. But everything to do with the implementation. So I think the original statement is true.
> algorithms are implemented with data structures
MIN := X[N]; k := N;
for j := N-1 step -1 until 1 do
if X[j] < MIN then
begin MIN := X[j]; k := j;
end;
[0] https://assets.cs.ncl.ac.uk/seminars/139.pdfSure, but then that's not the entire implementation, error: X is undefined. If you want to actually run that code, it needs to be one of those (or many other) things.
Algorithms + Data Structures = Programs
[ 1,2,3,undefined/null,undefined/null,undefined/null,undefined/null,undefined/null,4,5,6,undefined/null,undefined/null,undefined/null] - With the hashtables function, if you accidentally generate an index that is say 100,000, wouldn't you end up with an unwieldy-sized array that would be more difficult to search than one like this:
[{ value: 1, index: 103405}, { value: 2, index: 14550 }]
Or does JS store the arrays as an object internally and just stringify them with all the blanks?
Also, the part where it explains why memory is zero-addressed is so wrong, it rustled my jimmies.
That is why the word 'simplified' appears in the title, and the words 'super simplified' appear in the linked document. The purpose is to convey a point, and take away other distractions. Its probably not a good idea to introduce calculus to first graders either. If you don't think omitted content is a distraction, then it's probably not meant for you.
Second, I don't think the best place to go on lengthy explanations with figures included is in the comments of a source code file. Markdown is your friend.
I have 2 issues with this [..] I don't read stuff on data
structures to amuse myself. I want it to be as succint and
to the point as possible and not waste my time kidding
around.
Someone should write a serious data structures book for you. Oh wait, they have, there are literally hundreds of them.If you're attacking a topic with your full attention then you want maximum information as fast as possible.
If you're tired on a friday and want to learn something and have fun then information density doesn't matter anymore.