0% found this document useful (0 votes)
10 views10 pages

Microsoft Word Document

Uploaded by

marshalpubg1111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views10 pages

Microsoft Word Document

Uploaded by

marshalpubg1111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

#include <iostream>

#include <queue>

#include <stack>

using namespace std;

const int N = 8; // Matritsa o'lchami

// Matritsa bilan ishlash uchun yordamchi funksiyalar

void printMatrix(int graph[N][N]) {

cout << "Matritsa smeshnosti grafa:" << endl;

for (int i = 0; i < N; i++) {

for (int j = 0; j < N; j++) {

cout << graph[i][j] << " ";

}
cout << endl;

void calculateDegrees(int graph[N][N], int degrees[N]) {

for (int i = 0; i < N; i++) {

degrees[i] = 0;

for (int j = 0; j < N; j++) {

degrees[i] += graph[i][j];

int calculateSaturation(int degrees[N]) {

int totalEdges = 0;

for (int i = 0; i < N; i++) {

totalEdges += degrees[i];

return totalEdges / 2; // Grafda takrorlangan qirralarni olib tashlash

void depthFirstSearch(int graph[N][N], int start) {

cout << "DFS (Chuqurlik bo'yicha o'tish): ";

bool visited[N] = {false};

stack<int> s;

s.push(start);

while (!s.empty()) {

int current = s.top();


s.pop();

if (!visited[current]) {

cout << current << " ";

visited[current] = true;

for (int i = N - 1; i >= 0; i--) {

if (graph[current][i] == 1 && !visited[i]) {

s.push(i);

cout << endl;

void breadthFirstSearch(int graph[N][N], int start) {

cout << "BFS (Kenglik bo'yicha o'tish): ";

bool visited[N] = {false};

queue<int> q;

q.push(start);

visited[start] = true;

while (!q.empty()) {

int current = q.front();

q.pop();

cout << current << " ";

for (int i = 0; i < N; i++) {


if (graph[current][i] == 1 && !visited[i]) {

q.push(i);

visited[i] = true;

cout << endl;

int main() {

int graph[N][N] = {

{0, 1, 0, 0, 0, 0, 0, 1},

{1, 0, 1, 1, 1, 1, 1, 0},

{0, 1, 0, 1, 0, 1, 0, 1},

{0, 1, 1, 0, 1, 1, 0, 0},

{0, 1, 0, 1, 0, 1, 0, 0},

{0, 1, 1, 1, 1, 0, 1, 0},

{0, 1, 0, 0, 0, 1, 0, 1},

{1, 0, 1, 0, 0, 0, 1, 0}

};

printMatrix(graph);

int degrees[N];

calculateDegrees(graph, degrees);

cout << "Cho'qqilar darajalari:" << endl;

for (int i = 0; i < N; i++) {

cout << "Cho'qqi " << i << ": " << degrees[i] << endl;
}

int minDegree = degrees[0], maxDegree = degrees[0];

for (int i = 1; i < N; i++) {

if (degrees[i] < minDegree) minDegree = degrees[i];

if (degrees[i] > maxDegree) maxDegree = degrees[i];

cout << "Minimal daraja: " << minDegree << endl;

cout << "Maksimal daraja: " << maxDegree << endl;

int saturation = calculateSaturation(degrees);

cout << "Grafning to'yinganligi: " << saturation << endl;

if (saturation == (N * (N - 1)) / 2) {

cout << "Graf to'liq (polniy)." << endl;

} else {

cout << "Graf to'liq emas." << endl;

depthFirstSearch(graph, 0);

breadthFirstSearch(graph, 0);

return 0;

}
#include <iostream>

#include <queue>

#include <stack>

using namespace std;

const int N = 8; // Matritsa o'lchami

// Matritsa bilan ishlash uchun yordamchi funksiyalar

void printMatrix(int graph[N][N]) {

cout << "Matritsa smeshnosti grafa:" << endl;

for (int i = 0; i < N; i++) {

for (int j = 0; j < N; j++) {

cout << graph[i][j] << " ";

cout << endl;

void calculateDegrees(int graph[N][N], int degrees[N]) {

for (int i = 0; i < N; i++) {

degrees[i] = 0;

for (int j = 0; j < N; j++) {

degrees[i] += graph[i][j];

}
}

int calculateSaturation(int degrees[N]) {

int totalEdges = 0;

for (int i = 0; i < N; i++) {

totalEdges += degrees[i];

return totalEdges / 2; // Grafda takrorlangan qirralarni olib tashlash

void depthFirstSearch(int graph[N][N], int start) {

cout << "DFS (Chuqurlik bo'yicha o'tish): ";

bool visited[N] = {false};

stack<int> s;

s.push(start);

while (!s.empty()) {

int current = s.top();

s.pop();

if (!visited[current]) {

cout << current << " ";

visited[current] = true;

for (int i = N - 1; i >= 0; i--) {

if (graph[current][i] == 1 && !visited[i]) {

s.push(i);

}
}

cout << endl;

void breadthFirstSearch(int graph[N][N], int start) {

cout << "BFS (Kenglik bo'yicha o'tish): ";

bool visited[N] = {false};

queue<int> q;

q.push(start);

visited[start] = true;

while (!q.empty()) {

int current = q.front();

q.pop();

cout << current << " ";

for (int i = 0; i < N; i++) {

if (graph[current][i] == 1 && !visited[i]) {

q.push(i);

visited[i] = true;

cout << endl;

int main() {

int graph[N][N] = {
{0, 1, 0, 0, 0, 0, 0, 1},

{1, 0, 1, 1, 1, 1, 1, 0},

{0, 1, 0, 1, 0, 1, 0, 1},

{0, 1, 1, 0, 1, 1, 0, 0},

{0, 1, 0, 1, 0, 1, 0, 0},

{0, 1, 1, 1, 1, 0, 1, 0},

{0, 1, 0, 0, 0, 1, 0, 1},

{1, 0, 1, 0, 0, 0, 1, 0}

};

printMatrix(graph);

int degrees[N];

calculateDegrees(graph, degrees);

cout << "Cho'qqilar darajalari:" << endl;

for (int i = 0; i < N; i++) {

cout << "Cho'qqi " << i << ": " << degrees[i] << endl;

int minDegree = degrees[0], maxDegree = degrees[0];

for (int i = 1; i < N; i++) {

if (degrees[i] < minDegree) minDegree = degrees[i];

if (degrees[i] > maxDegree) maxDegree = degrees[i];

cout << "Minimal daraja: " << minDegree << endl;

cout << "Maksimal daraja: " << maxDegree << endl;


int saturation = calculateSaturation(degrees);

cout << "Grafning to'yinganligi: " << saturation << endl;

if (saturation == (N * (N - 1)) / 2) {

cout << "Graf to'liq (polniy)." << endl;

} else {

cout << "Graf to'liq emas." << endl;

depthFirstSearch(graph, 0);

breadthFirstSearch(graph, 0);

return 0;

You might also like