>So user, why should I hire you? Can you even reverse a binary tree?
So user, why should I hire you? Can you even reverse a binary tree?
No
Naw bitch, now back dat ass up
Can you even change directories?
No, but I can make your stack overflow.
*takes off make America great again cap and runs hand threw hair*
Look bitch,
No but at least I can change directories
Why would I need to know how to reverse a binary tree to do design verification work?
You should hire me because I have experience at a world leading ASIC design corporation, have been exemplary in simplifying flow of my suites, and am quicker than most others in the field to pick up new tricks and to make use of old tricks to automate my processes and update ancient code.
I can also speak English fluently which is more than I can say for half of the people in this industry
What's a binary tree and what does it mean to reverse it?
I CANT PROGRAM. REEEEEEEEEEE
A tree where each node can have at most two children senpai
What if the tree doesn't identify as binary you shitlord???????
Why would you ever reverse a binary tree instead of changing the method you access it by?
>actually getting called in to an interview
I wish.
Im not white.
>cd..
>cd ~/..
> cd kode
>...
> you're hired
01001110 01101111 00101100 00100000 01101110 01101111 01110111 00100000 01100110 01110101 01100011 01101011 00100000 01101111 01100110 01100110
Braindead easy.
01011001 01101111 01110101 00100000 01100001 01110010 01100101 00100000 01110110 01100101 01110010 01111001 00100000 01101101 01110101 01100011 01101000 00100000 01100110 01100001 01100111 01100111 01101111 01110100 00101110 00100000 01001001 00100000 01110000 01101111 01101111 00100000 01101001 01101110 00100000 01110011 01110100 01110010 01100101 01100101 01110100
reverse(binaryTree)
Do I get the job?
Go home, Tyrone. You're drunk.
Yeah, I can. You just need to start at the root, and recursively swap the left and right branches.
This has O(n) efficiency for both time and space.
recursively swap left and right nodes as you traverse down the tree?
>how to trigger Jow Forums: the post
>no one in this thread can do the most common interview question
keep being ngmi Jow Forums
>reverse a binary tree
What's a binary tree?
I have never been asked anything about binary trees on interviews. I haven't even finnished college yet and still received several job offers as a developer
What's a real world use case of reversing a binary tree?
You do it to pass an interview.
Reverse a binary tree? What the fuck
What's a tree? What's a node? What are children?
I would attend her classes where she teaches me how to do that.
Reverse as in change from ascending to descending or as in swap left/right?
Damn so close bud if only you'd posted this 6 years ago this would've actually been funny
Underrated.
I think this is right
struct node
{
int val{};
node *left, *right;
};
void reverse(node *arg)
{
if (!arg) return;
node *temp = reverse(arg->left);
arg->left = reverse(arg->right);
arg->right = temp;
}
Doing this on my phone so i cant test it
>Why do I want to work for you? Would you even sit on my face?
>What's a tree?
Go outside you fat dungeon beckbeard.
>What's a node?
A server-side js platform.
>What are children?
Something you will never have you fucking virgin.
>cd
>cd
>cd binarytree
>pwd
>cd code
Do I get the job?
karli kloss a cute
I feel like something is missing here but I'm drunk and quite put my finger on it but yea you got the idea
what does she smells like Jow Forums ?
I must know what The Kloss smells like.
Cum of Kushner's.
>implying that soyboy has the testicles to produce cum
top
no but you can reverse that booty onto my binary TREE, from the way it looks i know dat ass got that branch prediction come here
You're right, she probably smells more like her bull.
Hired
Reverse(node)
{
if node is not canada
{
Swap left and right children
Reverse(node's left child)
Reverse (node's right child)
}
}
Reverse(root);
Yes, I can.
Your function is a void, yet you expect it to return a node*.
Also why the
int val{};
she should join our startup
honestly, I think this question is worded quite poorly.
A binary tree isn't ordered, so asking someone to reverse it doesn't really make sense.
I think something like "mirror a binary tree" or mentioning that inorder traversal should yield a reversed result would be better fitting.
I'm pretty sure that there's a decent amount of people who get stuck on that. At least I can't imagine so many people having issues with basic recursion.
Wtf are you talking about? This does not return anything but reverses the tree in place.
I can dig out an oake...
*temp = reverse(arg->left);
but reverse has no return value.
void func(int x){ ... }
int y = func(10);
I can't help but think reversing a binary tree is a pointless task but I haven't spent much time on it.
We are talking about swapping the nodes recursively right? Every left becomes a right and vice versa?
In that case we should just have traversal functions predicated on a bool that asks how you wanted the tree to look.
Next to free in execution and memory. Costs some in binary size.
If you put conditionals in your function, that fucks branch prediction. If you use two separate functions each for different order, that twice the amount of code and fucks cache.
Even ignoring "muh low level efficiency", unless you never want to interface with other software, it's quite likely you'll have to actually modify the tree if the order is relevant to you.
>Costs some in binary size
what did he mean by this?
>two separate functions for each different order
Obviously.
What kind of idiot would write it any other way?
>twice amount of code
>fucks the cache
Luckily traversal is not math code. It's rather slim.
But come to think of it there's tons of reasons the compiler might explode the call at (almost) every call site. Which is still probably not enough to be a major problem compared to an actual reversal but it's nowhere near as cheap as the structure that doesn't support a reversal.
Basically what user here mentioned. The code duplication (meta-generated or not) costs you icache and if you have binary size constraints (mainly relevant in embedded) that's a cost too. Of course as user brings up it does cost more in icache.
>interface with other software
Depends on what you mean. You normally don't expect binary compatibility between programs.
If we're talking about actually calling the original code (the code where we implemented this scheme for reversal) I don't see any issue.
See AVL trees or other self balancing trees
Just swap the definitions of left and right
No, but can you manually start an oilburner?
no u
Boring, u literally offer nothing of value
It'd be really helpful if you didn't just point me at a datastructure and instead pointed me to where reversal helps for this structure.
I don't know what he's talking about.
The only way I could see reversing being useful would be to just have one rotate method but that's just going to be less efficient.
AVL trees is a self balancing tree data structure.
The idea is to reverse small sections of the tree in order to keep the depth of the tree either even or uneven by a single depth.
Eg
z y
/ \ / \
y T4 Right Rotate (z) x z
/ \ - - - - - - - - -> / \ / \
x T3 T1 T2 T3 T4
/ \
T1 T2
If you can tell me where you need to reverse for that, I will be impressed.
This, but unironically. Just cast to a struct that has left and right reversed.
You need to complete the reverse homework assignment before you get the avl assignment in the first semester course of algorithms and data structures.
Reversing is the most basic form of tree manipulation.
I guess I wasn't all that specific. I can see how swapping nodes is important for trees. But I don't see how a full reversal (swapping every node) is meaningful.
Of course trees have subtrees though. So I guess it's valid to ask this.
eert yranib
cd ..
ls
klass anythingelse
cd anythingelse
ls
killself.sh
bash killself.sh
Is this a joke?
no.
I don't think it have any practical use but it is a simple thing to do and everyone with a programming education have learned about it, so it filters out a lot of people.
You might as well ask how to estimate the product of two numbers to a person who claims to have a mathematical education.
binaryTree = AB
BA
D-did I get the job, Kloss-chan?
Reversing a tree and traversing a tree in reverse direction is the same procedure except for the output. This question is literally just about knowing basic tree traversal.
If you need to pass a tree, there is absolutely no point in traversing the tree and generating an new one based on the return value.