{"id":117,"date":"2023-11-11T02:23:16","date_gmt":"2023-11-10T23:23:16","guid":{"rendered":"http:\/\/www.cuneytbayrak.com\/?p=117"},"modified":"2025-02-21T00:45:03","modified_gmt":"2025-02-20T21:45:03","slug":"bir-dizideki-tek-sayilari-ve-cift-sayilari-kendi-icinde-grup-yapan-algoritma","status":"publish","type":"post","link":"http:\/\/www.cuneytbayrak.com\/?p=117","title":{"rendered":"Bir Dizideki Tek Say\u0131lar\u0131 ve \u00c7ift Say\u0131lar\u0131 Kendi \u0130\u00e7inde Grup Yapan Algoritma"},"content":{"rendered":"<p>Rastgele olu\u015fturulmu\u015f bir dizi i\u00e7indeki say\u0131lar\u0131 tek ve \u00e7iftler kendi i\u00e7inde grup olacak \u015fekilde s\u0131ralayan bir algoritma yapal\u0131m. Tek say\u0131lar dizinin sol taraf\u0131nda \u00e7ift say\u0131lar ise sa\u011f tarafta k\u00fcmelensin. Say\u0131lar\u0131n k\u00fc\u00e7\u00fckten b\u00fcy\u00fc\u011fe s\u0131ralanmas\u0131na gerek yok. (\u015fimdilik \ud83d\ude42 )<\/p>\n<p><a href=\"http:\/\/www.flowgorithm.org\/download\/index.html\" target=\"_blank\" rel=\"noopener\">Flowgorithm<\/a>\u00a0uygulamas\u0131 ile yapt\u0131\u011f\u0131m bir flowchart\u0131 a\u015fa\u011f\u0131da incelemenize sundum.<\/p>\n<p>Ayr\u0131ca program\u0131n tamam\u0131n\u0131 da\u00a0<a href=\"http:\/\/cuneytbayrak.com\/wp-content\/uploads\/2025\/02\/even_oddnumbergroupandsorting.rar\" target=\"_blank\" rel=\"noopener\">buradan\u00a0<\/a>indirebilirsiniz.<\/p>\n<p>A\u015fa\u011f\u0131da ki python kodlar\u0131na bakal\u0131m.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">import random\r\nimport time\r\n\r\n# Prepare random number generator\r\nrandom.seed()\r\n\r\nn = 100000\r\na = [0] * n\r\n\r\n# Measure start time\r\nst = time.time()\r\n\r\n# Fill the array with random integers between 1 and 25\r\nfor i in range(n):\r\n    a[i] = int(random.random() * 25) + 1\r\n\r\n# Rearrange the array based on the given conditions\r\nfor i in range(n):\r\n    if a[i] % 2 == 0:  # If the current number is even\r\n        tempc = i\r\n        for j in range(i + 1, n):\r\n            if a[j] % 2 != 0:  # If the next number is odd\r\n                # Swap a[j] and a[tempc]\r\n                temp = a[j]\r\n                a[j] = a[tempc]\r\n                a[tempc] = temp\r\n                tempc = j\r\n\r\n# Measure end time\r\net = time.time()\r\n\r\n# Calculate execution time\r\nexecution_time = et - st\r\nprint(\"Execution Time: \", execution_time)\r\n<\/pre>\n<\/div>\n<p>Bu algoritman\u0131n h\u0131z testini Jupyter compiler\u2019\u0131 \u00fczerinde test ettim ve sonucu a\u015fa\u011f\u0131da payla\u015f\u0131yorum.<\/p>\n<p><strong>Sonu\u00e7 : 506.00016689300537 sn<\/strong><\/p>\n<p>G\u00f6r\u00fcld\u00fc\u011f\u00fc gibi 100.000 adet bir veri seti i\u00e7in algoritmam 506,00017 saniye s\u00fcr\u00fcyor.<\/p>\n<p>Sizce bu s\u00fcre daha da h\u0131zland\u0131r\u0131labilir mi?<\/p>\n<p><em><strong>Not:\u00a0<\/strong><\/em><em>time.time() wall clock time\u2019\u0131 kullan\u0131r. CPU\u2019nun y\u00fcr\u00fctme s\u00fcresini \u00f6l\u00e7\u00fcmleyerek bir k\u0131yaslama yapmak istersek time.process_time() kullanmak gerekir. Kaynaklar\u0131n bekleme s\u00fcresini nihai sonuca dahil etmek istemiyorsak bu \u00e7\u00f6z\u00fcm\u00fc kullanmak en g\u00fczeli.\u00a0<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Kolay gele&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rastgele olu\u015fturulmu\u015f bir dizi i\u00e7indeki say\u0131lar\u0131 tek ve \u00e7iftler kendi i\u00e7inde grup olacak \u015fekilde s\u0131ralayan bir algoritma yapal\u0131m. Tek say\u0131lar dizinin sol taraf\u0131nda \u00e7ift say\u0131lar ise sa\u011f tarafta k\u00fcmelensin. Say\u0131lar\u0131n&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.cuneytbayrak.com\/?p=117\">Devam\u0131n\u0131 Oku<span class=\"screen-reader-text\">Bir Dizideki Tek Say\u0131lar\u0131 ve \u00c7ift Say\u0131lar\u0131 Kendi \u0130\u00e7inde Grup Yapan Algoritma<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[2],"tags":[33],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-algoritmalar","tag-even_oddnumbergroup","excerpt"],"_links":{"self":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=117"}],"version-history":[{"count":4,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":122,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/117\/revisions\/122"}],"wp:attachment":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}