Dynamic Programming - Parts PART 1 - Memoization P ART 2 - Tabulation Dynamic Programming with Fibonacci Example Recursion: Slow because time complexity is O(2^n) func fibR (x int ) int { if x <= 2 { return 1 } return fibR (x- 1 ) + fibR (x- 2 ) } Dynamic Way Example Recursion with Stored Value: // Fast because it removes duplicate processes by checking map. // Tail recursion-ish // Results are hitchhiking each recursive call func fibR2 (x int , y map [ int ] int ) int { if _ , ok := y[x]; ok { return y[x] } if x <= 2 { return 1 } y[x] = fibR2 (x- 1 , y) + fibR2 (x- 2 , y) return y[x] }
Goal of analysis is to identify trends and relationships within data so you can accurately answer the questions you're asking. Most data is organized in tables, always have data in the right format. Definition : Analysis // process used to make sense of the data collected Sorting // involves arranging data into a meaningful order to make it easier to understand, analyze, visualize Outliers // data points that are very different from similarly collected data and might not be reliable values Filtering // extracting specific data that meet certain criteria while hiding the rest Customized sort order // when you sort data in a spreadsheet using multiple conditions The 4 phases of analysis: 1. Organize data // getting the right data in the right size and order - Sorting : arrange data in meaningful order - Filtering : can help find errors or outliers 2. Format and adjust data // filtering or sorting or compiling data in a better
Selection sort sorts an array by finding the lowest value element and appending it to an empty array. The algorithm will shrink the unsorted array and repeat the process recursively until all unsorted elements are used up. package main func selectionSort (list *[] int ) { sorted := make ([] int , 0 , len (*list)) unSorted := *list for i := 0 ; i < len (*list); i++ { min := unSorted[ 0 ] index := 0 for i , e := range unSorted { if e <= min { min = e index = i } } sorted = append (sorted, (unSorted)[index]) if index == 0 { unSorted = unSorted[ 1 :] } else if index == ( len (*list) - 1 ) { unSorted = unSorted[:index] } else { unSorted = append (unSorted[ 0 :index], unSorted[index+ 1 :]...) } } * list = sorted } /*func main() { x := []int{4, 6, 3, 2, 9, 7, 3, 5} fmt.Print
Comments
Post a Comment