Universitet jizzax filiali


Download 179.79 Kb.
bet1/4
Sana30.04.2023
Hajmi179.79 Kb.
#1412559
  1   2   3   4
Bog'liq
Structura 3 modul


O`ZBEKISTON RESPUBLIKASI OLIY VA O`RTA MAXSUS
T
A`LIM VAZIRLIGI



MIRZO ULUG`BEK NOMIDAGI O`ZBEKISTON MILLIY
UNIVERSITET JIZZAX FILIALI

AMALIY MATEMATIKA” FAKULTETI


AXBOROT TIZIMLAR VA TEXNOLOGIYALARI” YO’NALISHI


20-21-guruh

’’ALGARITMIK TILLAR VA BERILGANLAR STRUKTURASI ” FANIDAN



3-MODUL.
Bajardi: ­­­­­­­­­­­­­­­­­­­­­­­­­­­ ALLAYAROV TOHIRJON

Qabul qildi: ULUG’MURODOV.SH.B


Jizzax 2023
7-Amaliy topshiriq.

O'z tartib raqamingizga ko'ra misollarni tanlab olib (*) quyida keltirilgan
qidirish algoritmlariga qo'yib, (Albatta ijodiy yondoshgan holatda) dastur natijasini chop eting hamda, dasturingiz ishlash vaqtining optimal qiymatini ko'rsating
Misol uchun: Dasturni 1000 marta ishlatganda ishlash vaqtlarning o'rta arifmetik
qiymatini oling.
Quyidagi saralash algoritmlaridan foydalaning:
2. [3, 34, 38, 61, 62, 24, 15, 96, 64, 11, 1, 31, 70, 88, 46, 36, 57, 17, 33,
54, 63, 51, 69, 53, 79, 86, 29, 56, 81, 58]
Counting Sort
Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace _7amaliy


{
class Program
{
// hisoblash tartibi uchun funksiya
static void countingsort(int[] Array)
{
int n = Array.Length;
int max = 0;
//massivdagi eng katta elementni toping
for (int i = 0; i < n; i++)
{
if (max < Array[i])
{
max = Array[i];
}
}
// takrorlanish sonini saqlash uchun chastota massivi yarating
//berilgan massivdagi har bir noyob elementlar
int[] freq = new int[max + 1];
for (int i = 0; i < max + 1; i++)
{
freq[i] = 0;
}
for (int i = 0; i < n; i++)
{
freq[Array[i]]++;
}
//berilgan massivni freq massividan foydalanib tartiblash
for (int i = 0, j = 0; i <= max; i++)
{
while (freq[i] > 0)
{
Array[j] = i;
j++;
freq[i]--;
}
}
}

// function to print array


static void PrintArray(int[] Array)
{
int n = Array.Length;
for (int i = 0; i < n; i++)
Console.Write(Array[i] + " ");
Console.Write("\n");
}
// kodni sinab ko'ramiz
static void Main(string[] args)
{
int[] MyArray = { 3, 34, 38, 61, 62, 24, 15, 96, 64, 11, 1, 31, 70, 88,
46, 36, 57, 17, 33, 54, 63, 51, 69, 53, 79, 86, 29, 56, 81, 58 };
Console.Write("Asl massiv\n");
PrintArray(MyArray);
Console.WriteLine();
countingsort(MyArray);
Console.Write("\nSaralangan massiv\n");
PrintArray(MyArray);
Stopwatch stopwatch = new Stopwatch();
for (int i = 0; i < 1000; i++)
{
stopwatch.Start();
countingsort(MyArray);
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds + "ms");
}
Console.Write("Tartiblash vaqti: ");
Console.WriteLine(stopwatch.ElapsedMilliseconds + "ms");
Console.WriteLine(stopwatch.Elapsed.TotalMilliseconds / 1000 + "ms");
Console.ReadKey();
}
}
}
Javobi:






8-Amaliy topshiriq.

O'z tartib raqamingizga ko'ra misollarni tanlab olib Heap Sort qidirish
algoritmiga qo'yib, (Albatta ijodiy yondoshgan holatda) dastur natijasini chop eting hamda, dasturingiz ishlash vaqtining optimal qiymatini ko'rsating
Misol uchun: Dasturni 1000 marta ishlatganda ishlash vaqtlarning o'rta arifmetik
qiymatini oling
2. [38, 8, 100, 15, 6, 50, 52, 66, 73, 20, 95, 78, 56, 82, 27, 33, 41, 25, 10,
75, 60, 74, 90, 61, 47, 31, 53, 32, 19, 77]

Download 179.79 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling