Jump to content

Problems faced while learning data structures and algorithms:

shivajikobardan

1) How long should I wait  before I can't find a solution with my own brain?

 

2) I read the algorithm, I Understand the algorithm but I could not think of that algorithm by myself. 

 

For eg: To remove duplicate elements from an array. I am stuck on this since yesterday. What are the preriquisites to understand this algorithm? Is there a site that has a list of problems to solve. I am from a country and generally harder questions aren't asked in interviews here. Plus my level is not that high already to solve codewars problems. What websites do you recommend for me. I for one found codeforwin.org exercises just around my level(difficulty is still high for me here).
 

 

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, shivajikobardan said:

For eg: To remove duplicate elements from an array.

Solve the problem in the brute force way first, then try to come up with better solutions. How would you do it by hand? Write some numbers on sticky notes then try to remove the duplicates.

17 hours ago, shivajikobardan said:

How long should I wait  before I can't find a solution with my own brain?

Spend as much time as you think is reasonable, there is noting wrong with looking at solutions, just make sure you understand what every line does  and don't copy paste code.

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

First just try to get it working, even if its the dumbest most naive approach.
Then, try to get it right, clean up the code, document it, improve the ancillary aspects, and enforce best practices.

Then, if needed, try to optimize it.

 

That's how I approach every software problem and funnily enough, usually by the time I am through step two, I don't even need to do step 3 anymore.

 

Not an exact answer but maybe it can be helpful for you.

If your question is answered, mark it so.  | It's probably just coil whine, and it is probably just fine |   LTT Movie Club!

Read the docs. If they don't exist, write them. | Professional Thread Derailer

Desktop: i7-8700K, RTX 2080, 16G 3200Mhz, EndeavourOS(host), win10 (VFIO), Fedora(VFIO)

Server: ryzen 9 5900x, GTX 970, 64G 3200Mhz, Unraid.

 

Link to comment
Share on other sites

Link to post
Share on other sites

I would suggest taking a sheet of paper and trying to solve the problem on the sheet of paper.

For example, think of 5-10 random numbers, write them down,  and duplicate 2-3 of them and put those duplicates randomly between numbers you wrote.

Then think how would remove the duplicates.. what would you do to remove duplicates?

Once you determine that, you would transpose that to code.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

More of a general piece of advice - The way I always try to work through complex coding issues is to write out what needs to happen using pseudocode, step by step.

Be sure to write down the values of assigned variables as well to keep track of how they change.

This can be tedious, but I find that it helps dissect the operations needed to be performed.

"Time will pass anyways so might as well make some progress towards your goals" - Will Tennyson

Link to comment
Share on other sites

Link to post
Share on other sites

Don't crutch but....

Sometimes seeing someone show you how to do a problem or two can help you understand how to solve future problems on your own. 

 

Don't make it a habit, and pick a number now for all the ones you're allowed to cheat with. Then see how you can do it. 

 

I agree with the pencil and paper methodology recommended above. 

Some data structures and algorithms are really complicated. 

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/2/2023 at 11:56 AM, shadow_ray said:

Solve the problem in the brute force way first, then try to come up with better solutions. How would you do it by hand? Write some numbers on sticky notes then try to remove the duplicates.

Spend as much time as you think is reasonable, there is noting wrong with looking at solutions, just make sure you understand what every line does  and don't copy paste code.

I wholeheartedly agree with what shadow_ray has said.

 

On top of their response, I highly recommend checking out ThePrimeagen's free Front-end Masters course on DSA, link here: https://frontendmasters.com/courses/algorithms/

He goes over each DS and A in a very easy-to-understand way, while also bringing some humor into each topic.

Highly recommend checking it out as, again, it is entirely free, but goes over most of what you may want/need in an excellent way.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×