TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Itsy Bitsy Data Structures – Simplified examples of many common data structures

223 pointsby thejameskyleover 8 years ago

11 comments

thejameskyleover 8 years ago
Hi I wrote this thing. I guess I&#x27;ll comment on this thread since it got some attention.<p>I think a lot of people that are in this thread went into this project with the complete wrong state of mind.<p>I&#x27;m not trying to teach people how a hash table or linked list implementation works. I&#x27;m not trying to make a library that is useful to anyone.<p>What I&#x27;m trying to do is connect the dots between a bunch of different important concepts in data structures.<p>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.<p>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&#x27;t get as much out of them if you don&#x27;t know the basics.<p>If I can provide people with just a quick highlight reel of essential knowledge of data structures then I&#x27;ve done what I set out to do.<p>I hope Hacker News can appreciate that, I don&#x27;t expect it to, but I can hope.
评论 #12372966 未加载
评论 #12373536 未加载
评论 #12374570 未加载
marvyover 8 years ago
Most languages have a built in type for a dynamic array, but many of them lack a built-in queue. I have a favorite trick for a quick-and dirty queue in those languages. You need an array (initially empty) and an integer (initially zero). To add to the queue, add to the array. To get the front of the queue, just do array[int]. And finally, to remove from the queue, simply increment the integer. The advantages of this approach are simplicity and speed: each operation takes amortized constant time. The obvious disadvantage is that it&#x27;s potentially a major memory leak. For instance, if you try to do breadth-first search of a tree using this queue, your memory usage will be proportional to the size of the tree. How much worse than optimal is this? It depends on the tree. If it&#x27;s a complete binary tree, you&#x27;ve doubled your memory usage, which might not be too bad. But if the tree is a path, then you use linear memory, whereas a proper queue would only use O(1) memory.
评论 #12370193 未加载
评论 #12371698 未加载
评论 #12370097 未加载
jscheelover 8 years ago
Seems to be a lot of snark in this thread already. If you see a problem, create an issue or submit a pull request. It&#x27;s great that OP is trying to help spread knowledge.
notsorandomnameover 8 years ago
Hash table realization seems to be harmful with the &quot;no collisions&quot; assumption. That&#x27;s like writing a red black tree and assuming that insert&#x2F;delete operations will keep tree balanced so we don&#x27;t need rotations.
评论 #12369770 未加载
评论 #12369208 未加载
评论 #12369716 未加载
nooberminover 8 years ago
One thing&#x27;s for sure, it caught my attention. Humungo text that made me chuckle. Then, I clicked on the text, and <i>it</i> was the example. Pretty clever.
mthomsover 8 years ago
At first glance, this looks like it could be a useful reference. Regardless it&#x27;s worth a visit for the ASCII art alone. My favorite: the literal interpretation of &quot;hash tables&quot;.
vonmoltkeover 8 years ago
&gt; algorithms are implemented with data structures<p>Eh, for a certain definition of &quot;algorithm&quot;. Plenty of signal processing algorithms, for instance, have nothing to do with data structures.
评论 #12369632 未加载
评论 #12369401 未加载
kylehotchkissover 8 years ago
Question: for the hashtables example, it looks like it&#x27;s setting arbitrary indexes inside a JS array, instead of incrementing ones. IIRC, Javascript stringifys arrays with gaps like this:<p>[ 1,2,3,undefined&#x2F;null,undefined&#x2F;null,undefined&#x2F;null,undefined&#x2F;null,undefined&#x2F;null,4,5,6,undefined&#x2F;null,undefined&#x2F;null,undefined&#x2F;null] - With the hashtables function, if you accidentally generate an index that is say 100,000, wouldn&#x27;t you end up with an unwieldy-sized array that would be more difficult to search than one like this:<p>[{ value: 1, index: 103405}, { value: 2, index: 14550 }]<p>Or does JS store the arrays as an object internally and just stringify them with all the blanks?
评论 #12369858 未加载
HiroshiSanover 8 years ago
This is fucking awesome, did you draw the ascii pictures yourself?
zeuskover 8 years ago
This is too dumbed down, imo.<p>Also, the part where it explains why memory is zero-addressed is so wrong, it rustled my jimmies.
评论 #12369747 未加载
andrepdover 8 years ago
I have 2 issues with this. First, you could say what you wanted to say in 1&#x2F;3rd of the length if you weren&#x27;t speaking in such a conversational manner and interspersing your discourse with irrelevant jokes and stuff like &quot;&quot;OOooooOOOooh <i>soo</i> exciting&quot; right?&quot;. I don&#x27;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. If I want to kid around I will do something else. But I guess some people prefer this, I suppose.<p>Second, I don&#x27;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.
评论 #12370874 未加载
评论 #12371074 未加载
评论 #12371651 未加载
评论 #12370792 未加载