contents(algo): fix typo and suggestions (#272)

pull/276/head
jomosz 3 years ago committed by GitHub
parent d90f358311
commit 87a923079d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,8 +32,8 @@ Arrays are among the most common data structures encountered during interviews.
**Disadvantages**
- Addition and removal of elements into/from the middle an array is slow because they remaining elements need to be shifted to accommodate the new/missing element. An exception to this is if the position to be inserted/removed is at the end of the array.
- For certain languages where the array size is fixed, it cannot alter its size after initialization. if an insertion causes the total number of elements to exceed the size, a new array has to be allocated and the existing elements have to be copied over. The act of creating a new array and transferring elements over takes O(n) time.
- Addition and removal of elements into/from the middle of an array is slow because the remaining elements need to be shifted to accommodate the new/missing element. An exception to this is if the position to be inserted/removed is at the end of the array.
- For certain languages where the array size is fixed, it cannot alter its size after initialization. If an insertion causes the total number of elements to exceed the size, a new array has to be allocated and the existing elements have to be copied over. The act of creating a new array and transferring elements over takes O(n) time.
## Learning resources

@ -50,7 +50,7 @@ Some helpful utility snippets:
| Set k<sup>th</sup> bit | <code>num &#124;= (1 << k)</code> |
| Turn off k<sup>th</sup> bit | `num &= ~(1 << k)`. |
| Toggle the k<sup>th</sup> bit | `num ^= (1 << k)`. |
| Multiple by 2<sup>k</sup> | `num << k` |
| Multiply by 2<sup>k</sup> | `num << k` |
| Divide by 2<sup>k</sup> | `num >> k` |
| Check if a number is a power of 2 | `(num & num - 1) == 0` or `(num & (-num)) == num` |
| Swapping two variables | `num1 ^= num2; num2 ^= num1; num1 ^= num2` |

@ -42,7 +42,7 @@ Be familiar with the various graph representations, graph search algorithms and
## Graph representations
You can be given a list of edges and you have to build your own graph from the edges so that you can perform a traversal on. them The common graph representations are:
You can be given a list of edges and you have to build your own graph from the edges so that you can perform a traversal on them. The common graph representations are:
- Adjacency matrix
- Adjacency list

@ -47,7 +47,7 @@ In the context of algorithm interviews, heaps and priority queues can be treated
| Operation | Big-O |
| ------------------------------------------------------ | --------- |
| Finx max/min | O(1) |
| Find max/min | O(1) |
| Insert | O(log(n)) |
| Remove | O(log(n)) |
| Heapify (create a heap out of given array of elements) | O(n) |
@ -58,7 +58,7 @@ In the context of algorithm interviews, heaps and priority queues can be treated
If you see a top or lowest _k_ being mentioned in the question, it is usually a signal that a heap can be used to solve the problem, such as in [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/).
If you require the top _k_ elements use a Min Heap of size _k_. Iterate through each element, pushing it into the heap. Whenever the heap size exceeds _k_, remove the minimum element, that will guarantee that you have the _k_ largest elements.
If you require the top _k_ elements use a Min Heap of size _k_. Iterate through each element, pushing it into the heap (for python `heapq`, invert the value before pushing to find the max). Whenever the heap size exceeds _k_, remove the minimum element, that will guarantee that you have the _k_ largest elements.
## Recommended questions

@ -21,7 +21,7 @@ toc_max_heading_level: 2
## Introduction
A a stack is an abstract data type that supports the operations **push** (insert a new element on the top of the stack) and **pop** (remove and return the most recently added element, the element at the top of the stack). As an abstract data type, stacks can be implemented using arrays or singly linked lists.
A stack is an abstract data type that supports the operations **push** (insert a new element on the top of the stack) and **pop** (remove and return the most recently added element, the element at the top of the stack). As an abstract data type, stacks can be implemented using arrays or singly linked lists.
This behavior is commonly called LIFO (last in, first out). The name "stack" for this type of structure comes from the analogy to a set of physical items stacked on top of each other.

@ -26,7 +26,7 @@ For each topic, you can expect to find:
1. Time complexities cheatsheet
1. Things to look out for during interviews
1. Corner cases
1. Useful techniques vRecommended questions to practice
1. Useful techniques with recommended questions to practice
## Study guides list

@ -93,7 +93,7 @@ When a question involves a BST, the interviewer is usually looking for a solutio
| Insert | O(log(n)) |
| Remove | O(log(n)) |
Space complexity of traversing balanced trees is O(n) while traversing very skewed trees (which is essentially a linked list) will be O(n).
Space complexity of traversing balanced trees is O(h) where h is the height of the tree, while traversing very skewed trees (which is essentially a linked list) will be O(n).
## Things to look out for during interviews

Loading…
Cancel
Save