BinaryByter
wikipedia
MᏫᎻᎯᎷᎷᎬᎠ
anyone know?
Just scroll to it until you get a match
Mihail
wikipedia
I heard that one is especially good
Unknown
Just scroll to it until you get a match
no its not the way how do I know what is the element in the middle, sorry I my question is different, it says that how do I get to the middle element of linked list and not searching an element.
Ariana
^
MᏫᎻᎯᎷᎷᎬᎠ
no its not the way how do I know what is the element in the middle, sorry I my question is different, it says that how do I get to the middle element of linked list and not searching an element.
Hit a counter with 0 and a temp Node that runs through the elements while increasing counter with(++) until it gets to the last element So counter is the size right now Now do this counter /=2 and bomm
BinaryByter
please
BinaryByter
no more /2
MᏫᎻᎯᎷᎷᎬᎠ
s/counter \/=2/counter = counter » 2
I don't speak the language of demons sorry
BinaryByter
you speak the language of "I want my code to be slower than it could be"
MᏫᎻᎯᎷᎷᎬᎠ
It's linked list remember?!
MᏫᎻᎯᎷᎷᎬᎠ
O(N)
BinaryByter
kek
BinaryByter
why is everybody i'm telling not to bloat their code referring to O notation?
BinaryByter
/2
kek'd
Unknown
Unknown
I realized that method 2 is better
BinaryByter
UGHHH
Unknown
no
why? We traverse the linked list 2 times in the first case and only one time in the second case
BinaryByter
You should keep track of how many elements the list has somewhere else
Mat
no
Yes, if you can't know how many elements you have in it
BinaryByter
but this is not required in method 2
method 2 is still slower than just scanning with one pointer
BinaryByter
Ariana
tbh linked lists usually worse in terms of memory consumption than arrays
Unknown
I am unable to understand
Mat
you should design your linked list to
Usually that's an interview question
Mat
And a linked list doesn't have that counter by default
BinaryByter
But please tell me the reason
because its more operations
Ariana
vanilla linked list is jus a pointer to next element
Ariana
So its O(n)
Ariana
its crappy
BinaryByter
yes
BinaryByter
but it has quick insertion
BinaryByter
which might be what you want
BinaryByter
And a linked list doesn't have that counter by default
you must live in the past century where C was the only option then
BinaryByter
any good implementation should feature the counter
Unknown
BinaryByter
kek
Unknown
according to me it has less or more or less same no. of operations
Parra
do may mean memory fragmentation maybe?
Ariana
Like space used
Unknown
no
I am really confused that if I am in an interview how will I explain
BinaryByter
Like space used
space complexity is your word
Parra
Like space used
not really then
Parra
this is extremely tricky haha
Parra
i didn't thought about that before
BinaryByter
i didn't thought about that before
because its kinda useless when you keep track of the amount of elements
BinaryByter
its just one pointer operation more
BinaryByter
two, in fact
BinaryByter
per cycle
Parra
findMiddle can seg fault, no?
BinaryByter
why would it?
BinaryByter
unless you badly fill your pointers
Parra
no, it won't
Parra
you are right
Parra
comic Sans is fun
Parra
😄
BinaryByter
xD
BinaryByter
this isnt comic sans
BinaryByter
its even worse
olli
https://youtu.be/YQs6IC-vgmo
BinaryByter
That divides by four
whoops shift by one i meant xD
BinaryByter
in general
Mihail
whoops shift by one i meant xD
Still do you think it'd be faster?
olli
Still do you think it'd be faster?
the compiler will optimize it anyway..