mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update README.md
This commit is contained in:
parent
937183da0c
commit
690d8bd706
@ -2,13 +2,26 @@
|
||||
|
||||
<br>
|
||||
|
||||
### stacks
|
||||
|
||||
<br>
|
||||
|
||||
* last in, first out structures (LIFO)
|
||||
* useful in certain recursive algorithms, where you can push temp data as you recurse, and remove them from the (memory or data structure) stack as you backtrace.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
----
|
||||
|
||||
### queues
|
||||
|
||||
<br>
|
||||
|
||||
* queues can be implemented with two arrays or a dynamic array (linked list).
|
||||
* if implemented with a dynamic array, a more efficient solution is to use a circular queue (ring buffer), i.e. a fixed-size array and two pointers to indicate the starting and ending positions.
|
||||
* an advantage of circular queues is that we can use the spaces in front of the queue. in a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. but using the circular queue, we can use the space to store new values.
|
||||
* first in, first out structures (FIFO), i.e., items are removed at the same order they are added.
|
||||
* queues can be implemented with two arrays or a dynamic array (linked list), as long as items are added and removed from opposite sides.
|
||||
* if implemented with a dynamic array, a more efficient solution is to use a circular queue (ring buffer), i.e. a fixed-size array and two pointers to indicate the starting and ending positions. an advantage of circular queues is that we can use the spaces in front of the queue. in a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. but using the circular queue, we can use the space to store new values.
|
||||
* queues are often used in breath-first search (where you store a list of nodes to be processed) or when implementing a cache.
|
||||
|
||||
|
||||
<br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user