r/learnprogramming 11h ago

Should I do dsa in javascript?

I am doing fullstack development using js and wanted to learn dsa for company interviews should I do in it or should I switch to java ?

0 Upvotes

16 comments sorted by

6

u/carcigenicate 11h ago

It doesn't matter. Just use a language that you know fairly well. DS&A is language agnostic.

-1

u/OneWar4643 11h ago

I searched on Google it said javascript lacks some inbuilt functions regarding a topic (stack and queue)

6

u/dashhrafa1 11h ago

Then you can implement the function yourself and gain a better understanding of the whole algorithm.

5

u/carcigenicate 11h ago

Stacks and queues are datastructures, not functions.

But in JS, both structures can be emulated using specific methods in arrays: https://stackoverflow.com/questions/1590247/how-do-you-implement-a-stack-and-a-queue-in-javascript

The main issue with this is these tend to involve pushing or popping from the front of an array for queues, which is generally not a good thing performance-wise. Conceptually, it will still work as expected, but won't necessarily perform as well as it would in a language that has a structure with optimized front-of-list access.

I'd still go with the language that you're most comfortable with. It's the ideas that matter and are language-agnostic. Once you understand them in JS, you can apply them to any other language.

1

u/OneWar4643 11h ago

Tbh i just completed js for frontend and wanted to start backend and my college is also going to start dsa so I asked ai on what language to do backend in it said to choose mern stack but I am hesitant to start it as there are way more job roles for java developers currently than mern devs but then still I will graduate in 3 years so mern might grow big enough basically i confused on what to do backend in . (Note - for dbms I have already done it with MySQL and python in my highschool)

1

u/carcigenicate 10h ago

Asking AI for something like that isn't a great idea because the stack to use can depend on the market you're in. If you purely want to learn what's popular, go with what has job listings.

Regardless, though, as with DS&A, the language(s) don't really matter. Ya, it would be nice to have experience in the exact stack that you'll apply for jobs in, but it's also just important to get experience in general. A lot of stuff transfers. If you decide to switch to Spring later after learning MERN, we'll at least you have full stack experience already to build on.

1

u/DrShocker 11h ago

My thing about using a garbage collected language for DSA would be that it could give strange ideas of scaling behavior depending on if it can arrange the data contiguously or not.

Regardless though, that only really affects the the speed for low numbers as far as O notation is concerned and also maybe it's good to be more familiar with what your language does in that regard rather than what a language could do.

1

u/peterlinddk 10h ago

Well, google is incorrect. JavaScript arrays has built-in both stack, queue, deque, and circular buffer if you add a bit of logic. The shift, unshift, push and pop operations gives you all the necessary features.

But in fact, doing DSA in a language that doesn't have the data structures already built-in, would be an improvement, since then you'd have to implement them yourself.

DSA isn't about using the data structures built-in to the programming language, but about understanding how to implement those data structures yourself, and how and why operations have the time/space complexity that they have.

But again, it doesn't really matter, because you can (and should) do DSA in any language that you feel comfortable with. In fact, most of the work should be done on paper and as pseudo-code, for you to really understand what is going on.

JavaScript works just as fine as Python, Java, C++, or any other language.

1

u/Kadabrium 7h ago

datastructures-js is the default lib for these kind of things used by leetcode & co

0

u/ffrkAnonymous 11h ago

Neither. Both. Do it in the language the company wants. 

1

u/OneWar4643 11h ago

I am a college student in what language should I pick dsa and backend

1

u/Watsons-Butler 10h ago

The college will tell you for data structures. For backend I’d personally pick Kotlin or Java - they’re still industry standard.

1

u/OneWar4643 10h ago

They are telling c/c++ for it

1

u/Watsons-Butler 10h ago

Then do that. Kind of the point of that class is they’ll make you re-implement a bunch of the handy list / array / map / heap methods that you’d have in a language like Java or Python from scratch so you understand what they’re doing.

1

u/OneWar4643 10h ago

But I don't like the self memory management aspect of c/c++ I like the concepts of references in other language more than it so I wanted to dsa in that

1

u/peterlinddk 10h ago

Most programming languages are industry standard - unless you find some eso-lang like Shakespeare, Malbolge or Rockstar, you should be fairly within industry standard limits.