{"id":182,"date":"2026-09-03T09:01:47","date_gmt":"2026-09-03T09:01:47","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=182"},"modified":"2026-09-03T09:01:47","modified_gmt":"2026-09-03T09:01:47","slug":"perform-selection-sort-by-taking-random-numbers-from-1-to-100","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2026\/09\/03\/perform-selection-sort-by-taking-random-numbers-from-1-to-100\/","title":{"rendered":"Perform selection sort by taking random numbers from 1 to 100."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random\n\ndef selection_sort(arr):\n    \"\"\"\n    Sorts a list using the Selection Sort algorithm.\n    \"\"\"\n    n = len(arr)\n    # Traverse through all array elements\n    for i in range(n):\n        # Find the minimum element in the remaining unsorted array\n        min_idx = i\n        for j in range(i + 1, n):\n            if arr[j] &lt; arr[min_idx]:\n                min_idx = j\n        # Swap the found minimum element with the first element of the unsorted part\n        arr[i], arr[min_idx] = arr[min_idx], arr[i]\n    return arr\n\n# --- Generate random numbers and sort them ---\n\n# Generate 10 random numbers between 1 and 100\nrandom_numbers = [random.randint(1, 100) for _ in range(10)]\nprint(\"Randomly generated numbers:\", random_numbers)\n\n# Sort the list using selection sort\nsorted_numbers = selection_sort(random_numbers.copy())  # Using copy to keep original\nprint(\"Sorted numbers (Ascending):\", sorted_numbers)\n\n# Generate another set of 15 random numbers\nrandom_numbers2 = [random.randint(1, 100) for _ in range(15)]\nprint(\"\\nAnother set of random numbers:\", random_numbers2)\nsorted_numbers2 = selection_sort(random_numbers2.copy())\nprint(\"Sorted numbers (Ascending):\", sorted_numbers2)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import random def selection_sort(arr): &#8220;&#8221;&#8221; Sorts a list using the Selection Sort algorithm. &#8220;&#8221;&#8221; n = len(arr) # Traverse through all array elements for i in range(n): # Find the minimum element in the remaining unsorted array min_idx = i for j in range(i + 1, n): if arr[j] &lt; arr[min_idx]: min_idx = j # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":96,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,3],"tags":[53,25,26,45],"class_list":["post-182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aiopd","category-bca","tag-aidpd","tag-bca","tag-bca-paper-solution","tag-python"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=182"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/182\/revisions"}],"predecessor-version":[{"id":183,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/182\/revisions\/183"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/96"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}