Which data structures must I learn for my first job?

Hello guys, so as I was searching the event loop (in JavaScript) and I reminded myself of how asynchronous code (HOC) work behind the scenes (stack->heap->queue), there Mr. Google gave me this article saying:

We will walk you through the top 6 data structures that any JS developer needs to know.

And they were:

    1. Array
    1. Queues
    1. Linked List
    1. Trees
    1. Graphs
    1. Hashtable / map

My two questions would be:

  1. By array in the context of data structures are programmers referring to the array object ? (then, I already know about it)
  2. How much of the rest of the five’s should I know for my first (possible) job, should I dive deep into them?

In javascript, yes. The plain old javascript object implements #6 unless you need something custom.

Depends on the job. If it’s development and not wordpress, probably all of them. Some difficult problems are rendered trivial by selecting the correct data structure. You should also be aware of other data structures and be able to create your own by creating new classes.

I would recommend doing the data structure curriculum if you haven’t already. It’s a good start.

1 Like

Yes and no. Different languages provide different “built-in” to help you build your data structures you need. For example, the Array in JavaScript, not only provides a data structure Array implementation, but also can be used as a Stack, Queue, List, and even HashMap data structures without much if any manipulation.

Another comparison would be Python’s concept of a List. The name is different, but functionally Python’s list is similar to JavaScript’s Array, both of which can replicate more specific data structures as mentioned above.

So keep in mind the data structure concept is theoretical, but each language provides different ways, to implement those theoretical data structures. This is where the study of data structures and algorithms turns “away” from actual hard languages and syntax and more into the theoritical.

If you know what an Array is, and can do, and why you’d want one to solve a problem, you should be able to take that knowledge to any language and implement it and solve your problem without worrying much about the actual syntax of the language.

I’d know each of them at a good solid level where your comfortable working with them. As they are everywhere.

There isn’t really a scenario where you can completely ignore any of those data structures and be effective. Some pop up more often than others, but you should be aware of what they are and how you’d use them if the need arises.

Yes, in this context, an array is equivalent.

It’s unlikely you’ll need to know about any of them. This isn’t to say knowledge won’t be very useful generally, but the chances of you needing to implement any of them in basic day-to-day work in the vast majority of [JS-focussed] jobs is basically zero.

The list looks like a CS101-type list of things. If you had come out of a CS degree you would have been taught them very early on. If you are self-taught it’s very likely you wouldn’t have looked at them at all unless you made the effort (YMMV, depends on what you were doing), as, bar arrays, it’s unlikely that you would have needed them.

Re JS, which is a lightweight very high-level language (ie it does most of the low-level things for you) primarily used for scripting functionality in web browsers (web GUI stuff):

  • Arrays: core data structure, a type of object, used everywhere. Note that in other languages, array often refers to an ordered, indexed collection of one type of thing of a specific size (in terms of how much memory it is allowed). In JS it’s just an ordered indexed collection that can contain anything and be any size.
  • Queues: trivially easy to implement on top of arrays, just look at some examples. There is a challenge in the FCC data structures & algorithms cert that asks you to create a function called standInLine; that’s a queue. Also see Stacks, which are very similar and very easy to understand and implement.
  • Linked List: arrays have an issue that, when you add elements to them anywhere except the end, indexes all need to be recalculated, all needs to be resized. Linked lists exist to get around this issue; the tradeoff is that you need to iterate through the whole list to actually find anything. Not particularly important w/r/t JS. Stereotypical whiteboard interview question is “how do you reverse a linked list”: afaik this is mainly due to it being important thing for C developers in the early 1980s :man_shrugging:t3:
  • Trees: you have a thing, which has some connected child things, and each of those also have child things. Very common in front-end web development because it’s what HTML documents are. However, actually creating trees or programs that walk trees in the normal course of JS Dev, less common. V useful to understand how to walk a tree structure though (Edit: this is where you want to understand recursion. Also any recursive program can be rewritten using a stack, so worth understanding how to do that).
  • Graphs: you have lots of interconnected things and you want the ability to record and analyse relationships between them. Extremely useful for a very large set of problems, none of which you are likely to need to tackle at your first (or second, or third) job. However, like trees, v useful to know what they are cos lots of stuff is based on them: so as one example, Facebook. As another example related to that, when you get an advert appear that seems uncannily specific, more than likely that’s just dumbly inferred from a graph of your data.
  • Hashtable: afaik, strictly speaking, cannot be properly implemented in JS because you don’t have access to the underlying memory model.

Following you should know, but you don’t really need to implement them or anything, just know how to use them:

  • Map (not Hashmap): is built into JS, ordered collection that maps a key to a value, very useful but API is not great so most of the time people just use objects instead.
  • Set: is built into JS, ordered collection where every element in it is unique. Again, very useful, and again API is not great (it’s missing really useful set-based things that other languages have).

Edit for completeness:

Also, WeakMap and WeakSet (versions of Map and Set that help deal with certain memory issues) exist but it’s highly unlikely you’re going to need to reach for them or understand them in any detail for 99% of day-to-day usecases.

And there are things that are sorta like arrays (have the same basic API) called typed arrays, they are for dealing with binary data. Again, unlikely you’ll use them, but there are situations like streaming data or graphics where they’re used relatively commonly. Very specialised though.

1 Like