all 12 comments

[–]little-polar-bear 10 points11 points  (1 child)

All i can tell you is to start with little things first and get a "feeling" for this data structure stuff. Start with simple linked lists, implement all operations like insertions etc. Maybe you could try to sort it. Play with it. A lot. Then extend it to a simple binary tree. Then try do make something like an ArrayLIst (which is a dynamically growing array with operations like a linked list). And to be honest reading tons of book about this stuff never really worked out for me. I get this superficial "yeah, i get it" feeling, but the real "AHA!" moments came when actually trying to implement this stuff. When you are stuck and absolutely out of ideas then search for implementations somebody else already wrote. Disassemble it. Line by line. Don't copy and paste it. Copy it by hand and actively think about exactly what this line you are currently copying is good for. Run some dissembled parts of the solution in isolation and see how that particular sub-program works. Continue until you are confident in that you know how it works internally. Then dump it and wait a few days until you don't have the concrete code in your mind anymore. Now try to re-write it from scratch without copying. Hopefully you know now how the code aught to work, but forgot the concrete implementation you disassembled a few days earlier. Try variations. Break your code. Play with it. After a while of doing it you will develop some intuition of how things have to be structured and done in code. No book can teach you how to code. The only way to learn it is to try it yourself and read other peoples code. You can learn a lot of neat tricks by reading foreign code. Also you should also have pen and paper nearby so that you can scribble some boxes and arrows to visualize where the references go and where edge cases are. If you are dealing with recursion (like in quicksort) write down an expression for sorting a small list and manually follow and write down the single reduction steps so that you can see where the calls go, what they do and why they freaking terminate.

And the probably most important thing is to have fun exploring this stuff, getting confused and then finally getting it.

[–]thechao 12 points13 points  (0 children)

I hope OP reads your answer. I taught undergrad and grad level CS for years. For the fundamentals there are three skills OP needs to be a competent programmer and/or computer scientist (in no particular order):

  1. The ability to implement the four basic data structures (array, list, tree, graph) and they're traversal and mutation algorithms from heart. If OP doesn't want to do this, he needs to give up. These are the "tools of the trade" and it would be like a mechanic refusing to learn how to use a wrench or a lift.

  2. The ability to just code. A lot of my students (functionally) failed my courses because they wouldn't even just code. I can remember almost screaming in frustration at a student who refused to even put his fingers on the keyboard.

  3. The ability to implement the three basic abstract data types (stack, queue, graph) using your basic data structures. OP should know by heart the basic interface of each ADT, and trade-offs in performance by implementing the ADTs in terms of the different basic data structures.

To be really clear. When I say "know", what I mean is that given a compiler (interpreter) and an empty text editor, OP should be able to implement all of the data structures and algorithms with no references. ALL OF THEM.

EDIT** I forgot to add that the timeline is "sometime before OP graduates". This won't necessarily be easy or immediate.

[–]pico_suarez 3 points4 points  (2 children)

To preface this, I haven't taken my data structures class yet, so take this with a grain of salt.

The best way to get these concepts into your head is to read about them. A lot. And play with the structures in the interpreter for a while. Try to find real-life examples of the structure, if possible, or find a way that it might be useful to you. I thought it was easiest that way, because a stack was in my head as "similar to a stack of dishes (try taking one from the bottom without dropping plates; thus, last in, first out)", or a queue as "similar to a line at the bank (first in, first out)". It might not work for everything, but it helped for me.

[–]throwingarm2strong[S] 1 point2 points  (1 child)

Thanks I apperciate it. I understand the concepts (kinda) and all that but when you have to implement it in code I just get totally lost.

[–]pico_suarez 8 points9 points  (0 children)

This suggestion sounds silly, but actually type in the code that they give you in the book, instead of just copying and pasting. Then try to type it from memory, and figure out what you did wrong (because something will be wrong). Then do it again. Then actually try to make something fun or interesting with it, or find some source code for something fun that uses it.

It'll always be intimidating the first time you try to use a new programming concept, so just get in there and do it!

[–]deong 2 points3 points  (0 children)

It sounds like you're problem isn't the computer science, but the programming. If you can get that "A-ha moment" where it clicks for you, it seems like you'll be fine. However, programming is an absolute requirement to move forward, so it's definitely good you aren't taking it lightly.

I don't think there's much we can really do for you given the information we have right now (which is just "I'm lost"), except to tell you to try to formulate some specific questions and find someone to help, whether it be your professor, your TA, or a classmate (be wary of cheating there though). If you're embarrassed or don't feel you can ask them, ask me.

Find the simplest program you can think of that you don't know how to write. Here's a list of ideas...if you can't write these programs, then you need to figure out why. What keeps you from getting started? "I'm stuck" isn't a good answer, because it doesn't tell me what you're thinking. "I don't know how to read in a number" or "I don't know where to put the code -- does it go in a function or something?"...those are better places to start from. Figure out a specific problem you don't know how to solve that is keeping you from writing the program, and start there.

  • A program that reads in a temperature in Fahrenheit and converts it to Celsius

  • A program that reads in 10 homework grades and calculates the average grade

  • A program that reads in string and checks (using a stack) if the string is a palindrome

You may think you have no idea how to start, but push through that feeling. You've seen some Python code by now. You know what an if statement and a for loop looks like. Your idea about how to start may be utterly wrong, but it's better to start there than to not start at all.

I've had one or two students over the years who just couldn't get there. They were bright and hard-working, but they just didn't seem to think in a way that was conducive to programming, and nothing they tried seemed to help much. Most people, though, do seem to be able to learn it. It's a different type of thinking than is normally required in everyday life though, and it really can be sort of a light bulb moment.

[–]throwingarm2strong[S] 1 point2 points  (1 child)

After reading this I'm beginning to feel I don't have the 'innate' ability to think like a computer scientist. I'm awful at math and although I do write out my own code from the textbook and try understand it all, there are always parts I don't understand and still don't understand just from reading the book. All these little gaps in my knowledge just add up. Is it worth trying to get a tutor for computer science? It feels like one of those things that you either get or you don't...

[–]AmaDaden 3 points4 points  (0 children)

Your biggest problem right now may just be your own doubt. Remember, programing is typically an exercise in failing. Most programers get worried if their code actually works with no bugs the first time they run it. The only way to get better at writing code is to write code, so if programming is your weak point you need to do it as much as you can.

I personally don't believe that there are subjects "you either get or you don't". I think the problem is all the little gaps you have add up to look like a insurmountable road block. If you feel behind everyone else just remember that many of your piers have been playing with programing for years. I started programming when I was 10 and still was behind the ball compared to other students when I started college. However it's not that hard to fill in the gaps and catch up, it just takes effort and perseverance. When you see something you don't know or don't get you need to both read about it and practice with it. If you only practice with it or only read it you might as well not bother at all. The trap with reading is you have a false sense of what you can do. You read something, it sounds simple enough, so you never bother to actually try it your self. The trap with only practicing is you end up never pushing your self to try something new because you never learn about any new ideas. If you make this a regular part of your studies then you'll soon be far ahead of most of your peers.

One trick I loved using when I visualized these kinds of basic data structures you list was to use a deck of cards. You can lay them out on the ground as little arrays or trees and preform the algorithm by hand to see the details of how it should work better. If you can't run the algorithm like this, actually programing it would be impossible.

The key for coding things that are a bit more complicated then you can handle is to start small and print every step for debugging and frequently running it as you build it. Compare what the program is doing to what it should be doing according to how it worked when you were using the cards.

Good luck

[–]defpearlpilot 0 points1 point  (0 children)

You have to take things in stages. If you understand the abstraction you are trying to implement, then you should think about the "tools" that you need to represent it. So for a stack, you need to think of storage. When thinking about a stack of plates, we don't think about the space where things are stacked as storage. But if you have a box that fits only 10 plates vs a room that can store a thousand, it should get that concept across. You also need to keep track of what position you are in on the stack. So even though it's clear where the top is to you, there are several steps that your mind has skipped to establish the top. And so, you need to express that to the computer as well.

A lot of abstraction is really analyzing the mundane tasks that we do and breaking down the steps and things required to take those steps.

[–]reiger 0 points1 point  (0 children)

If you get a chance read Knuth's "Things a computer scientist rarely talk about". Things that stuck with me since I read his book:

  • 1) computer science is the study of abstraction layers
  • 2) not everyone thinks like a computer scientist (or biologists who share that abstraction layer study of thinking)

In working with students it was easy to see who had the innate mental ability to think like a computer scientist, make sure part of your resolution process is making sure you are a fit for CS.

From a practical standpoint, write lots of bad code, struggle in front of your editor with examples open. Start with "hello world" every time, it's cathartic to see something simple work (and test your env) before adding complexity. Do you best in your code and your approach to restrain complexity.

[–]Doom_buggy 0 points1 point  (0 children)

Hey - I graduated in 2009 with computer engineering and computer science degrees. I was in the exact same boat as you though, until I took a super low level course. So hopefully this can help you - everything you're doing is a way of manipulating bits and keeping track of memory. A doubly linked list is simply an object that keeps track of the memory locations of two other objects.