How do I get better at programming? I'm struggling in my data structures class right now

How do I get better at programming? I'm struggling in my data structures class right now.

Other urls found in this thread:

geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/
twitter.com/NSFWRedditGif

Write more code.

If you're struggling with data structures try implementing the structures themselves in your OOP language of choice this should give you a greater understanding of the concepts.

Academia doesn't make you write code so you have to do it yourself.

read the texts really slow so you can properly process it, dont read technical literature like a novel. In addition, check out vids on youtube like tushar roy (good pajeet), mit, or other universities.

And sleep well for God's sake.

Shoot any questions you have, be specific.

I understand the concepts, I just finished doing tree traversal, the problem is I don't have any idea on how I'd translate this into code. There seems to be a massive mental block between what a question asks, and how I'm supposed to implement it.

[code]
//class definition of a tree
class Tree {

data myData; //payload
Tree leftChild; //this one will be visited first in depth first recursion
Tree rightChild; //child 2

//constructor
Tree(data){ myData = data; }

}

// --------------------------------------------//

// traverse the tree in depth first mode, so always try to take the left child as next node

void DepthFirst(Tree node){
//do something with this node's data
var x = node.myData;

//visit the children recursively
if(node.leftChild != null) DepthFirst(node.leftChild);
if(node.rightChild != null) DepthFirst(node.rightChild);

}

// --------------------------------------------//
[/code]

how to create a tree with an int as its payload:
var t = new Tree(1);
t.leftChild = new Tree (2);
t.rightChild = new Tree (3);

when calling Depthfirst(t). The x values will be assigned as 1, 2, and then 3.

Its really simple and intuitive once you get it.

In that case google (and in some cases your textbook) are your friend. I'd recommend struggling with how to implement the structures for a good 30min to an hour then looking up the solution. Sometimes struggling with a problem is the best thing for learning even if you don't solve it.

As for tree traversals they can be handled pretty simply with recursion. Here's a pretty good resource

geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/

>OOP
OOP obfuscates data structures and algorithms.
Best to learn it in something like ML or even Lisp before attempting it in OO.

Functional languages are great but most universities don't teach them first.

The typical path is programming 1 (python/c++/java) -> OOP -> data structures. Guy is learning data structures I don't want to tell him "but before that you must first use functional languages and learn lambda calculus"

Pro tip: by using higher level languages you'll never become a good programmer.
Everything is already implemented for you, you just plug&play. If you want to write exquisite code, you have to go low level, C/C++/assembly doesn't matter which.

Implementing data structures by yourself, algorithm, see if you can optimize what you've written.
You'll soon see that all those ifs are the fuel of satan. True programmers needs the bare minimum amount of comparisons in order to do the job, code monkeys just spams condition-statements everywhere because it's easier.

Solving competitive programming problems made me excellent at implementing algorithms and data structures

I don't understand the point of:
>var x = node.myData;

there is no real point to it, It was just an example of what to do with the payload of the node. In that example, I just assigned myData to x, thats all. I also could've printed x to the console or something.

However, your focus should lie in the structure of things. Look at how the child nodes are recursively invoked by the function

>i'm excellent at doing useless things
wow

I think it's best to not see how the sausage is made until you get into compiler design, lest your mind be wracked with the horror of knowing the unknowable and you gibber endlessly about optimization

youll never become a good programmer if you work at the assembler level. everything is already implemented for you.

well, I have the same feeling and I knew it would be this way. nonetheless, it could help OP.

Generally beginners code can be quite reduced due to many redundancies. I didn't mean very low level stuff like CPU-wise microoptimization, something like "you took 5 if-else to do this, there was a better way?"

I got that, I'm just unsure of whether you're starting from the parent node (preorder), or the child node for postorder.

The calculator is able to do additions for you, does that mean you shouldn't learn how to do them?
Java and other way-to-high level programming languages keeps you too much in a bubble, for example the idea that dynamic memory is something like infinite&quick.

see

As someone who has used and knows Assemblr and COBOL, I only slightly agree. Basic assembly code will help you work through the process of writing code, but it's ultimately a worthless skill when it comes to working in the industry. You're better off becoming skilled at high level languages on IDEs that people actually use.

My physics curriculum says that i will program next semester (physics). I'm anxious now, i never programmed. What to expect?

Procedural programming is basically sequential logic, so if you are good at logic I would not be worried

Look at the data structure implemented in a real world application, github is very useful. Seeing it put in practice is worth hours of banging your head against the wall reading a book

mmmmmmmmmmmush shetlabin

If you've never done it before, I'd imagine it'll be python or C, depending on what the module is. Almost certainly python.
Unless its something very specialist, like you're in Astro or something, then, speaking from experience it'll be R and/or IDL, probably along with python
You'll probably be fine, with the exception of IDL there's a trove of tutorials and documentation you can get started with online, and IDL is pretty widespread in astro, meterology etc so there's probably be someone who can give you a hand

I've read here the only way to really learn math is to do it. It's easy to read the book and think you absorbed the concepts when in reality you don't know shit. Same applies to programming. Even little things that seem like they'd be easy like moving around nodes in a linked list actually require some thought at first. Once you iron out all the little nuisances of programming you can deal with the big picture in which case if you actually are smart you'll be 10x better than everyone else.

it's actually the opposite you want to learn the high level stuff first because otherwise you will lose interest because C/C++ takes forever to learn (and has low productivity) when you don't have the fundamentals of computation down.

TL;DR it's only a good idea to start with the low level languages if you are learning them from a university or have a year to spare with no productivity.

Intro to Programming 101 and Data Structure and Basic Algorithms 102 are the two hardest classes for non-programmers. Everything past that is easy. You just got to get used to using programming constructs to make nontrivial things. Practice coding up every algorithm and data structure you learn and practice translating ideas into working code.

Remember, they computer is retarded as fuck. You have to hold its hand at every little step and explicitly say everything single thing must be done. Just keep breaking down the steps into they couldn't get any simpler and code it up.

>How do I get better at ______
same as all the other shit. Stop being a lazy cunt

Fuck off /g/
>java
Fuck off /g/
>and learn lambda calculus
You don't need to learn lambda calculus to use functional programming. All they need to know is that they are on the fly functions that can capture data.
>you have to go low level, C/C++
C and C++ are not low level. They just give a high level of control. Fuck off to /g/ and stay there.
>see if you can optimize what you've written
Not without a profiler. The only global pre-optimization you should do is the overall design consideration.
>You'll soon see that all those ifs are the fuel of satan
No, malloc's and cache misses are far worst.

We are Learning Matlab>OOP>Databases and shit
1. year Comp sci student, not OP.

...

I never understood why mainstream object systems never used principles from abstract algebra.

Identify the issue. Is it foundational? Is it task-dependent? Is it language-dependent? For getting better at programming in general, you can't go wrong with reaffirming or delving into the underlying principles/mathematics/compsci, and just write a lot of code. The former irons out bad habits and ignorance, the latter actually makes you good at the practice of programming.

Like you can write code for all simpler algorithms, just tree is too complex?

See cpp.sh/3i6sn for run-able c++ code doing bfs and dfs on the example tree in the image.

Now make it run on a 2d array and not predefined tree structure

>Now make it run on a 2d array

That's a disgusting representation and you can easily write a constructor to parse it into Tree.

Your indentation made me puke.

>my indentation

Tree tree
░{'a',
░░{
░░░{'b',
░░░░{
░░░░░{'d',
░░░░░░{
░░░░░░░{'1'},
░░░░░░░{'2'},
░░░░░░░{'3',
░░░░░░░░{
░░░░░░░░░{'5'},
░░░░░░░░░{'d'}
░░░░░░░░}
░░░░░░░},
░░░░░░░{'4'}
░░░░░░}
░░░░░}
░░░░}
░░░},
░░░{ 'c',
░░░░{
░░░░░{'3',
░░░░░░{
░░░░░░░{'f'}
░░░░░░}
░░░░░},
░░░░░{'9',
░░░░░░{
░░░░░░░{'j'},
░░░░░░░{'k',
░░░░░░░░{
░░░░░░░░░{'m'}
░░░░░░░░}
░░░░░░░}
░░░░░░}
░░░░░},
░░░░░{'g'}
░░░░}
░░░}
░░}
░};

Better?

because its academic bullshit useless in real world, if it had useful properties everyone in the world would already use it

the opposite is true
dealing with low level stuff is for brainlets, as they have to think more technically and less about abstractions and how to solve things

>There seems to be a massive mental block between what a question asks, and how I'm supposed to implement it.

it's not "mental block", you just cant program for shit and just know theory, thats how universities work

>way-to-high
into the trash it goes, what a brainlet

It's not scary at all. Start learning how to programming in C++ now and read a book.

this is probably true, I'm gonna need to hammer this shit out hard, yet I have virtually zero interest in it.

Do you even believe what you're saying? Or are you just fucking baiting

Get your ass and hands into writing code. Coding is made by practice not pure theory

>yet I have virtually zero interest in it.

Then why are you learning it?