[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 26 KB, 385x343, tree1.jpg [View same] [iqdb] [saucenao] [google]
4396671 No.4396671 [Reply] [Original]

Hey there /sci/.

I'm in need of help. I was taking a class on algorithms and data stractures (practically c language) but the professors were shit and I was to lazy to study on my own, so I decided to ditch the class. Tomorrow however is the final exam and there may be a chance of me getting a C if I play my cards right. The professor always has a question about binary trees. He always gives us a binary tree and asks for the tree traversal in all the 3 different methods.(preorder, inorder and postorder).I looked for a tutorial online but couldn't find anything simple. Can anyone give me a few tips on what the fuck are those things?

tl;dr:
>Got a test in C tomorrow
>Have no idea what a binary tree is
>Need to learn tree traversal (preorder,inorder,postorder)
>Keep it simple

>> No.4396673
File: 132 KB, 500x333, dawkinslaugh2.jpg [View same] [iqdb] [saucenao] [google]
4396673

>get a C on a test on C

>> No.4396675

>>4396673
Oh look, a religion troll.

Nevermind, go on. It's a shitty homework thread anyway.

>> No.4396681

>>4396678
The joke is that he derails the thread by inciting a religious debate with his picture.

(No, the C pun wasn't funny.)

>> No.4396678

>>4396675
lol dumbass didn't get the joke.

>> No.4396683

>>4396671
If you study real hard till tomorrow, you might even get a C++.

>> No.4396686

>>4396681
I wish everyone on /sci/ jumped to conclusions as well as you.

>> No.4396687

>>4396683
Op here, this is actually funny. And that just proves we don't have a sense of humor

>> No.4396690
File: 25 KB, 351x250, office_space.jpg [View same] [iqdb] [saucenao] [google]
4396690

>>4396686
So do I!

>> No.4396688

>>4396681
Are you stupid or something?

>> No.4396691

>>4396686
How is there any "jumping to conclusions"?
He posted a religious picture on a board that discusses religion troll threads in thousands and thousands of butthurt posts.

Why do I even care about his trolling garbage?

saged and hidden

>> No.4396697

>>4396691
Go away. You derailed the thread by opening YOUR mouth.

>> No.4396699

>>4396697
I was not the one derailing the thread. Blame the religion troll.

>> No.4396705
File: 22 KB, 435x196, 1320871775732.jpg [View same] [iqdb] [saucenao] [google]
4396705

>>4396671
http://www.cse.hut.fi/en/research/SVG/TRAKLA2/exercises/BST_TraversePre.html
http://www.cse.hut.fi/en/research/SVG/TRAKLA2/exercises/BST_TraverseIn.html
http://www.cse.hut.fi/en/research/SVG/TRAKLA2/exercises/BST_TraversePost.html
http://www.cse.hut.fi/en/research/SVG/TRAKLA2/exercises/BST_TraverseLevel.html
you're welcome

>> No.4396713

>>4396699
>post picture of biologist
>aspie freaks out about religion

>> No.4396716

>>4396713
>implying biologist
>implying he isn't known solely for being a religion hater

>> No.4396720

>>4396716
Why does that bother you so much?

>> No.4396723

>>4396720
The rules say "no religion vs science threads".
It annoys me to say someone constantly breaking the rules.

>> No.4396725

>>4396723
*see

>> No.4396733

>>4396723
>implying you just didn't verify >>4396713's scenario

>> No.4396737

>>4396733
No, I didn't. I don't care about biologists. I just can't stand religion trolls.

>> No.4396736

>>4396705
That's it? Just some pieces of code? You're awesome dude! Thanks! I was thinking I'd have to calculate shit and stuff

>> No.4396739

>>4396691
To clarify:

This is the conclusion you jumped to:
>>4396713

sage because this thread is completely derailed. Sorry, op. This time you weren't even the biggest faggot in the thread.

>> No.4396741

>>4396739
This wasn't even my post.

>> No.4396747
File: 126 KB, 1100x914, 1318927643463.jpg [View same] [iqdb] [saucenao] [google]
4396747

>>4396736
This is actualy a pseudocode not proper code but to learn how these procedures work it should suffice.

>> No.4396749

>>4396737
This guy's fucking retarded. To further clarify: it seems pretty obvious that the guy who posted a picture of dawkins laughing because he made a joke, not because he's trying to derail the thread into a shitfest, as it has become.

>> No.4396753

>>4396749
I assume the poster knows about /sci/''s reaction to religious pictures.
In conclusion he posted it for the sole purpose of derailing the thread.

>> No.4396756
File: 16 KB, 321x472, file[1].jpg [View same] [iqdb] [saucenao] [google]
4396756

HAI GUISE! LOOK AT ME HOW I'M TOTALLY INCITING A RACISCM THREAD NOW WITH MY TOTALLY RACIST PICTURE.

>> No.4396758

Honestly OP, ditching a course on data structures is ok only if you work on them on your own. I don't mean it will make you fail the exam, I mean you're missing on something not only interesting, but also extremely important. You can't imagine how many pieces of codes in big apps could be made much faster or take much less memory using proper data structures. Sometimes it's because the software wasn't supposed to be used on big scales and the coder got lazy, but sometimes it's because someone never gave a crap about studying data structures, and that's a shame.

>> No.4396760

>>4396753
Let's evaluate the situation scientifically. Count the number of times someone replied to the dawkinsguy saying something about religion or atheism. Then count the number of times someone jumped to the conclusion that he was attempting to derail the thread with a religion/atheism debate.

how hard am I being trolled right now?

>> No.4396763

>>4396756
If the guy in your picture was known for his public propagation of racism, the picture would have the same effect as >>4396673

>>4396760
He trolled us, indeed. That was his intention and he was successful. Embarrassing.

>> No.4396768
File: 29 KB, 452x315, pzmyers.jpg [View same] [iqdb] [saucenao] [google]
4396768

OOGA BOOGA!

>> No.4396772
File: 35 KB, 581x387, 8_jan_Remember_McCain.gif [View same] [iqdb] [saucenao] [google]
4396772

>>4396763

>> No.4396801

>>4396758

op here: I can't tell you that I know what you mean, cause I seriously have no idea... But I understand the feeling of learning something interesting and useful. I had an awesome teacher in my java class and I really enjoyed it. But the guy that taught data structures was just insufferable. He had a lisp problem and couldn't pronounce the s (which wouldn't mean much if he made any sense) but he would also be completely incoherent in general. His sentences made no sense and he jumped from one topic to the next, explaining nothing and leaving no time for questions from the students. He just said whatever he had prepared for each class, way too fast, showing us blocks of code on a board, but not bothering to explain what the code was for. He just recited each line and gave a few comments like : "printf prints things on the screen. Malloc allocates memory". To top everything off, since I'm not from/in an english speaking country the guy had translated everything in our language. I had to find out the exam question was about binary trees by trying out what "trees in C" are on google. Well that doesn't seem so tragic, but imagine having to translate traversals....

>> No.4396835

>>4396801
Yeah, I had translators in my teachers too, and that sucked. But really, whether you end up doing fine with your exam or not, try to find online resources to study data structures a little bit. You don't need to know as much as if you were taking an exam, but makes sure you at least have an idea about what exists, so that you can look it up again when you need it. Knowing how the routines for adding keys, removing keys etc work, that is useless, because you won't be implementing the structure by yourself. But if you want to use a library, you'd better know which structure does the job for your problem, and you can't know that if you don't know how to compare data structures in terms of efficiency for a given problem.

>> No.4396940

A binary tree is a type of data structure consisting of a root node, that contains references to the root nodes of one, two, or zero other binary trees (its recursively defined) one being called the left child, and the other the right child. I'm not going to get more specific without more specific questions.

The three types of binary tree traversal you most likely studied are In-order, pre-order, and post-order.

In-order traversal is the easiest, you recursively visit the left sub-tree, then the root, then the right sub-tree. Basically, pass over the tree from left to right, ignoring the height of each node. So the example tree you posted, you would visit: 9, 5, 1, 7 , 2, 12, 8, 4, 3, 11.

With pre-order traversal, you first visit the root, then recursively visit the left sub-tree, then the right. So: 8, 5, 9, 7, 1, 12, 2, 4, 11, 3

With post order traversal, you recursively visit the left sub-tree, then the right, then the root. So: 9, 1, 2, 12, 7, 5, 3, 11, 4, 8

Keep in mind, its entirely possible I've made a small mistake somewhere with the examples.

Its a shame you had such a shit sounding professor for data structures though, its one of the more interesting topics you get to study early on in computer science.

>> No.4396967

OP, just remember the three main actions:

1) Print
2) Go to the left
3) Go to the right

So for preorder, it goes PLR (print, left, right). For inorder it's (left, print, right) and for postorder it's (left, right, print).

So using the OP picture as an example, a preorder traversal would go as follows:

At node 8
Print
Go left
At node 5
Print
Go left
At node 9
Print
Back to parent
Go right
At node 7
Print

etc.