{"id":1043,"date":"2023-11-04T08:42:38","date_gmt":"2023-11-04T08:42:38","guid":{"rendered":"https:\/\/learnlearn.uk\/igcsecs\/?page_id=1043"},"modified":"2023-11-04T08:42:38","modified_gmt":"2023-11-04T08:42:38","slug":"linear-search","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/","title":{"rendered":"Linear Search"},"content":{"rendered":"<div class=\"mceTemp\"><\/div>\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Linear Search<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Linear Search<\/h3>\n<p>Linear search, also known as sequential search, is a simple searching algorithm that checks each element of a list in order until a match is found or the entire list has been traversed.<\/p>\n<p><strong>Algorithm Steps<\/strong><\/p>\n<ol>\n<li>Start at the beginning of the list.<\/li>\n<li>Compare the target value with the current element.<\/li>\n<li>If the target value matches the current element, the search is successful and the position of the element is returned.<\/li>\n<li>If the target value does not match the current element, move to the next element in the list.<\/li>\n<li>Repeat steps 2-4 until a match is found or the end of the list is reached.<\/li>\n<\/ol>\n\n<\/div><h2 class=\"tabtitle\">Demonstration<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Interactive linear Search Demonstration<\/h3>\n<p><iframe loading=\"lazy\" title=\"Linear Search\" src=\"https:\/\/revise.learnlearn.uk\/teachassist\/static\/static_pages\/linear_search.html\" width=\"800\" height=\"400\" frameborder=\"0\"><\/iframe><\/p>\n\n<\/div><h2 class=\"tabtitle\">Complexity<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Time complexity &#8211; O(n)<\/h3>\n<p>Because linear search potentially needs to check each item (n) in the list once in the list, the time complexity is O(n)<\/p>\n<h3>Space complexity O(1)<\/h3>\n<p>The space complexity of a linear search algorithm is generally O(1), which means it uses a constant amount of additional memory regardless of the size of the input data. This is because a linear search does not require any additional data structures or memory allocation that scales with the size of the input.<\/p>\n<p>You may use a few variables for control and temporary storage, but the memory usage remains constant and doesn&#8217;t depend on the size of the input data.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Pros &amp; Cons<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Advantages &amp; Disadvantages of Linear Search<\/h3>\n<p><strong>Advantages<\/strong><\/p>\n<ul>\n<li>Simple and easy to understand<\/li>\n<li>Works on both sorted and unsorted lists<\/li>\n<li>Works well for small data sets<\/li>\n<li>Useful if you expect the item to be near the beginning of the list<\/li>\n<\/ul>\n<p><strong>Disadvantages<\/strong><\/p>\n<ul>\n<li>Inefficient for large data sets<\/li>\n<li>Time complexity: O(n), where n is the size of the list<\/li>\n<li>Can be slow compared to other search algorithms<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Python Code<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Example Python Code Implementation of Linear Search<\/h3>\n<p><iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python\/6e4c6ca1f0?start=result\" width=\"100%\" height=\"600\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<p><em>How does my implementation above differ to standard Python in the way it handles linear search?<\/em><\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linear Search Linear search, also known as sequential search, is a simple searching algorithm that checks each element of a list in order until a match is found or the entire list has been traversed. Algorithm Steps Start at the beginning of the list. Compare the target value with the current element. If the target&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Linear Search<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":100,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linear Search | IGCSE Computer Science | Learnlearn.uk<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linear Search | IGCSE Computer Science | Learnlearn.uk\" \/>\n<meta property=\"og:description\" content=\"Linear Search Linear search, also known as sequential search, is a simple searching algorithm that checks each element of a list in order until a match is found or the entire list has been traversed. Algorithm Steps Start at the beginning of the list. Compare the target value with the current element. If the target&hellip;&nbsp;Read More &raquo;Linear Search\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/\" \/>\n<meta property=\"og:site_name\" content=\"IGCSE Computer Science\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/\",\"url\":\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/\",\"name\":\"Linear Search | IGCSE Computer Science | Learnlearn.uk\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/#website\"},\"datePublished\":\"2023-11-04T08:42:38+00:00\",\"dateModified\":\"2023-11-04T08:42:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"IGCSE Computer Science Course\",\"item\":\"https:\/\/learnlearn.uk\/igcsecs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linear Search\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/igcsecs\/\",\"name\":\"IGCSE Computer Science\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/igcsecs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/#organization\",\"name\":\"IGCSE Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/igcsecs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/igcsecs\/wp-content\/uploads\/sites\/23\/2020\/08\/LearnLearnLogowhitenew.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/igcsecs\/wp-content\/uploads\/sites\/23\/2020\/08\/LearnLearnLogowhitenew.png\",\"width\":710,\"height\":98,\"caption\":\"IGCSE Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/igcsecs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linear Search | IGCSE Computer Science | Learnlearn.uk","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/","og_locale":"en_GB","og_type":"article","og_title":"Linear Search | IGCSE Computer Science | Learnlearn.uk","og_description":"Linear Search Linear search, also known as sequential search, is a simple searching algorithm that checks each element of a list in order until a match is found or the entire list has been traversed. Algorithm Steps Start at the beginning of the list. Compare the target value with the current element. If the target&hellip;&nbsp;Read More &raquo;Linear Search","og_url":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/","og_site_name":"IGCSE Computer Science","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/","url":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/","name":"Linear Search | IGCSE Computer Science | Learnlearn.uk","isPartOf":{"@id":"https:\/\/learnlearn.uk\/igcsecs\/#website"},"datePublished":"2023-11-04T08:42:38+00:00","dateModified":"2023-11-04T08:42:38+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/igcsecs\/linear-search\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/igcsecs\/linear-search\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"IGCSE Computer Science Course","item":"https:\/\/learnlearn.uk\/igcsecs\/"},{"@type":"ListItem","position":2,"name":"Linear Search"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/igcsecs\/#website","url":"https:\/\/learnlearn.uk\/igcsecs\/","name":"IGCSE Computer Science","description":"","publisher":{"@id":"https:\/\/learnlearn.uk\/igcsecs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/igcsecs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/igcsecs\/#organization","name":"IGCSE Computer Science","url":"https:\/\/learnlearn.uk\/igcsecs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/igcsecs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/igcsecs\/wp-content\/uploads\/sites\/23\/2020\/08\/LearnLearnLogowhitenew.png","contentUrl":"https:\/\/learnlearn.uk\/igcsecs\/wp-content\/uploads\/sites\/23\/2020\/08\/LearnLearnLogowhitenew.png","width":710,"height":98,"caption":"IGCSE Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/igcsecs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/igcsecs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Linear Search Linear search, also known as sequential search, is a simple searching algorithm that checks each element of a list in order until a match is found or the entire list has been traversed. Algorithm Steps Start at the beginning of the list. Compare the target value with the current element. If the target&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/pages\/1043"}],"collection":[{"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/comments?post=1043"}],"version-history":[{"count":1,"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/pages\/1043\/revisions"}],"predecessor-version":[{"id":1048,"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/pages\/1043\/revisions\/1048"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/igcsecs\/wp-json\/wp\/v2\/media?parent=1043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}