{"id":1140,"date":"2020-11-05T21:09:24","date_gmt":"2020-11-05T21:09:24","guid":{"rendered":"http:\/\/learnlearn.uk\/alevelcs\/?page_id=1140"},"modified":"2021-03-26T06:48:13","modified_gmt":"2021-03-26T06:48:13","slug":"insertion-sort","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/","title":{"rendered":"Insertion Sort"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Insertion Sort<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Insertion Sort<\/h3>\n<p><span style=\"color: #0000ff;\"><em>A Level Only \u2013 You are required to know how it works and be able to write Code \/ Pseudocode for the algorithm<\/em><\/span><\/p>\n\n<\/div><h2 class=\"tabtitle\">Python Tutorial<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python Tutorial Video<\/h3>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Insertion Sort Python Tutorial for Beginners\" title=\"Play video &quot;Insertion Sort Python Tutorial for Beginners&quot;\">https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M\" title=\"Insertion Sort Python Tutorial for Beginners\">Insertion Sort Python Tutorial for Beginners (https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M)<\/a><\/noscript><\/div>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Python Code<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python code<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">l <span style=\"color: #333333;\">=<\/span> [<span style=\"color: #0000dd; font-weight: bold;\">7<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">11<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">3<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">2<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">5<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">6<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">9<\/span>]\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">insertion_sort<\/span>(l):\r\n    <span style=\"color: #008800; font-weight: bold;\">for<\/span> outer_index <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #007020;\">len<\/span>(l)):\r\n        \r\n        current_item <span style=\"color: #333333;\">=<\/span>  l[outer_index]\r\n        inner_index <span style=\"color: #333333;\">=<\/span> outer_index\r\n        \r\n        <span style=\"color: #008800; font-weight: bold;\">while<\/span> inner_index <span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span> <span style=\"color: #000000; font-weight: bold;\">and<\/span> l[inner_index<span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>] <span style=\"color: #333333;\">&gt;<\/span> current_item:\r\n            l[inner_index] <span style=\"color: #333333;\">=<\/span> l[inner_index<span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>]\r\n            inner_index <span style=\"color: #333333;\">-=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n            \r\n        l[inner_index] <span style=\"color: #333333;\">=<\/span> current_item\r\n\r\n        \r\ninsertion_sort(l)\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">print<\/span>(l)\r\n<\/pre>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Pseudocode<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Pseudocode<\/h3>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Resources<\/h2>\n<div class=\"tabcontent\">\n\n<p><a href=\"https:\/\/docs.google.com\/spreadsheets\/d\/13Yzd9mB-9b3M644AFt95QF5l--2tf3CoJFyvhbhkWr0\/edit?usp=sharing\">Student Walkthrough Google Sheets Example<\/a><\/p>\n<p><a href=\"https:\/\/gist.github.com\/richardbwest\/10781a339c51006658b50638f7e09eb1\">Insertion Sort Python Animation<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Go to File &gt; Make a copy so that you can edit the sheet and practice the algorithm.<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Insertion Sort A Level Only \u2013 You are required to know how it works and be able to write Code \/ Pseudocode for the algorithm Python Tutorial Video https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7MVideo can&#8217;t be loaded because JavaScript is disabled: Insertion Sort Python Tutorial for Beginners (https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M) Python code l = [7,11,3,1,2,5,6,9] def insertion_sort(l): for outer_index in range(1,len(l)): current_item&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Insertion Sort<\/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":"","neve_meta_content_width":70,"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>Insertion Sort - A Level Computer Science<\/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\/alevelcs\/insertion-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Insertion Sort - A Level Computer Science\" \/>\n<meta property=\"og:description\" content=\"Insertion Sort A Level Only \u2013 You are required to know how it works and be able to write Code \/ Pseudocode for the algorithm Python Tutorial Video https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7MVideo can&#8217;t be loaded because JavaScript is disabled: Insertion Sort Python Tutorial for Beginners (https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M) Python code l = [7,11,3,1,2,5,6,9] def insertion_sort(l): for outer_index in range(1,len(l)): current_item&hellip;&nbsp;Read More &raquo;Insertion Sort\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"A Level Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-26T06:48:13+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/\",\"name\":\"Insertion Sort - A Level Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\"},\"datePublished\":\"2020-11-05T21:09:24+00:00\",\"dateModified\":\"2021-03-26T06:48:13+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"A Level Computer Science Home\",\"item\":\"https:\/\/learnlearn.uk\/alevelcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Insertion Sort\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"name\":\"A Level Computer Science\",\"description\":\"CIE Specification\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\",\"name\":\"A Level Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"A Level Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Insertion Sort - A Level Computer Science","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\/alevelcs\/insertion-sort\/","og_locale":"en_GB","og_type":"article","og_title":"Insertion Sort - A Level Computer Science","og_description":"Insertion Sort A Level Only \u2013 You are required to know how it works and be able to write Code \/ Pseudocode for the algorithm Python Tutorial Video https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7MVideo can&#8217;t be loaded because JavaScript is disabled: Insertion Sort Python Tutorial for Beginners (https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M) Python code l = [7,11,3,1,2,5,6,9] def insertion_sort(l): for outer_index in range(1,len(l)): current_item&hellip;&nbsp;Read More &raquo;Insertion Sort","og_url":"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/","og_site_name":"A Level Computer Science","article_modified_time":"2021-03-26T06:48:13+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/","url":"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/","name":"Insertion Sort - A Level Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#website"},"datePublished":"2020-11-05T21:09:24+00:00","dateModified":"2021-03-26T06:48:13+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/alevelcs\/insertion-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"A Level Computer Science Home","item":"https:\/\/learnlearn.uk\/alevelcs\/"},{"@type":"ListItem","position":2,"name":"Insertion Sort"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/alevelcs\/#website","url":"https:\/\/learnlearn.uk\/alevelcs\/","name":"A Level Computer Science","description":"CIE Specification","publisher":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization","name":"A Level Computer Science","url":"https:\/\/learnlearn.uk\/alevelcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"A Level Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/alevelcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Insertion Sort A Level Only \u2013 You are required to know how it works and be able to write Code \/ Pseudocode for the algorithm Python Tutorial Video https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7MVideo can&#8217;t be loaded because JavaScript is disabled: Insertion Sort Python Tutorial for Beginners (https:\/\/www.youtube.com\/watch?v=jRsm6FmHp7M) Python code l = [7,11,3,1,2,5,6,9] def insertion_sort(l): for outer_index in range(1,len(l)): current_item&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1140"}],"collection":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/comments?post=1140"}],"version-history":[{"count":8,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1140\/revisions"}],"predecessor-version":[{"id":1863,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1140\/revisions\/1863"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/media?parent=1140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}