Sarthak To Marda A File
Sarthak To Marda A File
Sarthak To Marda A File
University
Nawabganj , Kanpur
Lab File
Submitted To : Submitted By :
Dr. Imran Khan Sarthak Tomar
Assistant Professor 200108053
CSE Department Information Technology (III)
INDEX
Serial
No.
Content Page No.
int n1 = q - p + 1;
int n2 = r - q;
int i, j, k;
i = 0;
j = 0;
k = p;
arr[k] = L[i];
i++;
} else {
arr[k] = M[j];
j++;
k++;
arr[k] = L[i];
i++;
k++;
arr[k] = M[j];
j++;
k++;
mergeSort(arr,low,mid);
mergeSort(arr,mid+1,high);
merge(arr,low,mid,high);
int main()
printArray(arr, arr_size);
printArray(arr, arr_size);
return 0;
#include <bits/stdc++.h>
int t = *a;
*a = *b;
*b = t;
{
if (arr[j] < pivot)
swap(&arr[i], &arr[j]);
return (i + 1);
quickSort(arr, pi + 1, high);
int i;
int main()
quickSort(arr, 0, n - 1);
printArray(arr, n);
return 0;
#include <bits/stdc++.h>
int i, w;
if (i == 0 || w == 0)
K[i][w] = 0;
else
return K[n][W];
}
int main()
int W = 50;
return 0;
#include<bits/stdc++.h>
int tsp(const vector<vector<int>>& cities, int pos, int visited, vector<vector<int>>& state)
if(state[pos][visited] != INT_MAX)
return state[pos][visited];
// can't visit ourselves unless we're ending & skip if already visited
continue;
int distance = cities[pos][i] + tsp(cities, i, visited | (1 << i), state);
state[pos][visited] = distance;
return state[pos][visited];
int main()
{ 20, 0, 30, 34 },
{ 42, 30, 0, 12 },
};
vector<vector<int>> state(cities.size());
return 0;
}
5: N – Queen problem implementation using C++.
#include <bits/stdc++.h>
#define N 4
if(board[i][j])
printf("\n");
int i, j;
if (board[row][i])
return false;
if (board[i][j])
return false;
return true;
if (col >= N)
return true;
if (isSafe(board, i, col)) {
board[i][col] = 1;
return true;
board[i][col] = 0;
return false;
bool solveNQ()
if (nQueens(board, 0) == false) {
return false;
printSolution(board);
return true;
}
int main()
solveNQ();
return 0;
#include <bits/stdc++.h>
int i, key, j;
key = arr[i];
j = i - 1;
arr[j + 1] = arr[j];
j = j - 1;
arr[j + 1] = key;
}
void printArray(int arr[], int n)
int i;
int main()
insertionSort(arr, N);
printArray(arr, N);
return 0;
#include <iostream>
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
largest = r;
if (largest != i) {
swap(arr[i], arr[largest]);
heapify(arr, N, largest);
heapify(arr, N, i);
swap(arr[0], arr[i]);
heapify(arr, i, 0);
int main()
printArray(arr, N);
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
int main(void)
{
int arr[] = { 2, 3, 4, 10, 40 };
int x = 10;
int n = sizeof(arr) / sizeof(arr[0]);
int result = binarySearch(arr, 0, n - 1, x);
if(result == -1)
cout << "Element is not present in array"<<endl;
else
cout << "Element is present at index " << result <<endl;
return 0;
}
10: Implement kth smallest element problem using C++.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N = 10;
int arr[N] = { 10, 5, 4, 3, 48, 6, 2, 33, 53, 10 };
int K = 4;