>tfw asked to implement a BST during interview
>tfw asked to implement a BST in an AST
>>60902561
dumb frogposter
>>60902561
if you've done that before or even just understood the concept at least once in your life it shouldn't be that hard...
What the hell is BST and AST
>>60902693
binary search tree and abstract syntax tree
weird bait thread you have here
Now thats actually not that hard. If smaller make left child else make right child.
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def bst(self, data):
if self.data == data:
return True
elif self.left is not None and self.data > data:
return self.left.bst(data)
elif self.right is not None and self.data < data:
return self.right.bst(data)
else
return False
how would BST in AST work?
>>60902825
i prefer the array representation. objects & recursion is probably the most concise but can become a mess of pointers and suffer from caching issues if sufficiently large desu
>>60902989
kint bst(int *bt, size_t len, int data)
{
size_t i = 0;
while (i < len && vec[i] != data) {
if (vec[i] < data)
i = 2*i + 1;
else
i = 2*i + 2;
}
return i < len;
}
>>60902989
Be real for one second anon. In real life you download library.
This is just shit test to see how big failure you are during interview. And if you can work under stress.
>>60903098
>Being a Library babby
>>60903127
Not googling problems and finding solved solutions implemented and tested to perfection before implementing it yourself.
It is almost like you want to waste time and money on purpouse.
Arent you that one guy who implements his own sql connectors and data parsers himself?
>>60903127
>insisting on reinveting the wheel and wasting time on problem someone already solved
>>60903098
In real life I'd check the language's standard library to see if it's builtin, yeah. these sorts of things are bullshit to test on given what coding is like in real life but it's a good filter, even if it mostly tests "did this guy go to school and do an algos class" it still keeps idiots out