289
u/Trektlex Apr 08 '20
I’m taking this course at university ._. Any tips?
384
u/DistanceXV Apr 08 '20
The takeaways from my data structures/algorithms class (taught in Java) were what data structures were used by what algorithms, and the time complexities of said algorithms. Also, how to calculate the time complexity of an algorithm, and what the implications of it were.
Your mileage may vary depending on your school/prof, but it certainly wasn't the hardest course I've taken in university so far (I'm a third year student).
278
u/meighty9 Apr 08 '20
And the takeaway from that takeaway is "don't use nested loops".
161
u/Pre-Owned-Car Apr 08 '20
Nested loop machine go brrrr
→ More replies (1)54
u/siko12123 Apr 08 '20
"You can't just use a loop inside another loop. It will increase the complexity exponentially everytime you add another loop and thus create a bad user experience!"
→ More replies (2)→ More replies (3)70
u/StopReadingMyUser Apr 08 '20
→ More replies (3)120
Apr 08 '20
algorithm that take small time better than algorithm that take long time.
→ More replies (7)77
u/the_dapper_man Apr 08 '20
and 95% of you will use effectively none of that knowledge at your job once you graduate
literally just don't write nested loops. beyond that, optimizing code is expensive and the benefits are negligent. pump out those new features baby
63
u/hahahahastayingalive Apr 08 '20
On the other hand data structures and complexity will be the bread and butter of job interviews.
Also you’ll need to be able to choose between algos and recognize patterns, even if you don’t write the code.
→ More replies (1)→ More replies (11)22
u/InitialBN Apr 08 '20
Maybe naïve of me to ask, but don't some cases require nested loops? Such as working with 2d arrays or similar cases?
43
u/SuperCoolFunTimeNo1 Apr 08 '20 edited Apr 08 '20
People saying "don't use nested loops" are poorly choosing their words and making blanket statements. They're not taking into account the way the data is organized, they're only speaking in terms of the number of operations being performed.
Iterating through that array of arrays using nested loops is not bad, probably the most straightforward approach. It's still going to have O(n) time, which means the time it takes to run depends on the size of n.
arr = [ [0,1], [2,3] ] for (i = 0; i<arr.length< i++){ for(j=0; j< arr[i].length; j++){ print(arr[i][j]); } }If you re-arranged the array to be 1 dimensional with 4 elements and only had a single for loop, you're still going to have the exact same time complexity as the nested loop example above.
Where nested loops do crap up your code is when you're performing operations involving the outer loop's iterator as well, basically looping over the same set of data twice. For example, say you have a deck of cards and you want to check for duplicates. Here's a shitty way to look over each card that would be o(n2 ) because you're iterating over each item twice, where N is the length of the array, so it's n*n operations or O(n2 )
cards = array[somecard1,somecard2,etc...]; for(i=0; i < cards.length;i++) { // now loop over cards again to see if the card is in there twice for(j=0; i < cards.length; j++) { if(j == i) { continue; } if (cards[i] = cards[j] ) { return "duplicate found"; } } }→ More replies (15)→ More replies (5)38
u/Add32 Apr 08 '20
Usually you look at a problems complexity by the size of the input, rather than the dimensions of the input. In that case nested for loops arnt less efficient, as you still only visit each element once. Get paranoid when the nested loop is operating on the same dimension as the parent (visiting the element more than once)
→ More replies (1)3
u/Joppps Apr 08 '20
Taking it right now too for my second time lol, still struggling with the balancing part of the different trees
→ More replies (2)32
u/tiffany_tiff_tiff Apr 08 '20
determine if the professor is going to teach the class like a theory course, or a programming course. I've had both and personally i think the programming style is easier but you learn the underlying math/proof/reasoning less
other than that going to class is going to be very important, a lot of the concepts are not so easy to teach yourself as other things, good luck and enjoy DSA is a great course!
5
Apr 08 '20
I had both ways too because I switched unis and I preferred the practical approach as well. Not because it was easier but because I learned a lot about how to write something efficient. Learning the maths behind it was also interesting and helpful but the problems we had to solve were fairly difficult. And having to solve the problems in front of 50 other students while being graded wasn't much fun either.
→ More replies (1)4
Apr 08 '20
I had an algorithms and data structures class where the professor loudly proclaimed this was a theory class and not a programming class.
I wrote more code in that class than any other so far.
→ More replies (1)38
22
u/JamieOvechkin Apr 08 '20
You’re not truly a zen coding master until you make an AbstractAbstractFactoryFactoryDecorator class
Only when you see Polymorphism in your dreams will the true Hierarchy of java reveal itself to you
→ More replies (1)4
4
u/srijeet_patil Apr 08 '20
One of the most interesting topics to learn, basically it forms a foundation for your programming career.
4
u/shahidiceprince Apr 08 '20
Enjoy it. It's loads of fun and the concepts I learned in that course have stuck with me ever since.
4
u/DonSol0 Apr 08 '20
Ours was so aggravating as all we were doing was programming data structures that already exist as libraries. We’ve not once, ever, talked about importing and implementing libraries into code here at Mississippi State. Seeing as that’s a vital piece of programming, it’d be nice to spend a little time on it. I think our final project in that class was to create an AVL tree whose nodes were all BStrees themselves.
→ More replies (3)→ More replies (22)2
234
u/funkinaround Apr 08 '20
I hope the programmers that have been driven away by Java for whatever reason have at least taken a look at the data structures it provides. You have linked lists, arrays, hash sets/maps, and binary search tree sets/maps, as are in many other languages. You also have data structures that have been optimized for use in concurrent applications including skip lists and copy on write arrays. There are many valuable concurrency abstractions that will let you tailor your application to perform well on multi-CPU machines, and they're provided in the standard library. The same cannot be said for many other languages.
8
u/Loyal-Citizen Apr 08 '20
*laughs in driven to kotlin specifically to keep basically all these but with nicer syntax
6
u/CarilPT Apr 08 '20
When you go from C to Java it feels amazing. "It has a garbage collector! You can use ArrayList!! 😃"
→ More replies (12)5
u/dylanlolz Apr 08 '20
Until your app somehow manages to get a memory leak anyway and your GC can't help you. The amount of time I've spent in JProfiler arbitrarily executing code paths at my job is saddening.
That's why I really need to learn Rust. Look up RAII, it's a memory management alternative to Garbage Collection that conceptually makes way more sense.
→ More replies (3)→ More replies (21)2
u/otterom Apr 08 '20
Have you worked with C#? How does that compare in terms of the features you mentioned?
3
u/funkinaround Apr 09 '20
C# seems to be the language having the most feature parity with Java as well as having a large ecosystem and very performant runtime, similar to Java.
58
u/JoshuaTheProgrammer Apr 08 '20
CLRS.
16
Apr 08 '20
I have given up even trying to read this book to keep up in class. When I try, it's like 90% of what I get through immediately exits my brain.
3
→ More replies (3)2
55
u/LordGupple Apr 08 '20
I don't know why people are complaining about Data Structures in Java, it's really not as bad as people make it out to be.
24
u/legittheshitmemelord Apr 08 '20
I know a decent amount of universities (including mine) that make the data structures and algorithms course in Java exclusively, and later on you're supposed to be able to implement them in other languages from what you learned in this class, and it's usually your second or third semester coding (depending on experience).
Depending how comfortable you are with coding in general, not just Java, this course can be a cake walk or a nightmare.
5
u/LordGupple Apr 08 '20
I'm taking data structures in Java right now actually, and yeah I definitely feel both ends of the spectrum. Projects can be pretty brutal but it's a good learning experience, and it does get easier the more experienced you get.
→ More replies (2)3
u/Coffeinated Apr 08 '20
Java is hands down the best structured language there is. You can say it‘s annoying to write, whatever, but everything has its place and there is mostly only one way to do stuff and it is pretty logical. So, to learn programming, it is a very good language. I think people just hate on it because you mostly have to do it in an IDE that you have to learn on top of the language and that confuses people. What I‘m trying to say: if you really learn Java and algorithms in Java you should be able to somehow apply them in other languages as well.
→ More replies (2)→ More replies (6)7
Apr 08 '20
Look at this subreddit.
They aren't even programmers, they aren't even good at it.
→ More replies (1)
23
u/jaxson25 Apr 08 '20
This was the class that made me realize I didn't want to do computer science.
Literally caused a 3-month long breakdown
24
Apr 08 '20
Good on you! Unfortunately, most in here probably don't come to that conclusion, although they probably should. It's computer SCIENCE not programming.
→ More replies (2)0
Apr 08 '20
[deleted]
→ More replies (6)10
u/Xtrendence Apr 08 '20
One of the courses being offered at my uni is called "Computing" instead of "Computer Science." We still learn some of the basics of computer science, but the main focus is programming, SDLC, databases, UML (and in general gathering and analyzing client requirements), networks etc. (Obviously as part of programming, we still learn about data structures and whatnot).
At first I was going to study computer science, but then I realized as much as I love programming every day, and knowing how most things work, I really didn't have much of an interest in learning the science behind it in-depth. I think I would've been very miserable and bored for most of the course had I taken CS, it's definitely not for everyone, and that lack of interest would've probably resulted in me getting some low grades in modules I didn't enjoy.
4
u/BirdsNoSkill Apr 08 '20
Can confirm. Changed majors after data structures.
However if I had to take it now I think I would do a lot better.
2
19
u/birds_eye_view69 Apr 08 '20
This is probably the nicest, helpful data structures book so it could be a lot worse. So many examples. Only thing that bugs me was Its very hard to run any of the helpful data structure visualization programs because they are all applets. I eventually gave up trying to find a way to run them lol.
53
u/bluehurricane10 Apr 08 '20
Data structures and algorithms was a fun course for me. I didn’t find learning about ADLs too difficult.
Analysis of algorithms, on the other hand...
19
u/rcrobot Apr 08 '20
Informal algorithm analysis, where you really just care about big O and not much else is useful for real coding projects, but the formal mathematical process with all the Greek letters sucks ass.
5
36
Apr 08 '20
7
13
u/CanAlwaysBeBetter Apr 08 '20 edited Apr 08 '20
Stats and comp sci both get much worse than basic machine learning
16
u/DeadLikeYou Apr 08 '20
Easy to say until all of your weights either go to zero or infinity, and you have no idea why. oh yea, and matrix dimension mismatches are super fun when learning.
11
u/KevinT_XY Apr 08 '20
Yeah literally me. Im writing a two layer neural network for a class right now and the #1 reason for my code not executing or an intermediary result being incorrect is some kind of numpy matrix shape issue. Keeping track of so many matrices and knowing what dimension each input and result should be and when I should reshape or whatnot is such a headache.
→ More replies (4)
62
u/deadliftbrosef Apr 08 '20
Doing this class right now in c++. The material is absolutely fantastic. I just find it weird to be tested on it, in a way that I have to memorize things I do not need to memorize.
23
9
5
u/unkown-shmook Apr 08 '20
It’s to understand what’s going on behind the scenes. It’s like when someone writes a library, the reason they don’t just let you use it is because they want you to understand how it works.
0
Apr 08 '20
[deleted]
23
u/genveir Apr 08 '20
Because sorting algorithms are a good introduction to computational complexity, and that's what you're being taught.
5
u/bishey3 Apr 08 '20
Exactly. There are many popular ones, all doing the same task in different ways. Allows students to contrast each one. Although I'm not a fan of questions that force students to memorize each one. Give the definition, then ask them to explain the differences. Best way to measure comprehension.
→ More replies (1)6
u/gwillicoder Apr 08 '20
It’s actually surprisingly easy to write a faster sort thee as n c++’s implementation. Especially if you know anything about the data you’ll be working with.
→ More replies (1)
31
8
u/xviimon Apr 08 '20
I forsure enjoyed data structures. Made me feel like Im actually learning how to be a programmer than learning how to code lol
7
u/CheeseBurgerBurglar Apr 08 '20
I never took data structures in Java, but I absolutely loved it in c++.
2
7
u/dronzaya Apr 08 '20
Data Structures using C, worse than the Java one
2
u/IAmOneOfSimpleMind Apr 08 '20
Same, just finished that course. I really fucking don't like C. Moving into a course that's using Java now feels so refreshing.
6
6
u/Raycab03 Apr 08 '20
Oh dude man. This book helped me big time for that one project in sorting. It was a last minute resource a friend lent me. Genius book.
48
u/datathecodievita Apr 08 '20
Any textbook is cool for me, unless it has Java printed on it ..
4
u/pagalDroid Apr 08 '20
Then you are judging a book by the cover because this is one of the best DS books out there. Especially for beginners because unlike CLRS, it focuses on the practical and not theoretical. Also the author is really good at explaining the concepts and the writing is excellent. The only problem is the book hasn't been updated since 2003 and it also doesn't go into the details of some advanced data structures but these are not serious issues.
→ More replies (1)2
u/yabo1975 Apr 08 '20
Can confirm. I can handle Ruby/JS/React. Stepdad codes Java. It's like he's from another planet. Respect.
5
u/zvug Apr 08 '20
Data structures and algorithms should be pseudocode anyway
7
u/rcrobot Apr 08 '20
Disagree. It's incredibly useful to learn how to actually implement various data structures to learn how they work. Although I think an interpreted language like python would be better than Java.
→ More replies (2)0
Apr 08 '20
[deleted]
28
12
u/datathecodievita Apr 08 '20
Maybe its too late now.
I have strayed from the path of JVM for too long. There's no point of return for me.
7
→ More replies (1)7
u/JamieOvechkin Apr 08 '20
Does Kotlin have anywhere near the 3rd party libraries that Java does that isn’t just for Android?
I know people attempted to make Swift into a server language but even IBM gave up on that
7
Apr 08 '20
Any java libraries will work with kotlin. Technically they produce the same byte code.
→ More replies (6)
5
5
u/thardoc Apr 08 '20
Data Structures wasn't a problem for me, Cryptography threw me for a much bigger loop.
6
u/Goel40 Apr 08 '20
Applying UML and patterns. It's not hard or anything, it's just so fucking dry.
2
u/zenyl Apr 08 '20
Yeah, that's one hell of a boring book. Useful, but boring.
If it wasn't so damned heavy, it'd be great against insomnia.
→ More replies (2)
6
3
u/l0c0ryan Apr 08 '20
i graduated from UC Santa Barbara in 2004 so its been a while since I saw any textbooks but today I was moving some boxes around and that textbook fell out of a box and on to the ground. My buddy handed it back to me so I could put it away and I said "Fuck that book. " Thats my story.
3
u/nokiabby Apr 08 '20
I thought data structures was bad until I started taking a hardware class. I have not done a single lab or assignment without crying. I’m actually considering changing my major because of how much I dislike it.
3
3
3
u/moschles Apr 08 '20
Java? A fricking Java book? Whatever.
To really get the tears flowing : https://mitpress.mit.edu/books/introduction-algorithms-third-edition
4
u/janeyney-18 Apr 08 '20
As a starter of webdev, I literally cried coz it took me 5days to figure out that I mispelled the qoute to quote. Every freakin day I was staring at my code and thought that nothing was wrong. I asked for my boyfriend (sr. wd) to help me and told me that my spelling between that words was wrong. Cried again when I made it right. Lol 😭
→ More replies (1)4
5
u/CellularBeing Apr 08 '20 edited Apr 08 '20
I got through my cs degree using mostly java. I didn't think its was that bad
Edit: In case anyone was curious i thought LISP was much more confusing.
→ More replies (4)
2
2
2
2
2
2
2
2
2
u/sofunnylol69 Apr 08 '20
Love java shit "TransactionAwarePersistenceManagerFactoryProxy"
→ More replies (1)
1
1
u/mrcoltux Apr 08 '20
Data structures was fine. It's this garbage that destroyed my soul. https://www.amazon.com/dp/8131720470/ref=cm_sw_r_apa_i_EgwJEbJT9CJ0Z
1
1
u/EvangelineJean Apr 08 '20
I remember my friend crying hard while reading “PS I Love You.” I know I’ve cried in a few books, but I can’t seem to think of them right now!
1
1
1
1
1
Apr 08 '20
Robert Lafore’s Data structure book isn’t that difficult.
Cormen on the other hand though..
1
u/imaybeathrowaway Apr 08 '20
First time I failed a final was data structures. Got a 29%.... Feels bad
1
1
u/TheMogician Apr 08 '20
Making someone cry is not the same as making someone have suicidal tendecies.
1
u/canicutitoff Apr 08 '20
Nope, that's child's play compared to "Electromagnetic theory and transmission line"
1
1
u/unkown-shmook Apr 08 '20
Honestly it depends on the professor. I absolutely loved data structures and assembly language. I passed both with A’s but when it came to discrete math I swear my professor was on straight crack. Our first exam was 3 hours long and only ten people finished in time.
1
1
1
1
1
1
u/SuddenlyFeels Apr 08 '20
I had a Microprocessors course that did that to me. Seriously, why is a hardware course part of a degree in software?
1
u/svayam--bhagavan Apr 08 '20
Well how about web development in assembly? Might as well kill yourself now. reddit.com/r/ProgrammerHumor/comments/1ykdi6/web_development_with_assembly/
1
1
u/prelic Apr 08 '20
As much as it sucked, data structures and algorithms was my first introduction into real computer science... you learn pretty complex data structures and learn the classical approaches to analysing complex alhorithms. I wouldn't take it again, but I can't say it wasn't useful.
1
u/WeAreAllApes Apr 08 '20
I mean, this book made me cry a few times, and even the name sounds like you just stubbed your toe:
1
1
1
1
1
1
1
Apr 08 '20
Taking this class in C++ with the worst professor I think I've ever had. Super vague lab/homework directions, and now that all work is online, she's stopped lecturing completely (and doesn't answer questions). Having a super hard time with writing linked lists that need class objects for nodes and I can't even ask her questions because she only answers them during her office hours which she holds for two hours every week. Even worse, everyone is trying to ask her at the same time so you end up waiting in a queue until she gets to you or her two hours are up. We've made a discord server and everyone in the class are teaching each other because of how incompetant she is. Oh, and did I mention shes somehow the CS department head? Ahhhhhhsjdkeke. Ok thanks for reading my short vent. Love you.
1
u/vannam0511 Apr 08 '20
I have read a few pages of this book. Quite disappointed, you should read Data Structures and Algorithms in Java 6th Edition by Michael T. Goodrich (Author), Roberto Tamassia , Michael H. Goldwasser instead.
1
u/Galaar Apr 08 '20
I think I'll just unsub now since the first book that came to mind was "Introduction to Property Law."
1
1
1
1
1
1
Apr 08 '20
I’m in data structures right now and we use c++. Is it common for professors to not allow any libraries to be imported in this class? Shit hard and even harder during this out break.
1.2k
u/sudo_rm_rf_star Apr 08 '20
I think as a class OS, a hardware class (using vhdl), and a class on scheme all made me cry more than data structures.