{"componentChunkName":"component---src-components-blogpost-blogpost-jsx","path":"/blog/alg3/","result":{"data":{"site":{"siteMetadata":{"title":"K011"}},"mdx":{"id":"0f0086ad-9798-5e2f-885f-c57d4ee8f8ed","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\": \"Algorithms Search\",\n  \"date\": \"2021-08-26\",\n  \"description\": \"BFS & DFS\"\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(\"h2\", null, \"Linear Search\"), mdx(\"p\", null, \"linear search or sequence search is a method of finding a target value within the list.\\nIt consist of going through and examing each of the elements of the array until we find the element(s) we are looking for, or until we have looked at all the elements of the array.\"), mdx(\"p\", null, \"This is the slowest search method, but if our information is completely disordered, it is the only one that can help us find the data we are looking for.\"), mdx(\"center\", null, mdx(\"img\", {\n    className: \"w-60-l \",\n    src: \"https://imgur.com/9UaTiEP.gif\"\n  })), mdx(\"h2\", null, \"Binary Search\"), mdx(\"p\", null, \"Binary search works on ordered arrays. It consists of eliminating half of the elements of the array on which the search is performed after each comparison, it starts comparing the elements in te middle of the array with the searched value. If the searched value is equal to the middle element, its position in the array is returned. if the searched value is less or greater than the middle element, the search will cotinue in the first or second half, respectively, leaving the other half out of consideration; and if they are equal, the searched value has been found and the position is returned\\nwould function as a binary tree\"), mdx(\"center\", null, mdx(\"img\", {\n    className: \"w-60-l \",\n    src: \"https://imgur.com/yWJHmFH.gif\"\n  })), mdx(\"h1\", null, \"Graph / Tree  traversal\"), mdx(\"p\", null, \"In an unordered tree or in a network how can we search for items?. For this there are 2 algorithms:\"), mdx(\"center\", null, mdx(\"img\", {\n    className: \"w-60-l \",\n    src: \"https://imgur.com/XGy4i4e.gif\"\n  })), mdx(\"h2\", null, \"Breadth First Search\"), mdx(\"p\", null, \"Is another technique for traversing a graph. BFS visits the sibling vertices before visiting the child vertices, and a queue is used in the search process. this algorithm is ofted used to find the shortest path from one vertex to another.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"class Graph:\\n    def __init__(self):\\n        self.graph = defaultdict(list)\\n    def addEdge(self,u,v):\\n        self.graph[u].append(v)\\n \\n    def BFS(self, s):\\n \\n        visited = [False] * (max(self.graph) + 1)\\n        queue = []\\n \\n        queue.append(s)\\n        visited[s] = True\\n        \\n        while queue:\\n            s = queue.pop(0)\\n            print (s, end = \\\" \\\")\\n            for i in self.graph[s]:\\n                if visited[i] == False:\\n                    queue.append(i)\\n                    visited[i] = True\\n\")), mdx(\"h4\", null, \"PROS AND CONS\"), mdx(\"p\", null, \"This algorithm is used when the location of the node is believed to be at a high level, it is  located above.\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Pros\"), \": Shortest Path, Closer Nodes\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Cons\"), \": More memory\")), mdx(\"h2\", null, \"Depth First Search\"), mdx(\"p\", null, \"this algorithm visits the child vertices before visiting the sibling vertices.\\nThe algorithm begins with a chosen \\\"root\\\" vertex; it then iteratively transitions from the current vertex to an adjacent, unvisited vertex, until it can no longer find an unexplored vertex to transition to from this current location\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-python\"\n  }, \"class Graph:\\n    def __init__(self):\\n        self.graph = defaultdict(list)\\n  \\n    def addEdge(self, u, v):\\n        self.graph[u].append(v)\\n  \\n    # A recursive function used by DFS\\n    def DFSUtil(self, v, visited):\\n        visited.add(v)\\n        print(v, end=' ')\\n        for neighbour in self.graph[v]:\\n            if neighbour not in visited:\\n                self.DFSUtil(neighbour, visited)\\n  \\n    def DFS(self, v):\\n        visited = set()\\n        self.DFSUtil(v, visited)\\n\")), mdx(\"h4\", null, \"PROS AND CONS\"), mdx(\"p\", null, \"This algorithm is used when the location of the node is believed to be at a low level, it is  located above.\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Pros\"), \": Less Memory, Does path Exist?\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Cons\"), \": Can get slow\")), mdx(\"h1\", null, \"Shortest path\"), mdx(\"p\", null, \"This is a problem that consists of finding a path between two nodes, This problem does not necessarily have a unique solution. And it also has several applications, for example, the shortest way to go from one city to another, which bus or train to take to get faster to a destination, etc..\"), mdx(\"p\", null, \"In weighted graphs can be taken as the shortest path is that the sum of the weights of the edges that constitute it is minimal.\"), mdx(\"h2\", null, \"Dijkstra\"), mdx(\"h2\", null, \"Bellman\"));\n}\n;\nMDXContent.isMDXComponent = true;","frontmatter":{"title":"Algorithms Search","date":"2021-08-26","description":"BFS & DFS"}},"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/alg3/","id":"0f0086ad-9798-5e2f-885f-c57d4ee8f8ed"}},"staticQueryHashes":["63159454"]}