Answering: 'Why does Recursion suck for DSA?'

preview_player
Показать описание
FAANG Coding Interviews / Data Structures and Algorithms / Leetcode
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Depending in implementation details, tail recursion could be as efficient as iteration for just about any example.

RS-fzps
Автор

Wow, feeling a bit lost here! Hopefully, a year from now I'll stumble upon this video again and finally grasp what it's all about. hehe

viniciusv
Автор

It's often better to construct a new data structure than mutate an existing one. The safety & simplicity of immutable data is often worth a small hit on performance. Some programming languages that emphasize immutable data are also ones that make recursion (often with tail-call elimination) easy to use. Clear code & immutable data!

jonathanjohnston
Автор

Regular linked list can't be reversed in o(1) complexity only doubly linked list or i miss something in your explanation...?

alonson
Автор

Why is it not recommended in C/C++ ???

muhammadmutahir
Автор

I've never made a Linked List that wasn't Double Linked. And the Root ALWAYS pointed to the 1st, last and a current pointer.
Problem a non issue.

Basically my Root & every Node are identical.

NODE / ROOT
id / id
Prev / first
Next / last
Parent / curr
Data / ? (forgot how used this)
Size / Count

(Data/size are mem alloc.)

LG-qzom
Автор

Yeah I do NOT do iterations. Even for graph problems I want iteration so I can visualize what’s going on.

sumanthmurthy
Автор

just spent 4 hours trying to reverse a doubly linked list and this pops up smh

dubzy
Автор

not correct, when you change next pointer of 2 from 3 to 1, you loose the rest of the chain. you have to start from the reverse and iterate to the beginning.

einfacherkerl
Автор

The best way to do it is to know that no-one uses linked lists in production code. Use a deque and you're done.

davidgillies
Автор

You actually can do it, can't you? This video is good, PLEASE ensure that your other videos too maintain this quality and try to show example of what you're doing rather than just saying it.

professornumbskull
Автор

I wish we had unlimited space and time so that I can use as many loops as i can 😂

somename
Автор

conceptually, i think the following works. i have not had time to test it. feel free people to tell me if it fails. (spacing got weird when i posted it)

// returns the head of the reversed linked list
//
node* reverseLL( node *ll )
{
node *cur, *nxt, *nxtnxt;

cur = nxtnxt = ll;
if( cur )
nxtnxt = cur->next;

while( nxtnxt )
{
nxt = nxtnxt;
nxtnxt = nxt->next;
nxt->next = cur;
cur = nxt;
}

if( ll ) ll->next = nullptr;

return cur;
}

mazthespaz
Автор

tail call optimization decorators >>>>

Sarwaan
Автор

Damn why is C++ not recommended for recursion 😭

alansun
Автор

I'm c ++ programmer, Initially it was very difficult for me to understand recursion, now I mainly look at every recursion call as a separate function call, which returns a value to itself every time.

lolgaming-bqvs
Автор

Bro looks so much like Justin Gaethje😂

androidgamingtutorials
Автор

Super triggered C# isn't on you list of commonly used languages. Haskell? Really?

lizard
Автор

why is it O(1)? You clearly went through each node to reverse the pointer and thus shouldn't it be O(n)? Edit: Oh, I get it now. Its O(1) space. lol. Good point!!

mmm-iews