Add some datastructures

This commit is contained in:
Tyler Perkins 2021-09-22 23:33:54 -04:00
parent 98165579d1
commit de36139245
7 changed files with 114 additions and 0 deletions

View File

@ -9,12 +9,26 @@ Different ways to store and operate on data, with differing efficiency
* [[linked_list|Linked List]] * [[linked_list|Linked List]]
* [[stack|Stack]] * [[stack|Stack]]
* [[queue|Queue]] * [[queue|Queue]]
* [[skip_list|Skip list]]
* [[hash_table|Hash Table]]
== Non sequential Data Structures == == Non sequential Data Structures ==
* [[binary_tree|Binary Tree]] * [[binary_tree|Binary Tree]]
* [[graph|Graph]] * [[graph|Graph]]
* [[b_tree|B-Tree]]
* [[red_black_tree|Red Black Tree]]
* [[splay_tree|Splay Tree]]
* [[avl_tree|AVL Tree]]
* [[kd_tree|KD Tree]]
== Sorting ==
* [[quicksort|Quicksort]]
* [[mergesort|Mergesort]]
* [[heapsort|Heapsort]]
* [[radix|Radix]]
* [[bucket|Bucket]]
* [[counting|Counting]]
[[../index]] [[../index]]

16
tech/array.wiki Normal file
View File

@ -0,0 +1,16 @@
= Array =
A sequential data structure of consecutive items. Fixed length (usually).
== Good for ==
* Fixed size sets of data
* Acessing an index in O(1)
* Data that doesnt change often
== Bad for ==
* Data that will change sizes often
* Data when you need to search by contents, not index
[[algorithms]]

36
tech/linked_list.wiki Normal file
View File

@ -0,0 +1,36 @@
= Linked lists =
A Sequential "list" of elements that is basically a daisy chain of pointers.
Comes in single and double linked flavors. This thing really has one good
property but that can be abused by linking it with other data structures (think
LRUCache)
== Good for ==
* Data that is often swaped or deleted, done in O(1)
== Bad for ==
* Basically everything else
== Optimize ==
If memory is a real concern you can XOR the pointers to the next and prev items.
To do this you need to xor the prev and next addresses, then when traversing
xor the previous and the combined pointer. This really is only when youre
worrying about like 4 bytes per node and either have tons of nodes or memory is
precious and the time spent XORing is a valid tradeoff.
== Visual ==
{{{
Head Tail
---------------- --------- --------- --------- ----------------
| Data | | Data | | Data | | Data | | Data |
| prev* (NULL) | <= | prev* | <= | prev* | <= | prev* | <= | prev* |
| next* | => | next* | => | next* | => | next* | => | next* (NULL) |
---------------- --------- --------- --------- ----------------
}}}
[[algorithms]]

16
tech/queue.wiki Normal file
View File

@ -0,0 +1,16 @@
= Queue =
A literal ordered queue. Keep an order of elements and only push on and remove
from the back
== Good For ==
* Keeping an order of elements
== Bad For ==
* Everything else
[[algorithms]]

0
tech/splay_tree.wiki Normal file
View File

16
tech/stack.wiki Normal file
View File

@ -0,0 +1,16 @@
= Stack =
First in Last Out container. Think like a stack of plates, you take off the top
first. Really speciallized and great for things like pre/postfix parsing and
like
== Good For ==
* Keeping an order of things added
== Bad For ==
* Everything else
[[algorithms]]

16
tech/vector.wiki Normal file
View File

@ -0,0 +1,16 @@
= Vector =
Like an array, but takes care of resizing
== Good for ==
* Fixed size sets of data
* Acessing an index in O(1)
* Data that doesnt change often
== Bad for ==
* Data that will change sizes often
* Data when you need to search by contents, not index
[[algorithms]]