I get to know this links and questions from my mentor in Timely Bootcamp.
Reference: https://www.youtube.com/watch?v=uhYq27iSk9s
1. Array
- Array is stored in a contiguous way. In RAM, the array would be stored in a subset of that memory in order.
- If we know the index that we want to access, we can directly figure out what is the value in constant time.
- However, in terms of inserting and removing element, it may take longer if it is not located at the end of array.
- Time complexity of inserting/removing middle of an array: O(n)
- Time complexity of inserting/removing end of an array: O(1) ; big O of one time.
- We can't just remove an element in the middle, because that will be not contiguous anymore.
2. Linked List
- Stored an ordered list of elements. In RAM, the set of values are not have to be contiguous.
- We don't have to shift everything over like we did with an array.
- Insert/Remove End: O(1)
- Insert/Remove Mid: O(1)
3. HashMap
- Single most common data structure. It is actually built on top of arrays.
- Key + Value (The relationship itself is a matter here).
- Key = not like index of array, it could be any arbitrary everything (e.g., characters, numbers, strings).
- Value = Could be everything
- Insert/Remove/Search: O(1)
4. Queue
- Many cases, they are implemented using linked lists.
- Doubly linked list cues: having two pointers between each node. Typically used to process a set of elements in the same order that they are added.
- Push/Pop Front/Back: O(1)
5. Binary Tree
- For every single node, the left subtree of that node is going to be less than it.
- For every single node, the right subtree of that node is going to be larger than it.
- Less efficient versions of hashmaps
- Insert/Remove/Search: O(logn)
6. Trie/Prefix Tree
- Each note typically represents a single character and each node can have up to 26 children.
- Usually each node is for one of the characters in the alphabet so if you wanted to insert a new word into this
- ex. A -> N -> T (e.g., autocomplete in google search)
- Insert/Search: O(n)
7. Heap
- either min / max heap according to the node value.
- Every level in the tree will be completely full except for the last level potentially of the tree and while they're visualized as trees
- Insert/Pop: O(logn)
- Min/Max: O(1)
8. Graph
- wide range of potential
- Node + Neighbors
Other useful links:
2. https://www.hackerrank.com/
3. https://leetcode.com/tag/hash-table/
4. https://leetcode.com/problems/diameter-of-binary-tree/
5. https://leetcode.com/problems/maximum-width-of-binary-tree/solution/
6. https://leetcode.com/problems/maximum-depth-of-binary-tree/
'Coding 공부기록' 카테고리의 다른 글
[R] Convert Data between Wide and Long Format (0) | 2022.10.02 |
---|---|
타임리 부트캠프 시즌2 리트코드 숙제1 (0) | 2022.09.23 |
Behavior Questions Preparation (~6/28) (0) | 2022.06.28 |
[statistics] sample size 구하기 (0) | 2021.11.29 |
[SQL]leetcode medium 뿌시기 (0) | 2021.11.01 |