본문 바로가기

Javascript/Algorithms

(12)
Dynamic Programming A method for solving a complex problem by breaking it down into collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions. 'dynamic' was chosen by Bellman to capture the time varing aspect of the problems. 'programming' didn't refer to computer programming but to finding an optimal program n the same way. It only works on problems with optimal su..
Dijkstra's Algorithm one of the most famous and widely used algorithms the shortest path between the vertices. Edsger Dijkstra, a Dutch programmer Useful for GPS - finding fastest route Network Routing - finds open shortest path for data Biology - used to model the spread of viruses among humans Airline tickets - finding cheapest route to your destination Many other uses! thr first thing is we need to do is adding a..
Merge Sort There is a family of sorting algorithms that can improve time complexity from O(n^2) to O(n log n) It was created by Jonathan Van Norman in 1948. it is a combination of two things - merging and sorting. it works by decomposing an array into smaller arrays, spliting up the larger array we are trying to sort into smaller sub arrays all the way down. first, splitting up until we end up with sorted ..
Insertion Sort Builds up the sort by gradually creating a larger left half which is always sorted taking an element one at a time and inserting it in the correct spot. Insertion Sort Pseudocode Start by picking the second element in the array Now compare the second element with the one before it and swap if necessary. Continue to the next element and if it is in the incorrect order, iterate through the sorted ..
Selection Sort similar to bubble sort. but instead of first placing large values into sorted position, the actual sorted data is accumulating at the beginning. Selection Sort Pseudocode Store the firtst element as the smallest vlaue you've seen so far. Compare this item to the next item in the array until you find a smaller number If a smaller number is found, designate that smaller number to be the new 'minim..
Bubble Sort Sotring is the process of rearranging the itmes in a collection so that the items are in some kind of order. it is common task. may different ways to sort thing and each has own defferent pros and cons. Built-In JavaScript Sorting it always doesn't work how we expect it should JavaScript Sort() method takes evety item that array is converted to a string and then the Unicode value of that is take..
Searching Algorithms Intro to Linear Search -> Checking every single thing at a set interval on item at a time -> many different search methods on arrays in JavaScript - indexOf, includes, find, findIndex Linear Search Pseudocode Loop through the array and check if the current array element is equal to the value If it is, return the index at which the element is found If the value is never found, return -1 Linear Se..
Recursion basic idea is taking one problem and doing it over and over on a smaller piece or on a chaning piece until you hit some endpoint which we call the base case. Recursion is different way of thinking about writing solution. can choose a solution iterative way or recursive way. A process that calls itself. ex) JSON.parse / JSON.stringify document.getElementById Object traversal the call stack - it i..