{"componentChunkName":"component---src-templates-blog-post-jsx","path":"/blogs/linearSearch","result":{"data":{"blog":{"frontmatter":{"title":"LINEAR SEARCH","thumbnail":"blog56","date":"April 17, 2021","dsaCppCodeFile":"https://drive.google.com/file/d/1GO62d0buScKrOIXD1NmL_CXdGx1h2CUj/view?usp=sharing"},"excerpt":"<div class=\"my-2 p-2\">\n              <h4>Introduction</h4>\n              <div class=\"m-2\">\n                <p>\n                  Linear or Sequential Search Algorithm is a method for finding\n                  an element within a given data structure. It sequentially\n                  checks each element until the match is found or whole list has\n                  been scanned.\n                </p>\n                <p>Let&apos;s look at the working of this algorithm.</p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Working Procedure</h4>\n              <p class=\"text-muted\">\n                Do refer the code available the end of this section to\n                understand the following theory.\n              </p>\n              <ol class=\"pl-4\">\n                <li>Consider an array of n elements.</li>\n                <li>\n                  Create a temporary variable called pos to store the index of\n                  the searching element(if found) and initially assign it to -1.\n                </li>\n                <li>Loop through the array from 0 to n-1.</li>\n                <li>\n                  Check if array element is equal to the element to be searched.\n                </li>\n                <li>\n                  If it matches then assign this index+1 to pos variable and\n                  break the loop.\n                </li>\n                <li>\n                  After looping, if pos value is still -1 then it means that the\n                  element is not found in the given array.\n                </li>\n                <li>\n                  If it&apos;s not -1 then element is found the position whose value\n                  is pos.\n                </li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Time Complexity</h4>\n              <div class=\"m-2\">\n                <p class=\"text-muted\">\n                  <strong>PS: We give random inputs because the no. of input will\n                    generally be 100 or 1000 to find the time complexity and\n                    manually giving so many inputs is cumbersome work.</strong>\n                </p>\n                <p>\n                  The basic operation in this algorithm is the comparision\n                  between each array element and the element to be searched(step\n                  3 in the above working procedure). So increment the count\n                  variable above this if condition to get the count of no. of\n                  times the basic operation has been performed.\n                </p>\n                <span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \">\n      <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 74.32432432432432%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABJ0AAASdAHeZh94AAABqklEQVQ4y51Ti46CQAzk/z/QHBqVKA8TAUF5COjOzSyCED3vck2WLrvttJ1uHfwiVVUhPZ2QZRmOxyPKovxo79zvd1yvV7Rdh7Zt0TTNqDueJUmC3W6PKIrgeZ4FlsjPcFk/afro39EnDEMkaYoTMxHAVKc8L4rC7pVtEARYLBZwv77grlYI93vkmw0S7i+XCxxFE2DbdviLKGtleVYQBr0xICOiqWvk5zOcmLxEh4MtW2KM+XmxmlEIwJTATHquBZjncDbrNfk5WA5eAPXfH/ZaW3JrmKEpy+c9RZyflaHv+5b0un5mKIDHz3Ov7Ohg15DpI/DwGkSFExBQHCrCDHAA6q0BdfdhMwYb7CmizJa8YncC25R2ZmBFZzRCWc6BJhW8ALquOwfU0htj5wzLM7fbnNs3jZsBikg92mrgkN0yvDA0GEj/2PkJhxZwfId6BipN+h+iHlhARUjiGDlBMz7UhBOhi1hn1JpfTYC0qpGe3kuru5qkcVJqpquZVNpyGqJJy9DONCdimG2dy1m8y65kZVVV2hF1Zl19Ixqn5XIJnzO83XrW6ZN8A0XekZvHzHRlAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;\"></span>\n  <img class=\"gatsby-resp-image-image\" alt=\"Linear Search\" title=\"Linear Search\" src=\"/static/65f08daf8979be4c2f3ab26d378f657f/fcda8/graph.png\" srcset=\"/static/65f08daf8979be4c2f3ab26d378f657f/12f09/graph.png 148w,\n/static/65f08daf8979be4c2f3ab26d378f657f/e4a3f/graph.png 295w,\n/static/65f08daf8979be4c2f3ab26d378f657f/fcda8/graph.png 590w,\n/static/65f08daf8979be4c2f3ab26d378f657f/efc66/graph.png 885w,\n/static/65f08daf8979be4c2f3ab26d378f657f/2c5fd/graph.png 1006w\" sizes=\"(max-width: 590px) 100vw, 590px\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\" loading=\"lazy\">\n    </span>\n                <p class=\"lead\"><strong>Time Complexity: O(n)</strong></p>\n              </div>\n              <div class=\"my-2 p-2\">\n                  <strong>Similar posts:</strong>\n                  <a href=\"/blogs/binarySearch\">Binary Search</a>\n              </div>\n            </div>\n","html":"<div class=\"my-2 p-2\">\n              <h4>Introduction</h4>\n              <div class=\"m-2\">\n                <p>\n                  Linear or Sequential Search Algorithm is a method for finding\n                  an element within a given data structure. It sequentially\n                  checks each element until the match is found or whole list has\n                  been scanned.\n                </p>\n                <p>Let&apos;s look at the working of this algorithm.</p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Working Procedure</h4>\n              <p class=\"text-muted\">\n                Do refer the code available the end of this section to\n                understand the following theory.\n              </p>\n              <ol class=\"pl-4\">\n                <li>Consider an array of n elements.</li>\n                <li>\n                  Create a temporary variable called pos to store the index of\n                  the searching element(if found) and initially assign it to -1.\n                </li>\n                <li>Loop through the array from 0 to n-1.</li>\n                <li>\n                  Check if array element is equal to the element to be searched.\n                </li>\n                <li>\n                  If it matches then assign this index+1 to pos variable and\n                  break the loop.\n                </li>\n                <li>\n                  After looping, if pos value is still -1 then it means that the\n                  element is not found in the given array.\n                </li>\n                <li>\n                  If it&apos;s not -1 then element is found the position whose value\n                  is pos.\n                </li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Time Complexity</h4>\n              <div class=\"m-2\">\n                <p class=\"text-muted\">\n                  <strong>PS: We give random inputs because the no. of input will\n                    generally be 100 or 1000 to find the time complexity and\n                    manually giving so many inputs is cumbersome work.</strong>\n                </p>\n                <p>\n                  The basic operation in this algorithm is the comparision\n                  between each array element and the element to be searched(step\n                  3 in the above working procedure). So increment the count\n                  variable above this if condition to get the count of no. of\n                  times the basic operation has been performed.\n                </p>\n                <span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \">\n      <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 74.32432432432432%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABJ0AAASdAHeZh94AAABqklEQVQ4y51Ti46CQAzk/z/QHBqVKA8TAUF5COjOzSyCED3vck2WLrvttJ1uHfwiVVUhPZ2QZRmOxyPKovxo79zvd1yvV7Rdh7Zt0TTNqDueJUmC3W6PKIrgeZ4FlsjPcFk/afro39EnDEMkaYoTMxHAVKc8L4rC7pVtEARYLBZwv77grlYI93vkmw0S7i+XCxxFE2DbdviLKGtleVYQBr0xICOiqWvk5zOcmLxEh4MtW2KM+XmxmlEIwJTATHquBZjncDbrNfk5WA5eAPXfH/ZaW3JrmKEpy+c9RZyflaHv+5b0un5mKIDHz3Ov7Ohg15DpI/DwGkSFExBQHCrCDHAA6q0BdfdhMwYb7CmizJa8YncC25R2ZmBFZzRCWc6BJhW8ALquOwfU0htj5wzLM7fbnNs3jZsBikg92mrgkN0yvDA0GEj/2PkJhxZwfId6BipN+h+iHlhARUjiGDlBMz7UhBOhi1hn1JpfTYC0qpGe3kuru5qkcVJqpquZVNpyGqJJy9DONCdimG2dy1m8y65kZVVV2hF1Zl19Ixqn5XIJnzO83XrW6ZN8A0XekZvHzHRlAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;\"></span>\n  <img class=\"gatsby-resp-image-image\" alt=\"Linear Search\" title=\"Linear Search\" src=\"/static/65f08daf8979be4c2f3ab26d378f657f/fcda8/graph.png\" srcset=\"/static/65f08daf8979be4c2f3ab26d378f657f/12f09/graph.png 148w,\n/static/65f08daf8979be4c2f3ab26d378f657f/e4a3f/graph.png 295w,\n/static/65f08daf8979be4c2f3ab26d378f657f/fcda8/graph.png 590w,\n/static/65f08daf8979be4c2f3ab26d378f657f/efc66/graph.png 885w,\n/static/65f08daf8979be4c2f3ab26d378f657f/2c5fd/graph.png 1006w\" sizes=\"(max-width: 590px) 100vw, 590px\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\" loading=\"lazy\">\n    </span>\n                <p class=\"lead\"><strong>Time Complexity: O(n)</strong></p>\n              </div>\n              <div class=\"my-2 p-2\">\n                  <strong>Similar posts:</strong>\n                  <a href=\"/blogs/binarySearch\">Binary Search</a>\n              </div>\n            </div>"},"thumbnail":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='225'%20viewBox='0%200%20400%20225'%20preserveAspectRatio='none'%3e%3cpath%20d='M23%2099l-1%209v5h23l1-4v-3l2%203c1%203%202%204%204%204s2%200%202-6l1-10c0-3%200-3-2-3-3%200-3%200-3%203v4l-2-4c-1-3-2-3-7-3s-6%200-5%201v1l-1%206c0%205-1%205-4%206h-3v-7c0-7%200-7-2-7-3%200-3%200-3%205m33%200l-1%209v5h7c6%200%206%200%206-2%200-3%200-3-4-3l-4-1%202-1c3%200%205-1%205-3s-1-2-4-2c-4%200-3-2%202-2%203%200%204-1%204-3s0-2-6-2h-7v5m19-2c-2%202-6%2015-6%2016h3l3-1%202-2%202%201c0%202%205%203%206%202l-3-16c-1-4-5-4-7%200m12-1l-1%209c0%207%200%208%202%208l2-2c0-4%201-4%203-1s3%203%205%202V95c-2-2-10-1-11%201m25-1c-4%202-4%208%201%2010%203%203%203%204-1%204-3-1-5%201-3%203s9%201%2010-1h2c0%202%201%202%207%202s6%200%206-2c0-3%200-3-4-3-5%200-5-1%200-2%204-1%204-5%200-5s-4-2%201-2c3%200%204-1%204-3s0-2-6-2l-6%201-1%205c-1%206-1%206-4%203l-2-2h2c3%200%204-3%202-6h-8m28%203l-3%2010-2%205h3l3-1%203-2%202%202%203%201c2%200%202%200%202-4-2-11-3-14-6-15-3%200-3%200-5%204m13-3l-1%2010c0%208%200%208%202%208s3-1%203-3l1-3%201%203c2%203%203%203%205%202v-3c-1-3-1-4%201-6%202-6%200-9-6-9l-6%201m18%201c-6%205-6%2015%200%2017%205%201%2011-3%208-7-1-1-1-1-3%201-3%204-5%200-3-6%201-4%203-4%202-1%200%202%200%202%203%202%205-1%203-8-3-8l-4%202m11%204l-1%209c0%204%200%204%203%204s3%200%203-3l2-4c1-1%201%200%201%203%200%204%200%204%203%204l2-1%201-9v-9h-2c-2%200-3%201-3%203-1%205-4%205-4%201s0-4-2-4c-3%200-3%200-3%206m117%206l-1%208v7h9c8%200%209%201%209%203s0%202-2%202c-5-1-16%2013-21%2026l-3%2020%206-7c4-5%206-7%2010-8%206-3%206-2%206%201%200%202%200%202%201%201h3l-2-5-2-7-1-3v-3c3-2%2013-2%2013%200l-1%201h-2c0%202%203%202%204%201h1l-1%202-1%203-2%207-2%204h3c2%200%202-1%201-3%200-2%200-2%207%200%204%201%205%202%207%205l3%204%201%203%202%206%202%204%201%204c2%207-1%2010-9%208h-4v-24h-15v-3l-1-3-1%203v3h-17v7l-1%208c-2%202-2%203-1%203%202%200%203%204%202%206h-15c-2-3-2-5%201-8%204-6%202-7-2-2-3%203-4%205-4%207%200%203%200%203-9%204-9%200-9%200-9%202s1%203%205%203h5l-1%204v3h97l1-4c1-2%202-3%205-3%205-1%205-4%200-5h-3v-14c0-14-1-21-4-21l-2-2c-1-2-1-2-1%200%200%203-8%203-8-1%200-2%200-2%202-2%202%201%203%200%201-1-2-2-1-4%203-12%206-11%205-17-1-20l-3-2-1-1-1-4-1-5c-1-1-1%201-1%204v5l-3-1c-3-1-22%200-24%201-1%201-1-1-1-4v-5l-14-1-13%201m2%207v7h22v-3l1-3v-1l-1-3v-3h-22v6m-31%2028l1%209h12v-18h-13v9m3%2023l-1%205c0%203%200%204-1%203%200-4-2-3-3%200l2%204%202%203%203%201c2%200%202%200%202-3%200-2%200-3%202-3s2-1%202-4l-1-4-1%203c0%203-2%202-2-2%200-3-1-4-4-3'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":1.7699115044247788,"src":"/static/872a74626a958416a251b3e89d91407e/ee604/blog56.png","srcSet":"/static/872a74626a958416a251b3e89d91407e/69585/blog56.png 200w,\n/static/872a74626a958416a251b3e89d91407e/497c6/blog56.png 400w,\n/static/872a74626a958416a251b3e89d91407e/ee604/blog56.png 800w,\n/static/872a74626a958416a251b3e89d91407e/f3583/blog56.png 1200w,\n/static/872a74626a958416a251b3e89d91407e/e4d72/blog56.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"pageContext":{"blog":"linearSearch","thumbnail":"thumbnails/blog56.png"}},"staticQueryHashes":["2987289216","63159454"]}