{"id":406,"date":"2025-08-05T13:19:21","date_gmt":"2025-08-05T13:19:21","guid":{"rendered":"https:\/\/ruby-doc.org\/blog\/?p=406"},"modified":"2025-08-05T13:23:15","modified_gmt":"2025-08-05T13:23:15","slug":"time-complexity-of-linear-search-the-basics","status":"publish","type":"post","link":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/","title":{"rendered":"Time Complexity of Linear Search &#8211; The Basics"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png\" alt=\"Time Complexity of Linear Search\" class=\"wp-image-407\" srcset=\"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png 1024w, https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search-300x300.png 300w, https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search-150x150.png 150w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>When studying algorithms, one of the fundamental concepts you&#8217;ll encounter is <strong>time complexity<\/strong>\u2014a measure of how the runtime of an algorithm grows relative to its input size. Among the simplest and most widely taught algorithms is <strong>linear search<\/strong>, also known as <strong>sequential search<\/strong>. While it&#8217;s easy to understand and implement, its efficiency can vary depending on the context in which it&#8217;s used. In this article, we\u2019ll explore what linear search is, how it works, and\u2014most importantly\u2014the <strong>time complexity of linear search<\/strong> in different scenarios.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Linear Search?<\/h2>\n\n\n\n<p>Linear search is an algorithm used to find a particular element in a list or array by checking each element one by one from the beginning to the end. If the element is found, the index is returned; otherwise, the search continues until the end of the list is reached.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example:<\/h3>\n\n\n\n<p>Imagine searching for the number <strong>7<\/strong> in the list <code>[3, 5, 7, 9, 11]<\/code>. Linear search will:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Check 3 \u2192 not a match<\/li>\n\n\n\n<li>Check 5 \u2192 not a match<\/li>\n\n\n\n<li>Check 7 \u2192 match found at index 2<\/li>\n<\/ol>\n\n\n\n<p>It\u2019s that simple\u2014no sorting or pre-processing is required.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Time Complexity of Linear Search<\/h2>\n\n\n\n<p>The <strong>time complexity<\/strong> of an algorithm refers to how the runtime grows as the input size (<code>n<\/code>) increases. For linear search, this varies based on where the target element is located or if it exists in the list at all.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Best Case Time Complexity: O(1)<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>When it occurs<\/strong>: The element is found at the very beginning of the list (index 0).<\/li>\n\n\n\n<li><strong>Explanation<\/strong>: The algorithm only needs one comparison to find the target.<\/li>\n\n\n\n<li><strong>Real-world example<\/strong>: Searching for the first contact in your phonebook by name.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Average Case Time Complexity: O(n)<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>When it occurs<\/strong>: The element is equally likely to be anywhere in the list.<\/li>\n\n\n\n<li><strong>Explanation<\/strong>: On average, half of the list will be scanned before finding the element.<\/li>\n\n\n\n<li><strong>Formula<\/strong>: (n + 1) \/ 2 comparisons on average, which simplifies to O(n) in Big-O notation.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Worst Case Time Complexity: O(n)<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>When it occurs<\/strong>:\n<ul class=\"wp-block-list\">\n<li>The element is at the very end of the list<\/li>\n\n\n\n<li>Or the element is not in the list at all<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Explanation<\/strong>: The algorithm must check all <code>n<\/code> elements.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Why Linear Search Has Linear Time Complexity<\/h2>\n\n\n\n<p>Linear search doesn\u2019t use any shortcuts or divide-and-conquer strategies. It checks every element one by one, so:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you double the size of your data, the time taken roughly doubles.<\/li>\n\n\n\n<li>Therefore, the time grows <strong>linearly<\/strong> with the input size.<\/li>\n<\/ul>\n\n\n\n<p>This property gives the algorithm its name: <strong>linear<\/strong> search.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Space Complexity of Linear Search<\/h2>\n\n\n\n<p>While we focus on time complexity, it\u2019s also worth noting the <strong>space complexity<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Space Complexity: O(1)<\/strong><\/li>\n\n\n\n<li><strong>Why<\/strong>: Linear search only uses a constant amount of extra memory (like an index variable or a temporary placeholder), regardless of the size of the input array.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Comparison with Other Search Algorithms<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Algorithm<\/th><th>Time Complexity (Best \/ Average \/ Worst)<\/th><th>Requirements<\/th><\/tr><\/thead><tbody><tr><td>Linear Search<\/td><td>O(1) \/ O(n) \/ O(n)<\/td><td>No sorting needed<\/td><\/tr><tr><td>Binary Search<\/td><td>O(1) \/ O(log n) \/ O(log n)<\/td><td>Requires sorted array<\/td><\/tr><tr><td>Hashing (Lookup)<\/td><td>O(1) \/ O(1) \/ O(n)<\/td><td>Requires hash table setup<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Note<\/strong>: Binary search is significantly faster than linear search on large, sorted datasets, but it can&#8217;t be used on unsorted data.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">When to Use Linear Search<\/h2>\n\n\n\n<p>Despite its higher time complexity compared to other algorithms, linear search <a href=\"https:\/\/en.wikipedia.org\/wiki\/Linear_search\">is still useful<\/a> in many scenarios:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Small datasets<\/strong>: For small lists, the performance difference is negligible.<\/li>\n\n\n\n<li><strong>Unsorted data<\/strong>: When you don\u2019t want to sort the data just for a one-time search.<\/li>\n\n\n\n<li><strong>Simplicity<\/strong>: Great for quick prototypes or when algorithmic complexity isn\u2019t a concern.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Practical Example: Linear Search in Python<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">pythonCopyEdit<code>def linear_search(arr, target):\n    for i in range(len(arr)):\n        if arr[i] == target:\n            return i  # Element found\n    return -1  # Element not found\n\n# Example usage\nmy_list = [10, 23, 45, 70, 11]\nprint(linear_search(my_list, 70))  # Output: 3\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Also read our <a href=\"https:\/\/ruby-doc.org\/blog\/ruby-vs-python-a-comprehensive-comparison-for-developers\/\">ruby vs python<\/a> article.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Real-World Applications of Linear Search<\/h2>\n\n\n\n<p>While linear search isn\u2019t always the most efficient method, it\u2019s still widely used in practical scenarios, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Searching in small or dynamically changing datasets<\/strong><\/li>\n\n\n\n<li><strong>Filtering or scanning logs<\/strong><\/li>\n\n\n\n<li><strong>Checking for duplicates in real-time systems<\/strong><\/li>\n\n\n\n<li><strong>Educational purposes to teach algorithmic basics<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p>The <strong>time complexity of linear search<\/strong> is straightforward:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Best case<\/strong>: O(1)<\/li>\n\n\n\n<li><strong>Average case<\/strong>: O(n)<\/li>\n\n\n\n<li><strong>Worst case<\/strong>: O(n)<\/li>\n<\/ul>\n\n\n\n<p>Although not the most efficient algorithm for large datasets, linear search remains relevant due to its simplicity and zero prerequisites like sorting, according to <a href=\"https:\/\/ocw.mit.edu\/courses\/electrical-engineering-and-computer-science\/6-006-introduction-to-algorithms-spring-2020\/index.htm\">MIT<\/a>. Understanding its time complexity helps in choosing the right algorithm for the task at hand.<\/p>\n\n\n\n<p>Whether you&#8217;re optimizing performance or just starting to learn about algorithms, knowing when to use linear search\u2014and when not to\u2014is a foundational skill in computer science.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When studying algorithms, one of the fundamental concepts you&#8217;ll encounter is time complexity\u2014a measure of how the runtime of an algorithm grows relative to its input size. Among the simplest and most widely taught algorithms is linear search, also known as sequential search. While it&#8217;s easy to understand and implement, its efficiency can vary depending [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":407,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-406","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Time Complexity of Linear Search - The Basics - Ruby-Doc.org<\/title>\n<meta name=\"description\" content=\"Explore the time complexity of linear search in detail, including best, worst, and average cases with our in-depth guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Time Complexity of Linear Search - The Basics - Ruby-Doc.org\" \/>\n<meta property=\"og:description\" content=\"Explore the time complexity of linear search in detail, including best, worst, and average cases with our in-depth guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/\" \/>\n<meta property=\"og:site_name\" content=\"Ruby-Doc.org\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-05T13:19:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-05T13:23:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ryan McGregor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ryan McGregor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/\"},\"author\":{\"name\":\"Ryan McGregor\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#\\\/schema\\\/person\\\/db7fcc3c518c40f29f8bf79ffa678dfc\"},\"headline\":\"Time Complexity of Linear Search &#8211; The Basics\",\"datePublished\":\"2025-08-05T13:19:21+00:00\",\"dateModified\":\"2025-08-05T13:23:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/\"},\"wordCount\":741,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Time-Complexity-of-Linear-Search.png\",\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/\",\"name\":\"Time Complexity of Linear Search - The Basics - Ruby-Doc.org\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Time-Complexity-of-Linear-Search.png\",\"datePublished\":\"2025-08-05T13:19:21+00:00\",\"dateModified\":\"2025-08-05T13:23:15+00:00\",\"description\":\"Explore the time complexity of linear search in detail, including best, worst, and average cases with our in-depth guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Time-Complexity-of-Linear-Search.png\",\"contentUrl\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Time-Complexity-of-Linear-Search.png\",\"width\":1024,\"height\":1024,\"caption\":\"Time Complexity of Linear Search\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/time-complexity-of-linear-search-the-basics\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Time Complexity of Linear Search &#8211; The Basics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/\",\"name\":\"Ruby-Doc.org\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#organization\",\"name\":\"Ruby-Doc.org\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/Ruby-Doc.org_logo_cropped.png\",\"contentUrl\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/Ruby-Doc.org_logo_cropped.png\",\"width\":909,\"height\":833,\"caption\":\"Ruby-Doc.org\"},\"image\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/#\\\/schema\\\/person\\\/db7fcc3c518c40f29f8bf79ffa678dfc\",\"name\":\"Ryan McGregor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f7b4d11da7f55d40163cd9431935ce1148d9bd69c95928064822f7757b6314dd?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f7b4d11da7f55d40163cd9431935ce1148d9bd69c95928064822f7757b6314dd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f7b4d11da7f55d40163cd9431935ce1148d9bd69c95928064822f7757b6314dd?s=96&d=mm&r=g\",\"caption\":\"Ryan McGregor\"},\"url\":\"https:\\\/\\\/ruby-doc.org\\\/blog\\\/author\\\/ryan\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Time Complexity of Linear Search - The Basics - Ruby-Doc.org","description":"Explore the time complexity of linear search in detail, including best, worst, and average cases with our in-depth guide.","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:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/","og_locale":"en_US","og_type":"article","og_title":"Time Complexity of Linear Search - The Basics - Ruby-Doc.org","og_description":"Explore the time complexity of linear search in detail, including best, worst, and average cases with our in-depth guide.","og_url":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/","og_site_name":"Ruby-Doc.org","article_published_time":"2025-08-05T13:19:21+00:00","article_modified_time":"2025-08-05T13:23:15+00:00","og_image":[{"width":1024,"height":1024,"url":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png","type":"image\/png"}],"author":"Ryan McGregor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ryan McGregor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#article","isPartOf":{"@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/"},"author":{"name":"Ryan McGregor","@id":"https:\/\/ruby-doc.org\/blog\/#\/schema\/person\/db7fcc3c518c40f29f8bf79ffa678dfc"},"headline":"Time Complexity of Linear Search &#8211; The Basics","datePublished":"2025-08-05T13:19:21+00:00","dateModified":"2025-08-05T13:23:15+00:00","mainEntityOfPage":{"@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/"},"wordCount":741,"commentCount":0,"publisher":{"@id":"https:\/\/ruby-doc.org\/blog\/#organization"},"image":{"@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png","articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/","url":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/","name":"Time Complexity of Linear Search - The Basics - Ruby-Doc.org","isPartOf":{"@id":"https:\/\/ruby-doc.org\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#primaryimage"},"image":{"@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png","datePublished":"2025-08-05T13:19:21+00:00","dateModified":"2025-08-05T13:23:15+00:00","description":"Explore the time complexity of linear search in detail, including best, worst, and average cases with our in-depth guide.","breadcrumb":{"@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#primaryimage","url":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png","contentUrl":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/08\/Time-Complexity-of-Linear-Search.png","width":1024,"height":1024,"caption":"Time Complexity of Linear Search"},{"@type":"BreadcrumbList","@id":"https:\/\/ruby-doc.org\/blog\/time-complexity-of-linear-search-the-basics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ruby-doc.org\/blog\/"},{"@type":"ListItem","position":2,"name":"Time Complexity of Linear Search &#8211; The Basics"}]},{"@type":"WebSite","@id":"https:\/\/ruby-doc.org\/blog\/#website","url":"https:\/\/ruby-doc.org\/blog\/","name":"Ruby-Doc.org","description":"","publisher":{"@id":"https:\/\/ruby-doc.org\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ruby-doc.org\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ruby-doc.org\/blog\/#organization","name":"Ruby-Doc.org","url":"https:\/\/ruby-doc.org\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ruby-doc.org\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/07\/Ruby-Doc.org_logo_cropped.png","contentUrl":"https:\/\/ruby-doc.org\/blog\/wp-content\/uploads\/2025\/07\/Ruby-Doc.org_logo_cropped.png","width":909,"height":833,"caption":"Ruby-Doc.org"},"image":{"@id":"https:\/\/ruby-doc.org\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/ruby-doc.org\/blog\/#\/schema\/person\/db7fcc3c518c40f29f8bf79ffa678dfc","name":"Ryan McGregor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f7b4d11da7f55d40163cd9431935ce1148d9bd69c95928064822f7757b6314dd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f7b4d11da7f55d40163cd9431935ce1148d9bd69c95928064822f7757b6314dd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f7b4d11da7f55d40163cd9431935ce1148d9bd69c95928064822f7757b6314dd?s=96&d=mm&r=g","caption":"Ryan McGregor"},"url":"https:\/\/ruby-doc.org\/blog\/author\/ryan\/"}]}},"_links":{"self":[{"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/comments?post=406"}],"version-history":[{"count":1,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"predecessor-version":[{"id":410,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions\/410"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/media\/407"}],"wp:attachment":[{"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ruby-doc.org\/blog\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}