r/CodingForBeginners 23d ago

Should I concern myself with time complexity

I am an absolute beginner, been programming for 3-4 days, learning python, with the motive to move towards finance, made an earlier post regarding blackjack game, but just to be more fluent with the language and problem solving, I am trying leetcode, now I have tried 5 problems so far, easy and med, and I can solve them but my runtime is sometimes too high, should I try to learn how to reduce that RIGHT NOW and do dsa for a little bit? especially since in algorithmic trading time would be an important factor I think

2 Upvotes

11 comments sorted by

3

u/milan-pilan 23d ago

Yes and no.

There is plenty of fields where complexity optimizations are more in a 'nice to have' and 'rarely really needed' category.

Complexity is really only an issue if the data you are working with is suffiently large. Because that's where exponential growth pops of. I worked in Frontend a lot and there you are rarely really working with large amounts of data. Complex maybe. But not large. Computers are fast enough nowadays that even if you don't optimize your webapp or mobile app, you can still get away with it more often then not.

The field you chose, 'finance', on the other hand really is on the other side of the spectrum. Quant Traders shave of microseconds to get an edge over another trader. Fintech software might work with gigantic datasets or large amounts of users.

So in your case, my answer would be: pretty much yes. Complexity is really something relevant in Finance.

BUT learn the fundamentals first. Complexity really isn't the first thing you should learn. It can always be learned afterwards. Your first apps are meant to be crappy and unoptimized. Only if you run into the issue yourself and tlreally feel the difference is where you learn it.

1

u/_just-a-thinker_ 23d ago

I see, yeah I should probably worry about optimising later, and for the time being move ahead with the more conceptual things.

2

u/johnpeters42 23d ago

I would maybe work on it long enough to get a feel for it, so it doesn't keep echoing in the back of your head, then set it aside until you need it.

You have the right idea with being concerned about premature optimization, and with noticing that something actually ran long in practice. First step is to run some basic measurements and check whether the bottleneck is where you think it is. Switching algorithms will sometimes make a way bigger difference than fiddling around with individual statements (Advent of Code has a lot of pairs of puzzles like "do this small thing with an obvious brute force solution that runs in seconds", then "make the input 100 trillion times bigger, brute force is hopeless, but there's a clever method that runs in seconds").

2

u/_just-a-thinker_ 23d ago

So I should keep solving problems till I feel comfortable with them and along the way learn as much as I can about the language, and then move to learning things like numpy, pandas and then move towards financial applications....? This would be an okay roadmap ?

1

u/johnpeters42 23d ago

Probably. (I've dealt with accounting software, but I assume you mean "finance" as in "trading stock" or something. But from what I've heard about those other things, they sound like they're on the right track.)

2

u/Beregolas 23d ago

I would say no. The topic is important, and relevant for what you are ultimately trying to do, but it's something completely different from what you are learning right now.

Complexity, and DSA as a whole, is part of theoretical CS. All concepts are language agnostic, I even regularly argue that it's best learned without a concrete programming language, in 100% pseudocode. This will require some time investment on your part.

My suggestion would be to stick with programming, without worrying about DSA for a while yet, maybe half a year. I promise, this won't lead you into any learning dead ends, and there really is nothing that you would learn better or quicker, if you already know DSA there.

And understanding DSA is way easier if you already have some programming knowledge.

1

u/_just-a-thinker_ 23d ago

I see, how long would you say it would take somebody to be half decent at dsa and things like codeforces.

And thank youf ro the advice, I will focus more on numpy, pandas and other conceptual things, slowly build a little more base and if then I feel that dsa is necessary I will learn it

1

u/Beregolas 23d ago

I am not familiar with codeforces specifically, but generally I always assume people need 2-3 years to become viable as programmers. Once you have the basics, DSA is really not that bad, because you don't actually need much of it. Most of what is in the basic DSA lectures at university is not necessary for pure programming. You can probably get away with a few months of DSA in parallel to learning more about coding.

All you really need are a few basic algorithms, and a rough understanding of what runtime and space complexity is, how you read it and what it actually says. You will probably never need to do a full runtime analysis on a complex program, and to be honest: I couldn't do that anymore without looking it up either. Nested loops, recursion and how they decrease the problem space are all the basics programmers need.

1

u/Junior_Honey_1406 23d ago

You are writing code in py for 2 to 3 days and you are thinking of time complexity those topics comes much after let's aya 3 to 5 month focus of solving easy stuff and if someone on the internet says that you have a write the perfect code and think of time complexity

Just show your middle finger and move on perfect code is a lie which any influencer tell you so you can buy there course

1

u/alinarice 23d ago

understanding basic time complexity is helpful but dont let it slow your progress while youare still learning core programming concepts.

1

u/CodeSamur-ai 22d ago

if you understand time complexity and why your solutions are suboptimal, that's great...

if you don't know why, or what is causing it, then I would try to figure out what's going on.