Changed a couple of items under arrays.

This commit is contained in:
John Washam 2016-06-11 17:01:29 -07:00
parent bb429d2a38
commit 6472d3d1be

View File

@ -148,7 +148,7 @@ Arrays
- Resizing arrays: - Resizing arrays:
- https://class.coursera.org/algs4partI-010/lecture/19 - https://class.coursera.org/algs4partI-010/lecture/19
- https://www.lynda.com/Developer-Programming-Foundations-tutorials/Resizable-arrays/149042/177108-4.html - https://www.lynda.com/Developer-Programming-Foundations-tutorials/Resizable-arrays/149042/177108-4.html
- Implement a vector (mutable array with automatic resizing): * - Implement a vector (mutable array with automatic resizing):
* - Practice coding using arrays and pointers, and pointer math to jump to an index instead of using indexing. * - Practice coding using arrays and pointers, and pointer math to jump to an index instead of using indexing.
* - new raw data array with allocated memory * - new raw data array with allocated memory
- can allocate int array under the hood, just not use its features - can allocate int array under the hood, just not use its features
@ -157,22 +157,22 @@ Arrays
* - capacity() - number of items it can hold * - capacity() - number of items it can hold
* - is_empty() * - is_empty()
* - at(index) - returns item at given index, blows up if index out of bounds * - at(index) - returns item at given index, blows up if index out of bounds
* - append(item) - or push(item) - check size of element 2^ * - push(item)
* - insert(index, item) * - insert(index, item) - inserts item at index, shifts that index's value and trailing elements to the right
* - prepend(item) - can use insert above at index 0 * - prepend(item) - can use insert above at index 0
* - pop() - remove from end, return value * - pop() - remove from end, return value
- delete(index) - delete item at index, shifting all trailing elements left * - delete(index) - delete item at index, shifting all trailing elements left
- remove(item) - looks for value and removes index holding it (even if in multiple places) * - remove(item) - looks for value and removes index holding it (even if in multiple places)
- find(item) - looks for value and returns first index with that value * - find(item) - looks for value and returns first index with that value, -1 if not found
* - resize(new_capacity) // private function * - resize(new_capacity) // private function
- when you reach capacity, resize to double the size - when you reach capacity, resize to double the size
- when popping an item, if size is 1/4 of capacity, resize to half - when popping an item, if size is 1/4 of capacity, resize to half
- Time * - Time
- O(1) to add/remove at end (amortized for allocations for more space), index, or update - O(1) to add/remove at end (amortized for allocations for more space), index, or update
- O(n) to insert/remove elsewhere - O(n) to insert/remove elsewhere
- Space * - Space
- contiguous in memory, so proximity helps performance - contiguous in memory, so proximity helps performance
- space needed = (array capacity, which is >= n) * size of item - space needed = (array capacity, which is >= n) * size of item, but even if 2n, still O(n)
Linked lists Linked lists
- singly-linked - singly-linked
* - Description: https://www.coursera.org/learn/data-structures/lecture/kHhgK/singly-linked-lists * - Description: https://www.coursera.org/learn/data-structures/lecture/kHhgK/singly-linked-lists
@ -189,18 +189,20 @@ Linked lists
- push_front - push_front
- get_front - get_front
- pop_front - pop_front
- push_back - insert_before(node, value)
- get_back - insert_after(node, value)
- pop_back
- insert_before(node, item)
- insert_after(node, item)
- size() - size()
- is_empty() - is_empty()
- find(item) - assume each item is unique - find(value) - assume each item is unique
- remove(item) - assume each item is unique - remove(value) - assume each item is unique
- reverse - reverses the list
- doubly-linked list - doubly-linked list
- Description: https://www.coursera.org/learn/data-structures/lecture/jpGKD/doubly-linked-lists - Description: https://www.coursera.org/learn/data-structures/lecture/jpGKD/doubly-linked-lists
- reverse a singly-linked list - implement:
- same as above for singly linked list
- push_back()
- get_back()
- pop_back()
Stacks Stacks
- see: https://class.coursera.org/algs4partI-010/lecture - see: https://class.coursera.org/algs4partI-010/lecture
- https://www.coursera.org/learn/data-structures/lecture/UdKzQ/stacks - https://www.coursera.org/learn/data-structures/lecture/UdKzQ/stacks