{"componentChunkName":"component---src-components-blogpost-blogpost-jsx","path":"/blog/alg2/","result":{"data":{"site":{"siteMetadata":{"title":"K011"}},"mdx":{"id":"c98c2810-15fb-5ccd-9192-96506790b393","body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Sorting algorithms\",\n  \"date\": \"2021-08-26\",\n  \"description\": \"Bubble sort .o0\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", null, \"Sorting algorithms\"), mdx(\"p\", null, \"Sorting algorithms are the methods of reorganize a large numbers of items into some order, the relation of order most common items are the numbers order or lexicgraphic order\"), mdx(\"h2\", null, \"What is it used for?\"), mdx(\"p\", null, \"The sorting algothims can be seen in companies like Google, Amazon, Apple. are highly used in data. Some examples can we see is:\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Order a list of products or clients by name\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Order a list of products by prices\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Order a list by size\")), mdx(\"p\", null, \"the most of the programming lenguages have a function prederterminate to sorting elements, but has a problem:\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"the issue with sort():\"), \" By not knowing wich algorithm we are using, we can have a problems. like in js the sort() method order elements by their unicode value, this implies that (3,1,22,100)\\u2014>(1,100,22,3).\"), mdx(\"a\", {\n    href: \"https://www.toptal.com/developers/sorting-algorithms\",\n    className: \"link  white hover-white-60\",\n    target: \"_blank\"\n  }, \"Interactive page\"), mdx(\"h2\", null, \"Algoritms:\"), mdx(\"p\", null, \"Exist a large sorting algorithms, that we can see them in \", mdx(\"a\", {\n    href: \"https://en.wikipedia.org/wiki/Sorting_algorithm\",\n    className: \"link  white hover-white-60\",\n    target: \"_blank\"\n  }, \" This link\"), \". all of these have their advantages and disavantages.\"), mdx(\"h3\", null, \"Complexity\"), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/A3hjDiv.jpg\"\n  })), mdx(\"h1\", null, \"Comparison sort\"), mdx(\"h2\", null, \"Burble sort\"), mdx(\"p\", null, \"the burble sort algortithm no have any situation practical. no situation in whitch we should use it.\"), mdx(\"p\", null, \"Is very easy to implemet\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"def bubbleSort(arr):\\n    n = len(arr)\\n    for i in range(n-1):\\n        for j in range(0, n-i-1):\\n              if arr[j] > arr[j + 1] :\\n                arr[j], arr[j + 1] = arr[j + 1], arr[j]\\n\")), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/QHhRBTv.gif\"\n  })), mdx(\"h2\", null, \"Selection sort\"), mdx(\"p\", null, \"This one has no practical use, as above\"), mdx(\"p\", null, \"likewise, this is very easy to implement \"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"def selection_sort(L):\\n    for i in range(len(L)-1):\\n        min_index = i\\n        for j in range(i+1, len(L)-1):\\n            if L[j] < L[min_index]:\\n                min_index = j\\n        L[i], L[min_index] = L[min_index], L[i]\\n\")), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/E6oooQT.gif\"\n  })), mdx(\"h2\", null, \"Insertion sort\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"def insertionSort(arr):\\n    for i in range(1, len(arr)):\\n        key = arr[i]\\n        j = i-1\\n        while j >= 0 and key < arr[j] :\\n                arr[j + 1] = arr[j]\\n                j -= 1\\n        arr[j + 1] = key\\n\")), mdx(\"p\", null, \"This and the following 3 algorithms are part of the divide-and-conquer algorithms\"), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/VXHUMLB.gif\"\n  })), mdx(\"h2\", null, \"Merge Sort\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"def mergeSort(arr):\\n    if len(arr) > 1:\\n        mid = len(arr)//2\\n        L = arr[:mid]\\n        R = arr[mid:]\\n        mergeSort(L)\\n        mergeSort(R)\\n        i = j = k = 0\\n        while i < len(L) and j < len(R):\\n            if L[i] < R[j]:\\n                arr[k] = L[i]\\n                i += 1\\n            else:\\n                arr[k] = R[j]\\n                j += 1\\n            k += 1\\n        while i < len(L):\\n            arr[k] = L[i]\\n            i += 1\\n            k += 1\\n \\n        while j < len(R):\\n            arr[k] = R[j]\\n            j += 1\\n            k += 1\\n\")), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/SePllz6.gif\"\n  })), mdx(\"h2\", null, \"Quick Sort\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"def partition(arr, low, high):\\n    i = (low-1)\\n    pivot = arr[high]\\n  \\n    for j in range(low, high):\\n        if arr[j] <= pivot:\\n            i = i+1\\n            arr[i], arr[j] = arr[j], arr[i]\\n  \\n    arr[i+1], arr[high] = arr[high], arr[i+1]\\n    return (i+1)\\ndef quickSort(arr, low, high):\\n    if len(arr) == 1:\\n        return arr\\n    if low < high:\\n        pi = partition(arr, low, high)\\n        quickSort(arr, low, pi-1)\\n        quickSort(arr, pi+1, high)\\n\")), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/gbda6RF.gif\"\n  })), mdx(\"h2\", null, \"Heap sort\"), mdx(\"center\", null, mdx(\"img\", {\n    src: \"https://imgur.com/x3sDGmP.gif\"\n  })), mdx(\"p\", null, \"Heapsort is a non-recursive, non-stable, non-recursive sorting algorithm with computational complexity O(logn).\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"def heapify(arr, n, i): #\\n    largest = i \\n    l = 2 * i + 1\\n    r = 2 * i + 2\\n    if l < n and arr[i] < arr[l]:\\n        largest = l\\n    if r < n and arr[largest] < arr[r]:\\n        largest = r\\n    if largest != i:\\n        arr[i],arr[largest] = arr[largest],arr[i] \\n        heapify(arr, n, largest)\\ndef heapSort(arr):\\n    n = len(arr)\\n    for i in range(n // 2 - 1, -1, -1):\\n        heapify(arr, n, i)\\n    for i in range(n-1, 0, -1):\\n        arr[i], arr[0] = arr[0], arr[i] \\n        heapify(arr, i, 0)\\n\")), mdx(\"h1\", null, \"Non-Comparison sorting Algorithms\"), mdx(\"a\", {\n    href: \"https://en.wikipedia.org/wiki/Sorting_algorithm\",\n    className: \"link  white hover-white-60\",\n    target: \"_blank\"\n  }, \" more\"));\n}\n;\nMDXContent.isMDXComponent = true;","frontmatter":{"title":"Sorting algorithms","date":"2021-08-26","description":"Bubble sort .o0"}},"allMdx":{"edges":[{"node":{"frontmatter":{"title":"Classification","date":"2021-11-03","description":"Naive Bayes, Discriminant Analysis, Logistic Regression"},"fields":{"slug":"/blog/est4/"}}},{"node":{"frontmatter":{"title":"Regression and Prediction","date":"2021-11-02","description":"REGRESSION"},"fields":{"slug":"/blog/est3/"}}},{"node":{"frontmatter":{"title":"Distribution","date":"2021-11-01","description":"Data distributions"},"fields":{"slug":"/blog/est1/"}}},{"node":{"frontmatter":{"title":"Stats Testing","date":"2021-11-01","description":"Statistical Experiments and significance testing"},"fields":{"slug":"/blog/est2/"}}},{"node":{"frontmatter":{"title":"Recursion","date":"2021-08-26","description":"Algorithm recursion"},"fields":{"slug":"/blog/alg1/"}}}]}},"pageContext":{"slug":"/blog/alg2/","id":"c98c2810-15fb-5ccd-9192-96506790b393"}},"staticQueryHashes":["63159454"]}