Algo 3 Flashcards
What is the relationship between data structure and algorithm?
Data structures are the way to arrange data so that some kind of operations on them get facilitated. Algorithm is the way to do something with the data in the most efficient way, so as most answers here indicate - Data structures help algorithms achieve their goals in the most efficient way.
compare the triplets
docs - Coding algorithms 3
Leet Code Symmetric Tree
https://www.youtube.com/watch?v=ta0mwKYLtmQ&t=767s
WORD PROCESSED - Algorithm Practices: The Coding Interview Bootcamp on Udemy
binary search tree
Binary Search Tree - Beau teaches JavaScript
* binary search tree uses the principle of binary search - on average operations are able to skip about half the tree
* runtime complexity
rewatch and learn the rest
A “binary search tree” (BST) or “ordered binary tree” is a type of binary tree where the nodes are arranged in order: for each node, all elements in its left subtree are less-or-equal to the node (<=), and all the elements in its right subtree are greater than the node (>).
Add 2 arrays together, so that first item in the new array is sum of 2 first items in the 2 arrays
Array.from([11, 21, 3], x=> x + x)
How to replace part of the string?
The following example will show you how to replace all underscore (_) character in a string with hyphen (-).
var myStr = ‘quick_brown_fox’;
You can use the JavaScript replace() method to replace the occurrence of any character in a string. However, the replace() will only replace the first occurrence of the specified character. To replace all the occurrence you can use the global (g) modifier.
myStr.replace(/_/g, “-“);
.slice
.subst
.substring
string.slice(start,end)
string.substr(start,length)
string.substring(start,end)
Note #1: slice()==substring()
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified. If you provide only one value it’ll return that index to end. Substring does the same.
What it does? The slice() method extracts parts of a string and returns the extracted parts in a new string. The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters. The substring() method extracts parts of a string and returns the extracted parts in a new string. Note #2:slice()==substring()
What is linear search?
Sometimes referred to as sequential search
An unordered list is searched for a particular value
Each value in the list is compared to the target value
Linear search implemented with a simple loop.
see graph PROCESSED - Coding Interview Algorithms 1 on word
Time taken is directly proportional to the amount of data
Linear search complexity
For n data items the time taken is equal to some constant multiplied by n.
The big time complexity is linear O(n)
Linked list cycle
https://www.youtube.com/watch?v=O7C6PlovZC8&list=PL5KO4h_e6La18s6O9BLqsN_kyaZ6oI5vW&index=9
3 methods
take notes on PROCESSED - Coding algorithms 3 - word
Leetcode Valid Parentheses
https://www.youtube.com/watch?v=q6-Dd_9d0e4&list=PL5KO4h_e6La18s6O9BLqsN_kyaZ6oI5vW&index=8
What is a hash map?
Didn’t understand this
take notes on PROCESSED - Coding algorithms 3 - word
Leetcode flipping image
https://www.youtube.com/watch?v=4dgYf8ozjmQ&list=PL5KO4h_e6La18s6O9BLqsN_kyaZ6oI5vW&index=7
Matrix = nested arrays that represent your rows and columns
take notes on PROCESSED - Coding algorithms 3 - word
what is the big O of simple nested loop
n^2 or quadratic
What is Binary Search (Javascript)
https://www.youtube.com/watch?v=tkip3psTLQI&list=PL5KO4h_e6La18s6O9BLqsN_kyaZ6oI5vW&index=6
If it says array is sorted is a good hint at the solution
take notes on PROCESSED - Coding algorithms 3 - word
JavaScript Interview Problem - Range Sum Of Binary Search Tree
Depth first search vs breadth first search
Bbq - use queue vs the other one uses stack or something else
https://www.youtube.com/watch?v=bnRYpOf61Pk&list=PL5KO4h_e6La18s6O9BLqsN_kyaZ6oI5vW&index=5
take notes on PROCESSED - Coding algorithms 3 - word
Lets Solve Leetcode Problems - 917 Reverse String Only
https://www.youtube.com/watch?v=YTaSgWyNSU0&list=PL5KO4h_e6La18s6O9BLqsN_kyaZ6oI5vW&index=4
take notes on PROCESSED - Coding algorithms 3 - word