In the 'put' function, inside 'if(currentNode != null)' there should be a 'return' in the end of this block. This is because we don't need to create new node if the node with that key is already present. (or, put the remainig lines in that function in 'else' block). The code gist on GitHub is updated
@akhilsrivastava1492 жыл бұрын
Very good explanation. Please load more videos.
@ee_32_farzanreza102 жыл бұрын
Very good explanation
@abhinavsinghvirsen3 жыл бұрын
awesome explanation Keep doing
@gouravkumar74593 жыл бұрын
Thanks for the explaination! i think in put function ,in block where currentNode !=null there should be return also.
@BhriguSrivastava3 жыл бұрын
Yes Gourav, that is correct. Seems like I missed (actually I was supposed to put the remaining lines in that function in the 'else' block, but missed it). I've updated in the code gist in GitHub.
@gamopim2 жыл бұрын
hi! the UseCache code is available somewhere? thanks for the tips!
@dewendrapandey11452 жыл бұрын
when it refers 4 again order must change, so as for 2 if you don't change order, how will you decide which need to delete for new entry?
@rozersmith2 жыл бұрын
Hey brother , there is a fundamental problem you have missed in the LRU . lets say we have 2->4 ->7 and again there is 4 which is requested we need to adjust the linked list again to 4->2->7 coz 4 is now recently used and the order should be retained lets say again 7 is hit , now the order will become 7->4>2 if you carefully observer now the least recently used is actually 2 - please fix this
@BhriguSrivastava2 жыл бұрын
Hi, yes you are correct but the diagram shown in the video at 2:50 doesn't show the items in order. It's just random. When we're inserting 9 at 3:28, we're removing 4 from the memory because 4 is not recently used (but in the diagram it's present in the middle of list). It's handled in code, but while explaining LRU, I was not explaining how it'll be ordered internally if we use a list, but just showing all the items randomly.
@ankitgupta-ph4nk2 жыл бұрын
Just one question in my mind.. If we are adding a new element and capacity is available, then why we are adding it at the beginning??
@akdesai8322 жыл бұрын
To make it recently used. Adding new one or accessing the existing key makes the key recently used and hence renew its expiry.