{"id":2136,"date":"2018-10-08T13:28:29","date_gmt":"2018-10-08T12:28:29","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/?p=2136"},"modified":"2018-10-08T13:28:29","modified_gmt":"2018-10-08T12:28:29","slug":"higher-linear-search-standard-algorithm","status":"publish","type":"post","link":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/2018\/10\/08\/higher-linear-search-standard-algorithm\/","title":{"rendered":"Higher &#8211; Linear Search Standard Algorithm"},"content":{"rendered":"<p>A linear search is used to check if a value is in an array. There are two ways of doing this:-<\/p>\n<p>Check every value in the list, even if you find the value immediatly.<\/p>\n<pre class=\"brush: python; collapse: true; light: false; title: Linear Search V1; toolbar: true; notranslate\" title=\"Linear Search V1\">\r\n\r\ndef linSearchV1(target,numbers):\r\n    #Search for target in all of the numbers\r\n    found=False\r\n    for counter in range(len(numbers)):\r\n        if numbers&#x5B;counter]==target:\r\n            found=True\r\n    return found\r\n\r\n<\/pre>\n<p>Check until you find the value you are looking for, this is much more effient and can on average half the ammount of time taken for the program to run.<\/p>\n<pre class=\"brush: python; collapse: true; light: false; title: Linear Search V2; toolbar: true; notranslate\" title=\"Linear Search V2\">\r\n\r\ndef linSearchV2(target,numbers):   \r\n    #Search for the target numbers until it is found\r\n    counter=0\r\n    found=False\r\n    while not found and counter!=len(numbers):\r\n        if numbers&#x5B;counter]==target:\r\n            found=True\r\n        else:\r\n            counter=counter+1\r\n    return found\r\n\r\n<\/pre>\n<p>The same algorithms can be used to find a string in an array of strings or a character in a string.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A linear search is used to check if a value is in an array. There are two ways of doing this:- Check every value in the list, even if you find the value immediatly. def linSearchV1(target,numbers): #Search for target in all of the numbers found=False for counter in range(len(numbers)): if numbers&#x5B;counter]==target: found=True return found Check &hellip;<\/p>\n","protected":false},"author":32,"featured_media":1386,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[432098,432100],"tags":[],"class_list":["post-2136","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-higher","category-implementation-algorithm-specification"],"jetpack_featured_media_url":"https:\/\/blogs.glowscotland.org.uk\/nl\/public\/ColtnessHS-ComputingScience\/uploads\/sites\/12638\/2016\/09\/Slide4.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/2136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/comments?post=2136"}],"version-history":[{"count":3,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/2136\/revisions"}],"predecessor-version":[{"id":2139,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/2136\/revisions\/2139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media\/1386"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media?parent=2136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/categories?post=2136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/tags?post=2136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}