5- amaliy mashg`ulot Mavzu


Download 280.2 Kb.
Sana19.04.2023
Hajmi280.2 Kb.
#1363942
Bog'liq
Algoritmlarni loyixalash Deadline 3


Guruh

F.I.Sh.

734-20

Xolmatov Dostonbek


5- Amaliy mashg`ulot
Mavzu: “Ajrat va hukmronlik qil” prinsipi bo‘yicha ishlaydigan algoritmlarni loyihalash. Elementlar jamlanmasini biror belgi bo‘yicha tartiblashtirish algoritmi. Bog‘langan graflarda marshrutlar, ularni narxi(masofasi) bo‘yicha baholash. Xasis algoritmlar. Eng qisqa marshrutni aniqlash algoritmi. Uni variantlar soni bo‘yicha hajmini baholash. Kruskal algoritmi. Prima algoritmi. Xoffman algoritmi.
Ishdan maqsad: “Ajrat va hukmronlik qil” prinsipi bo‘yicha ishlaydigan algoritmlarni loyihalash. Elementlar jamlanmasini biror belgi bo‘yicha tartiblashtirish algoritmi.
Amaliy qism:

#include


int binarqidiruv(char a[],int b, int o, char x){
if(o>=b)
{int mid=b+(o-b)/2;
if(a[mid]==x) return mid;
if(a[mid]>x) return binarqidiruv(a, b, mid-1, x);
return binarqidiruv(a, mid+1, o, x); } return -1;}
using namespace std;
int main()
{ int n;
cout<<"Massiv elementlari sonini kiriting: "; cin>>n;
char a[n];
cout<<"Massiv elementlarini kiriting: ";
for(int i=0; i{ cin>>a[i];} for (int i=n-1; i>0; i--)
{for(int j=0; ja[j+1]) {swap (a[j],a[j+1]); }}}
cout<<"Saralangan massiv: ";
for(int i=0; icout<cout<<"Qidirilayotgan elementni kiriting: "; cin>>x;
int natija=binarqidiruv(a, 0, n-1, x); cout<

Xulosa
Bu mavzuda biz “Ajrat va hukmronlik qil” prinsipi bo‘yicha ishlaydigan algoritmlarni loyihalash. Elementlar jamlanmasini biror belgi bo‘yicha tartiblashtirish algoritmi usulidan foydalanishni o`rgandik.

6- Amaliy mashg`ulot
Mavzu: Kesishmaydigan to‘plam ostilari va birlashmalarini qidirish algoritmi. NP-to‘liq masalalar. NP-to‘liq masalalarga keltirish usullari.
Ishdan maqsad: Kesishmaydigan to‘plam ostilari va birlashmalarini qidirish algoritmi. NP-to‘liq masalalar. NP-to‘liq masalalarga keltirish usullari.
Amaliy qism:

#include
using namespace std;
#define V 4
 
// implementation of traveling Salesman Problem
int travllingSalesmanProblem(int graph[][V], int s)
{
// store all vertex apart from source vertex
vector<int> vertex;
for (int i = 0; i < V; i++)
if (i != s)
vertex.push_back(i);
 
// store minimum weight Hamiltonian Cycle.
int min_path = INT_MAX;
do {
 
// store current Path weight(cost)
int current_pathweight = 0;
 
// compute current path weight
int k = s;
for (int i = 0; i < vertex.size(); i++) {
current_pathweight += graph[k][vertex[i]];
k = vertex[i];
}
current_pathweight += graph[k][s];
 
// update minimum
min_path = min(min_path, current_pathweight);
 
} while (
next_permutation(vertex.begin(), vertex.end()));
 
return min_path;
}
 
// Driver Code
int main()
{
// matrix representation of graph
int graph[][V] = { { 0, 10, 15, 20 },
{ 10, 0, 35, 25 },
{ 15, 35, 0, 30 },
{ 20, 25, 30, 0 } };
int s = 0;
cout << travllingSalesmanProblem(graph, s) << endl;
return 0;
}


Xulosa
Biz bu mavzuda kesishmaydigan to‘plam ostilari va birlashmalarini qidirish algoritmi. NP-to‘liq masalalar. NP-to‘liq masalalarga keltirish usullaridan foydalanishni o`rgandik.
Download 280.2 Kb.

Do'stlaringiz bilan baham:




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