[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: EfXCE01UYAA8csO.jpg (41 KB, 798x644)
41 KB
41 KB JPG
you CAN invert a binary tree, right anon?
>>
>>107834883
yeah you just turn the computer upside down
>>
File: gH6EtYs.png (478 KB, 1075x1250)
478 KB
478 KB PNG
>>107834883
Problemo solvo
>>
>>107834883
I keep forgetting to water mine.
>>
>>107834883
I don't even know what it is
>>
>>107834883
grok does it for me
>>
what's a binary tree?
>>
>>107834883
invert(n): null if n is null else Node(invert(n.r), invert(n.l))
>>
I used to, but ever since I started working I never needed it once and now I don't remember it anymore
>>
>>107834883
/*
class Node:
def __init__(self, val=None, left=None, right=None):
self.val = val
self.left = left
self.right = right
*/

def invert(root):
if root == None: return

invert(root.left)
invert(root.right)
root.left, root.right = root.right, root.left

return root

if __name__ == "__main__":
root = Node()
invert(root)

Now give me my 200k/yr SWE job.
>>
>>107835605
Wrong.
>>
>>107834883
I can do whatever I want to a binary tree. I could invert it, balance it, traverse it, tie it in knots, or even leak or corrupt it. The computer is my bitch and it will do whatever I want without question.
>>
from binarytree import tree, invert

def invert(tree):
if tree:
return invert(tree)
return


How'd I do, anons?
>>
>>107836084
RecursionError: maximum recursion depth exceeded
>>
>>107836237
Goddamn, programming is hard
>>
>>107834883
Just flip the bits bro
>>
>>107835006
A miserable pile of branches.
>>
>>107834883
Just cast the type of the node to one that has the branches the other way round (recursively). Like that, you invert the tree at zero cost.
>>
I think I have solved it at least five times, but I can't remember off the top of my head.
I just don't use binary trees in actual code.
>>
What does invert even mean, invert all the values of the tree or reverse the order of the tree?
>>
>>107837763
It means you swap the left and right nodes all the way down.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.