LRU Cache - Explanation, Java Implementation and Demo

  Рет қаралды 17,263

Bhrigu Srivastava

Bhrigu Srivastava

Күн бұрын

Пікірлер: 18
@BhriguSrivastava
@BhriguSrivastava 3 жыл бұрын
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
@akhilsrivastava149
@akhilsrivastava149 2 жыл бұрын
Very good explanation. Please load more videos.
@ee_32_farzanreza10
@ee_32_farzanreza10 2 жыл бұрын
Very good explanation
@abhinavsinghvirsen
@abhinavsinghvirsen 3 жыл бұрын
awesome explanation Keep doing
@gouravkumar7459
@gouravkumar7459 3 жыл бұрын
Thanks for the explaination! i think in put function ,in block where currentNode !=null there should be return also.
@BhriguSrivastava
@BhriguSrivastava 3 жыл бұрын
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.
@gamopim
@gamopim 2 жыл бұрын
hi! the UseCache code is available somewhere? thanks for the tips!
@dewendrapandey1145
@dewendrapandey1145 2 жыл бұрын
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?
@rozersmith
@rozersmith 2 жыл бұрын
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
@BhriguSrivastava
@BhriguSrivastava 2 жыл бұрын
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-ph4nk
@ankitgupta-ph4nk 2 жыл бұрын
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??
@akdesai832
@akdesai832 2 жыл бұрын
To make it recently used. Adding new one or accessing the existing key makes the key recently used and hence renew its expiry.
@akshitjain2906
@akshitjain2906 4 ай бұрын
legend
@unknown-lv8io
@unknown-lv8io 8 ай бұрын
sound is very low
@eshantkumargola
@eshantkumargola 6 ай бұрын
Volume in this video is very feeble.
@howardchang7999
@howardchang7999 2 жыл бұрын
i m a noob
L18. Implement LRU Cache
24:56
take U forward
Рет қаралды 46 М.
LeetCode 146. LRU Cache (Algorithm Explained)
18:00
Nick White
Рет қаралды 118 М.
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 56 МЛН
LRU Cache - 146. LeetCode - Java
12:52
Teddy Smith
Рет қаралды 410
Cache Systems Every Developer Should Know
5:48
ByteByteGo
Рет қаралды 495 М.
LRU Cache - Twitch Interview Question - Leetcode 146
17:49
NeetCode
Рет қаралды 278 М.
How to Implement an LRU Cache (Leetcode #146 explained)
10:32
Byte by Byte
Рет қаралды 35 М.
Huffman Coding -  Python Implementation and Demo
34:34
Bhrigu Srivastava
Рет қаралды 36 М.
8 Design Patterns | Prime Reacts
22:10
ThePrimeTime
Рет қаралды 418 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 833 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 657 М.