{"id":3479,"date":"2021-08-03T09:02:54","date_gmt":"2021-08-03T09:02:54","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=3479"},"modified":"2022-11-16T11:03:43","modified_gmt":"2022-11-16T11:03:43","slug":"iterative-selection-sort-for-linked-list","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/","title":{"rendered":"Iterative Selection Sort For Linked List"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png\" alt=\"\" \/><\/p>\n<p>In this blog, we tackle a coding task that involves iterative selection sort for linked list. A linked list is unidirectional i.e. we can only traverse the linked list in one direction. A selection sort is an effective sorting algorithm that is used in comparison operations. Let\u2019s understand a brief explanation of the selection sort for linked list. <\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>In this problem we are given the head of a linked list denoting the whole linked list, we have to apply the Iterative selection sort for linked list. Suppose we have a linked list represented as &#8211; <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/75_1-01.png\" alt=\"\" \/><\/p>\n<p>Then the sorted linked list is given as &#8211;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/75_2-01.png\" alt=\"\" \/><\/p>\n<p>Selection sort on the Linked list works in a similar way as it does on arrays but here instead of accessing the elements directly, we will be dealing with the links. Most of the Linked List problems are based on the manipulation of the links.<\/p>\n<h3>Approach &amp; Algorithm of Iterative Selection Sort For Linked List<\/h3>\n<p>The idea is to Iterate over the given Linked list N times where N is the number of elements in the Linked list. In every iteration of the algorithm, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray of the Linked list.<br \/>\nNow we have to perform a similar swapping operation, which is done in the Linked list in 2 ways &#8211;<\/p>\n<ul>\n<li>By swapping the data parts of the nodes.<\/li>\n<li>By swapping the complete nodes.<\/li>\n<\/ul>\n<p>We will be using here the second way to swap the nodes by manipulating the links. While we do the swapping of the link parts of two nodes, four cases arise:  <\/p>\n<ul>\n<li>When nodes are adjacent and the first node is the head node.<\/li>\n<li>Nodes can be adjacent and the first node isn\u2019t the head node.<\/li>\n<li>Nodes might not be adjacent and the first node is the head node.<\/li>\n<li>Nodes might not be adjacent and the first node isn\u2019t the head node.<\/li>\n<\/ul>\n<h4>Iterative Selection Sort For Linked List Implementation<\/h4>\n\t\t\t\t\t\t\t<h3 style=\"margin-bottom:20px ;display:block;width:100%;margin-top:10px\">Iterative Selection Sort For Linked List <\/h3>\r\n\t\t\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_3482 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_3482 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_3482 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_3482 .wpsm_nav-tabs > li.active > a, #tab_container_3482 .wpsm_nav-tabs > li.active > a:hover, #tab_container_3482 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_3482 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_3482 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_3482 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_3482 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_3482 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_3482 .wpsm_nav-tabs > li > a:hover , #tab_container_3482 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_3482 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_3482 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_3482 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_3482 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_3482 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_3482 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_3482 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3482 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_3482 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3482 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_3482 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_3482\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_3482\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3482_1\" aria-controls=\"tabs_desc_3482_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3482_2\" aria-controls=\"tabs_desc_3482_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3482_3\" aria-controls=\"tabs_desc_3482_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3482_4\" aria-controls=\"tabs_desc_3482_4\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_3482\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_3482_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include <bits\/stdc++.h>\r\nusing namespace std;\r\nstruct Node {\r\n\tint data;\r\n\tNode* next;\r\n};\r\nNode* newNode(int val)\r\n{\r\n\tNode* temp = new Node;\r\n\ttemp->data = val;\r\n\ttemp->next = NULL;\r\n\treturn temp;\r\n}\r\nNode* selectionsortfunction(Node* head)\r\n{\r\n\tNode *x, *y, *z, *w, *s;\r\n\tx = y = head;\r\n\twhile (y->next) {\r\n\t\tz = w = y->next;\r\n\t\twhile (w) {\r\n\t\t\tif (y->data > w->data) {\r\n\t\t\t\tif (y->next == w) {\r\n\t\t\t\t\tif (y == head) {\r\n\t\t\t\t\t\ty->next = w->next;\r\n\t\t\t\t\t\tw->next = y;\r\n\t\t\t\t\t\ts = y;\r\n\t\t\t\t\t\ty = w;\r\n\t\t\t\t\t\tw = s;\r\n\t\t\t\t\t\tz = w;\r\n\t\t\t\t\t\thead = y;\r\n\t\t\t\t\t\tw = w->next;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\ty->next = w->next;\r\n\t\t\t\t\t\tw->next = y;\r\n\t\t\t\t\t\tx->next = w;\r\n\t\t\t\t\t\ts = y;\r\n\t\t\t\t\t\ty = w;\r\n\t\t\t\t\t\tw = s;\r\n\t\t\t\t\t\tz = w;\r\n\t\t\t\t\t\tw = w->next;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (y == head) {\r\n\t\t\t\t\t\ts = y->next;\r\n\t\t\t\t\t\ty->next = w->next;\r\n\t\t\t\t\t\tw->next = s;\r\n\t\t\t\t\t\tz->next = y;\r\n\t\t\t\t\t\ts = y;\r\n\t\t\t\t\t\ty = w;\r\n\t\t\t\t\t\tw = s;\r\n\t\t\t\t\t\tz = w;\r\n\t\t\t\t\t\tw = w->next;\r\n\t\t\t\t\t\thead = y;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\ts = y->next;\r\n\t\t\t\t\t\ty->next = w->next;\r\n\t\t\t\t\t\tw->next = s;\r\n\t\t\t\t\t\tz->next = y;\r\n\t\t\t\t\t\tx->next = w;\r\n\t\t\t\t\t\ts = y;\r\n\t\t\t\t\t\ty = w;\r\n\t\t\t\t\t\tw = s;\r\n\t\t\t\t\t\tz = w;\r\n\t\t\t\t\t\tw = w->next;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tz = w;\r\n\t\t\t\tw = w->next;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tx = y;\r\n\t\ty = y->next;\r\n\t}\r\n\t\r\n\treturn head;\r\n}\r\nvoid show(Node* head)\r\n{\r\n\twhile (head) {\r\n\t\tcout << head->data << \"->\";\r\n\t\thead = head->next;\r\n\t}\r\n}\r\nint main()\r\n{\r\n\tNode* head = newNode(5);\r\n\thead->next = newNode(4);\r\n\thead->next->next = newNode(3);\r\n\thead->next->next->next = newNode(2);\r\n\thead = selectionsortfunction(head);\r\n\tshow(head);\r\n\treturn 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3482_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<stdio.h>\r\n#include<stdlib.h>\r\n\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\nstruct Node* newNode(int val)\r\n{\r\n    struct Node* temp = (struct Node*)malloc(sizeof(struct Node));\r\n    temp->data = val;\r\n    temp->next = NULL;\r\n    return temp;\r\n}\r\nstruct Node* selectionsortfunction(struct Node* head)\r\n{\r\n    struct Node *x, *y, *z, *w, *s;\r\n    x = y = head;\r\n    while (y->next) {\r\n        z = w = y->next;\r\n        while (w) {\r\n            if (y->data > w->data) {\r\n                if (y->next == w) {\r\n                    if (y == head) {\r\n                        y->next = w->next;\r\n                        w->next = y;\r\n                        s = y;\r\n                        y = w;\r\n                        w = s;\r\n                        z = w;\r\n                        head = y;\r\n                        w = w->next;\r\n                    }\r\n                    else {\r\n                        y->next = w->next;\r\n                        w->next = y;\r\n                        x->next = w;\r\n                        s = y;\r\n                        y = w;\r\n                        w = s;\r\n                        z = w;\r\n                        w = w->next;\r\n                    }\r\n                }\r\n                else {\r\n                    if (y == head) {\r\n                        s = y->next;\r\n                        y->next = w->next;\r\n                        w->next = s;\r\n                        z->next = y;\r\n                        s = y;\r\n                        y = w;\r\n                        w = s;\r\n                        z = w;\r\n                        w = w->next;\r\n                        head = y;\r\n                    }\r\n                    else {\r\n                        s = y->next;\r\n                        y->next = w->next;\r\n                        w->next = s;\r\n                        z->next = y;\r\n                        x->next = w;\r\n                        s = y;\r\n                        y = w;\r\n                        w = s;\r\n                        z = w;\r\n                        w = w->next;\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                z = w;\r\n                w = w->next;\r\n            }\r\n        }\r\n        x = y;\r\n        y = y->next;\r\n    }\r\n    \r\n    return head;\r\n}\r\nvoid show(struct Node* head)\r\n{\r\n    while (head) {\r\n        printf(\"%d->\",head->data);\r\n        head = head->next;\r\n    }\r\n}\r\nint main()\r\n{\r\n   struct Node* head = newNode(5);\r\n    head->next = newNode(4);\r\n    head->next->next = newNode(3);\r\n    head->next->next->next = newNode(2);\r\n    head = selectionsortfunction(head);\r\n    show(head);\r\n    return 0;\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3482_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\nclass IterativeSort \r\n{\r\n    static class Node \r\n    {\r\n\t\tint data;\r\n\t\tNode next;\r\n\t};\r\n\tstatic Node newNode(int val)\r\n\t{\r\n\t\tNode temp = new Node();\r\n\r\n\t\ttemp.data = val;\r\n\r\n\t\ttemp.next = null;\r\n\r\n\t\treturn temp;\r\n\t}\r\n\r\n\t\/* Function to sort a linked list using selection\r\n\t sort algorithm by swapping the next pointers *\/\r\n\tstatic Node selectionSort(Node head)\r\n\t{\r\n\t\tNode a, b, c, d, r;\r\n\t\ta = b = head;\r\n\t\t\/\/ While b is not the last node\r\n\t\twhile (b.next != null) \r\n        {\r\n            c = d = b.next;\r\n            \/\/ While d is pointing to a valid node\r\n\t\t\twhile (d != null) \r\n            {\r\n                if (b.data > d.data) \r\n                {\r\n                    \/\/ If d appears immediately after b\r\n\t\t\t\t\tif (b.next == d) \r\n                    {\r\n\t\t\t\t\t\tif (b == head) \r\n                        {\r\n                            b.next = d.next;\r\n\t\t\t\t\t\t\td.next = b;\r\n\r\n\t\t\t\t\t\t\t\/\/ Swap b and d pointers\r\n\t\t\t\t\t\t\tr = b;\r\n\t\t\t\t\t\t\tb = d;\r\n\t\t\t\t\t\t\td = r;\r\n\r\n\t\t\t\t\t\t\tc = d;\r\n\r\n\t\t\t\t\t\t\t\/\/ Update the head\r\n\t\t\t\t\t\t\thead = b;\r\n\t\t\t\t\t\t\td = d.next;\r\n                        }\r\n\t\t\t\t\t\t\/\/ Case 2: b is not the head of the linked list\r\n\t\t\t\t\t\telse \r\n                        {\r\n\t\t\t\t\t\t\tb.next = d.next;\r\n\t\t\t\t\t\t\td.next = b;\r\n\t\t\t\t\t\t\ta.next = d;\r\n\r\n\t\t\t\t\t\t\t\/\/ Swap b and d pointers\r\n\t\t\t\t\t\t\tr = b;\r\n\t\t\t\t\t\t\tb = d;\r\n\t\t\t\t\t\t\td = r;\r\n\t\t\t\t\t\t\tc = d;\r\n\r\n\t\t\t\t\t\t\td = d.next;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n                    \/* If b and d have some non-zero number of nodes in between them *\/\r\n\t\t\t\t\telse \r\n                    {\r\n\t\t\t\t\t\t\/\/ Case 3: b is the head of the linked list\r\n\t\t\t\t\t\tif (b == head) \r\n                        {\r\n\t\t\t\t\t\t\t\/\/ Swap b.next and d.next\r\n\t\t\t\t\t\t\tr = b.next;\r\n\t\t\t\t\t\t\tb.next = d.next;\r\n\t\t\t\t\t\t\td.next = r;\r\n\t\t\t\t\t\t\tc.next = b;\r\n\r\n\t\t\t\t\t\t\t\/\/ Swap b and d pointers\r\n\t\t\t\t\t\t\tr = b;\r\n\t\t\t\t\t\t\tb = d;\r\n\t\t\t\t\t\t\td = r;\r\n\r\n\t\t\t\t\t\t\tc = d;\r\n\r\n\t\t\t\t\t\t\t\/\/ Skip to the next element\r\n\t\t\t\t\t\t\t\/\/ as it is already in order\r\n\t\t\t\t\t\t\td = d.next;\r\n\r\n\t\t\t\t\t\t\t\/\/ Update the head\r\n\t\t\t\t\t\t\thead = b;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\/\/ Case 4: b is not the head of the linked list\r\n\t\t\t\t\t\telse \r\n                        {\r\n\t\t\t\t\t\t\t\/\/ Swap b.next and d.next\r\n\t\t\t\t\t\t\tr = b.next;\r\n\t\t\t\t\t\t\tb.next = d.next;\r\n\t\t\t\t\t\t\td.next = r;\r\n\t\t\t\t\t\t\tc.next = b;\r\n\t\t\t\t\t\t\ta.next = d;\r\n\r\n\t\t\t\t\t\t\t\/\/ Swap b and d pointers\r\n\t\t\t\t\t\t\tr = b;\r\n\t\t\t\t\t\t\tb = d;\r\n\t\t\t\t\t\t\td = r;\r\n\r\n\t\t\t\t\t\t\tc = d;\r\n\r\n\t\t\t\t\t\t\t\/\/ Skip to the next element\r\n\t\t\t\t\t\t\t\/\/ as it is already in order\r\n\t\t\t\t\t\t\td = d.next;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse \r\n                {\r\n\t\t\t\t\tc = d;\r\n\t\t\t\t\td = d.next;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ta = b;\r\n\t\t\tb = b.next;\r\n\t\t}\r\n\t\treturn head;\r\n\t}\r\n\tstatic void printList(Node head)\r\n\t{\r\n\t\twhile (head != null) {\r\n\t\t\tSystem.out.print(head.data + \" \");\r\n\t\t\thead = head.next;\r\n\t\t}\r\n\t}\r\n\r\n\t\/\/ Driver Code\r\n\tpublic static void main(String args[])\r\n\t{\r\n\t\tNode head = newNode(5);\r\n\t\thead.next = newNode(1);\r\n\t\thead.next.next = newNode(9);\r\n\r\n\t\thead = selectionSort(head);\r\n\r\n\t\tprintList(head);\r\n\t}\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3482_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node:\r\n\t\r\n\tdef __init__(self, val):\r\n\t\tself.data = val\r\n\t\tself.next = None\r\n\r\ndef selectionSort(head):\r\n\r\n\ta = b = head\r\n\r\n\twhile b.next:\r\n\r\n\t\tc = d = b.next\r\n\r\n\t\twhile d:\r\n\r\n\t\t\tif b.data > d.data:\r\n\r\n\t\t\t\tif b.next == d:\r\n\r\n\t\t\t\t\tif b == head:\r\n\r\n\t\t\t\t\t\tb.next = d.next\r\n\t\t\t\t\t\td.next = b\r\n\t\t\t\t\t\tb, d = d, b\r\n\t\t\t\t\t\tc = d\r\n\t\t\t\t\t\thead = b\r\n\t\t\t\t\t\td = d.next\r\n\t\t\t\t\t\r\n\t\t\t\t\telse:\r\n\r\n\t\t\t\t\t\tb.next = d.next\r\n\t\t\t\t\t\td.next = b\r\n\t\t\t\t\t\ta.next = d\r\n\t\t\t\t\t\tb, d = d, b\r\n\t\t\t\t\t\tc = d\r\n\t\t\t\t\t\td = d.next\r\n\t\t\t\t\t\r\n\t\t\t\telse:\r\n\r\n\t\t\t\t\tif b == head:\r\n\r\n\t\t\t\t\t\tr = b.next\r\n\t\t\t\t\t\tb.next = d.next\r\n\t\t\t\t\t\td.next = r\r\n\t\t\t\t\t\tc.next = b\r\n\t\t\t\t\t\tb, d = d, b\r\n\t\t\t\t\t\tc = d\r\n\t\t\t\t\t\td = d.next\r\n\t\t\t\t\t\thead = b\r\n\t\t\t\t\t\r\n\t\t\t\t\telse:\r\n\r\n\t\t\t\t\t\tr = b.next\r\n\t\t\t\t\t\tb.next = d.next\r\n\t\t\t\t\t\td.next = r\r\n\t\t\t\t\t\tc.next = b\r\n\t\t\t\t\t\ta.next = d\r\n\t\t\t\t\t\tb, d = d, b\r\n\t\t\t\t\t\tc = d\r\n\t\t\t\t\t\td = d.next\r\n\t\t\t\t\t\r\n\t\t\telse:\r\n\r\n\t\t\t\tc = d\r\n\t\t\t\td = d.next\r\n\r\n\t\ta = b\r\n\t\tb = b.next\r\n\t\r\n\treturn head\r\n\r\ndef printList(head):\r\n\r\n\twhile head:\r\n\t\tprint(head.data, end = \" \")\r\n\t\thead = head.next\r\n\r\nif __name__ == \"__main__\":\r\n\r\n\thead = Node(5)\r\n\thead.next = Node(4)\r\n\thead.next.next = Node(3)\r\n\thead.next.next.next = Node(2)\r\n\r\n\thead = selectionSort(head)\r\n\r\n\tprintList(head)\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_3482 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_3482 a\"),jQuery(\"#tab-content_3482\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h4>Output:<\/h4>\n<p>2-&gt;3-&gt;4-&gt;5<\/p>\n<p><!--more--><\/p>\n<p><strong>Time Complexity for selection sort for linked list <\/strong>: O(N<sup>2<\/sup>), where N is the number of nodes present in the Linked List.<\/p>\n<h3>Conclusion<\/h3>\n<p>In this article, we have tried to explain the selection sort linked list in an iterative fashion and also described its approach and time &amp; space complexities. We hope this article will help you to enhance your knowledge regarding the linked list. You can practice more such problems on the linked list you can check out PrepBytes &#8211; <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a><\/p>\n<table width=\"641\">\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"641\" style=\"text-align: center\"><strong>Related Articles<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/doubly-circular-linked-list-introduction-and-insertion\/\">Doubly circular linked list in data structure<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantages-disadvantages-and-uses-of-a-doubly-linked-list\/\">Application of doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/applications-of-linked-list-data-structure\/\">Applications of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/difference-between-a-singly-linked-list-and-a-doubly-linked-list\/\">Singly linked list vs doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantage-and-disadvantage-of-linked-list-over-array\/\">Advantages and disadvantages of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\">Doubly linked list all operations in C<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/binary-search\/binary-search-on-linked-list\/\">Binary search in linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/bubble-sort-for-linked-list-by-swapping-nodes\/\">Bubble sort linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-in-doubly-linked-list\/\">Deletion in doubly linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-middle-of-linked-list\/\">Delete the middle node of a linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/adding-two-polynomials-using-linked-list\/\">Polynomial addition using linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-smallest-and-largest-elements-in-a-singly-linked-list\/\">Find max value and min value in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/insert-a-node-at-a-specific-position-in-a-linked-list\/\">Insert a node at a specific position in a linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/swap-nodes-in-a-linked-list-without-swapping-data\/\">Swap nodes in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/add-two-numbers-represented-by-linked-lists-set-1\/\">Add two numbers represented by linked lists<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-first-node-of-the-loop-in-a-linked-list\/\">Find starting point of loop in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/merge-sort-on-a-singly-linked-list\/\">Merge sort linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-at-a-given-position\/\">Delete a node from linked list at a given position<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/remove-duplicates-from-an-unsorted-linked-list\/\">Remove duplicates from unsorted linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-linked-list\/\">Reverse a linked list in Python<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>FAQs regarding selection sort for linked list<\/h2>\n<ol>\n<li><strong>What is meant by selection sort?<\/strong><\/li>\n<p>Selection sort is an effective sorting algorithm that is based on comparison operations. Selection sort adds one element in every iteration and selects the smallest element and moves it to the beginning by swapping with the front element.<\/p>\n<li><strong>What is the time and space complexity of the selection sort?<\/strong><\/li>\n<p>The time complexity of the selection sort algorithm is O(N2) and the space complexity of O(1).<\/p>\n<li><strong>Which sorting is best for the linked list?<\/strong><\/li>\n<p>Merge sort is preferred for sorting a linked list.<\/p>\n<li><strong>Can we implement selection sort for linked list recursively?<\/strong><\/li>\n<p>Yes, we can implement selection sort for linked list recursively.<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we tackle a coding task that involves iterative selection sort for linked list. A linked list is unidirectional i.e. we can only traverse the linked list in one direction. A selection sort is an effective sorting algorithm that is used in comparison operations. Let\u2019s understand a brief explanation of the selection sort [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-3479","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Iterative Selection Sort For Linked List | Linked List | Prepbytes<\/title>\n<meta name=\"description\" content=\"Selection Sort algorithm applied in an iterative way to a linked list reduces the space complexity keeping the time complexity the same.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Iterative Selection Sort For Linked List | Linked List | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Selection Sort algorithm applied in an iterative way to a linked list reduces the space complexity keeping the time complexity the same.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-03T09:02:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-16T11:03:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png\" \/>\n<meta name=\"author\" content=\"PrepBytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PrepBytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Iterative Selection Sort For Linked List\",\"datePublished\":\"2021-08-03T09:02:54+00:00\",\"dateModified\":\"2022-11-16T11:03:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\"},\"wordCount\":681,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\",\"name\":\"Iterative Selection Sort For Linked List | Linked List | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png\",\"datePublished\":\"2021-08-03T09:02:54+00:00\",\"dateModified\":\"2022-11-16T11:03:43+00:00\",\"description\":\"Selection Sort algorithm applied in an iterative way to a linked list reduces the space complexity keeping the time complexity the same.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Iterative Selection Sort For Linked List\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Iterative Selection Sort For Linked List | Linked List | Prepbytes","description":"Selection Sort algorithm applied in an iterative way to a linked list reduces the space complexity keeping the time complexity the same.","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:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Iterative Selection Sort For Linked List | Linked List | Prepbytes","og_description":"Selection Sort algorithm applied in an iterative way to a linked list reduces the space complexity keeping the time complexity the same.","og_url":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-03T09:02:54+00:00","article_modified_time":"2022-11-16T11:03:43+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Iterative Selection Sort For Linked List","datePublished":"2021-08-03T09:02:54+00:00","dateModified":"2022-11-16T11:03:43+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/"},"wordCount":681,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/","url":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/","name":"Iterative Selection Sort For Linked List | Linked List | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png","datePublished":"2021-08-03T09:02:54+00:00","dateModified":"2022-11-16T11:03:43+00:00","description":"Selection Sort algorithm applied in an iterative way to a linked list reduces the space complexity keeping the time complexity the same.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644911440930-Iterative%20Selection%20Sort%20For%20Linked%20List_Artboard%202.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/iterative-selection-sort-for-linked-list\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"Iterative Selection Sort For Linked List"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=3479"}],"version-history":[{"count":7,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3479\/revisions"}],"predecessor-version":[{"id":10509,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3479\/revisions\/10509"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=3479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=3479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=3479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}