Original With Detail Out Put
Original With Detail Out Put
PROGRAM:
#include <iostream>
if (arr[i] == key)
return i;
return -1;
int main() {
int key = 6;
if (result != -1)
cout << "Element found at index " << result << endl;
else
cout << "Element not found" << endl;
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
if (arr[mid] == key)
return mid;
left = mid + 1;
else
right = mid - 1;
return -1;
int main() {
if (result != -1)
cout << "Element found at index " << result << endl;
else
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <algorithm>
int fib2 = 0;
int fib1 = 1;
fib2 = fib1;
fib1 = fib;
fib1 = fib2;
offset = i;
fib = fib2;
} else {
return i;
return offset + 1;
return -1;
int main() {
int arr[] = {10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100};
if (result != -1)
cout << "Element found at index " << result << endl;
else
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <stack>
#include <string>
if (isdigit(expression[i])) {
values.push(expression[i] - '0');
while (!ops.empty()) {
values.pop();
values.pop();
char op = ops.top();
ops.pop();
if (op == '+')
values.push(val1 + val2);
values.push(val1 - val2);
ops.push(expression[i]);
while (!ops.empty()) {
values.pop();
values.pop();
char op = ops.top();
ops.pop();
if (op == '+')
values.push(val1 + val2);
values.push(val1 - val2);
return values.top();
int main() {
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <stack>
int main() {
stack<int> s;
s.push(10);
s.push(20);
s.push(30);
s.pop();
cout << "Top element after pop: " << s.top() << endl;
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Queue {
private:
int* queue;
public:
Queue(int s) {
size = s;
} else {
queue[rear] = val;
}
void dequeue() {
if (front == -1) {
} else {
if (front == rear) {
} else {
void display() {
if (front == -1) {
} else {
};
int main() {
q.enqueue(10);
q.enqueue(20);
q.enqueue(30);
q.enqueue(40);
q.enqueue(50);
q.display();
q.dequeue();
q.display();
return 0;
OUTPUT:
RESULT
AIM:
PROGRAM:
#include <iostream>
class CircularQueue {
private:
int* queue;
public:
CircularQueue(int s) {
size = s;
} else {
queue[rear] = val;
}
void dequeue() {
if (front == -1) {
} else {
if (front == rear) {
} else {
void display() {
if (front == -1) {
} else {
};
int main() {
q.enqueue(10);
q.enqueue(20);
q.enqueue(30);
q.enqueue(40);
q.enqueue(50);
q.display();
q.dequeue();
q.display();
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <queue>
#include <vector>
class PriorityQueue {
private:
struct compare {
};
priority_queue<pair<int, int>, vector<pair<int, int> >, compare> pq; // Notice the space between >> here
public:
pq.push(make_pair(priority, val));
void dequeue() {
if (pq.empty()) {
} else {
cout << "Removed: " << pq.top().second << endl;
pq.pop();
void display() {
if (pq.empty()) {
} else {
while (!temp.empty()) {
cout << "(" << temp.top().second << ", " << temp.top().first << ") ";
temp.pop();
};
int main() {
PriorityQueue pq;
pq.enqueue(10, 2);
pq.enqueue(20, 1);
pq.enqueue(30, 3);
pq.enqueue(40, 2);
pq.display();
pq.dequeue();
pq.display();
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* next;
};
class SinglyLinkedList {
private:
Node* head;
public:
SinglyLinkedList() {
head = nullptr;
newNode->data = val;
newNode->next = nullptr;
if (head == nullptr) {
head = newNode;
} else {
temp = temp->next;
temp->next = newNode;
void display() {
if (head == nullptr) {
} else {
temp = temp->next;
};
int main() {
SinglyLinkedList list;
list.insertAtEnd(10);
list.insertAtEnd(20);
list.insertAtEnd(30);
list.display();
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* next;
Node* prev;
};
class DoublyLinkedList {
private:
Node* head;
public:
DoublyLinkedList() {
head = nullptr;
newNode->data = val;
newNode->next = nullptr;
newNode->prev = nullptr;
if (head == nullptr) {
head = newNode;
} else {
temp = temp->next;
temp->next = newNode;
newNode->prev = temp;
void displayForward() {
if (head == nullptr) {
} else {
temp = temp->next;
void displayBackward() {
if (head == nullptr) {
} else {
temp = temp->prev;
};
int main() {
DoublyLinkedList list;
list.insertAtEnd(10);
list.insertAtEnd(20);
list.insertAtEnd(30);
list.displayForward();
list.displayBackward();
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* next;
};
class CircularLinkedList {
private:
Node* head;
public:
CircularLinkedList() {
head = nullptr;
newNode->data = val;
if (head == nullptr) {
head = newNode;
newNode->next = head;
} else {
temp = temp->next;
temp->next = newNode;
newNode->next = head;
void display() {
if (head == nullptr) {
} else {
do {
temp = temp->next;
};
int main() {
CircularLinkedList list;
list.insertAtEnd(10);
list.insertAtEnd(20);
list.insertAtEnd(30);
list.display();
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int val) {
data = val;
};
class BinaryTree {
public:
Node* root;
BinaryTree() {
root = nullptr;
}
inorderTraversal(node->left);
inorderTraversal(node->right);
};
int main() {
BinaryTree tree;
tree.inorderTraversal(tree.root);
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int val) {
data = val;
};
class BinaryTree {
public:
Node* root;
BinaryTree() {
root = nullptr;
preorderTraversal(node->left);
preorderTraversal(node->right);
};
int main() {
BinaryTree tree;
tree.preorderTraversal(tree.root);
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int val) {
data = val;
};
class BinaryTree {
public:
Node* root;
BinaryTree() {
root = nullptr;
preorderTraversal(node->left);
preorderTraversal(node->right);
};
int main() {
BinaryTree tree;
tree.preorderTraversal(tree.root);
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int val) {
data = val;
};
class BinaryTree {
public:
Node* root;
BinaryTree() {
root = nullptr;
postorderTraversal(node->left);
postorderTraversal(node->right);
};
int main() {
BinaryTree tree;
tree.postorderTraversal(tree.root);
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <list>
#include <queue>
class Graph {
int V;
list<int>* adj;
public:
Graph(int V) {
this->V = V;
adj[v].push_back(w);
void BFS(int s) {
queue<int> q;
visited[s] = true;
q.push(s);
while (!q.empty()) {
s = q.front();
q.pop();
if (!visited[*i]) {
visited[*i] = true;
q.push(*i);
};
int main() {
Graph g(4);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 0);
g.addEdge(2, 3);
g.addEdge(3, 3);
cout << "Breadth-First Traversal starting from vertex 2: ";
g.BFS(2);
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
class Graph {
int V;
public:
Graph(int V) {
this->V = V;
adj.resize(V);
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
pq.push(make_pair(0, src));
dist[src] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
int v = (*i).first;
pq.push(make_pair(dist[v], v));
}
};
int main() {
Graph g(9);
g.addEdge(0, 1, 4);
g.addEdge(0, 7, 8);
g.addEdge(1, 2, 8);
g.addEdge(1, 7, 11);
g.addEdge(2, 3, 7);
g.addEdge(2, 8, 2);
g.addEdge(2, 5, 4);
g.addEdge(3, 4, 9);
g.addEdge(3, 5, 14);
g.addEdge(4, 5, 10);
g.addEdge(5, 6, 2);
g.addEdge(6, 7, 1);
g.addEdge(6, 8, 6);
g.addEdge(7, 8, 7);
g.dijkstra(0);
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
if (arr[mid] == key)
return mid;
return -1;
int main() {
int arr[] = {2, 3, 4, 10, 40};
if (result != -1)
cout << "Element found at index " << result << endl;
else
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
int i = 0, j = 0, k = left;
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
k++;
arr[k] = L[i];
i++;
k++;
arr[k] = R[j];
j++;
k++;
int main() {
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
int t = *a;
*a = *b;
*b = t;
i++;
swap(&arr[i], &arr[j]);
quickSort(arr, pi + 1, high);
int main() {
printArray(arr, n);
quickSort(arr, 0, n - 1);
printArray(arr, n);
return 0;
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <vector>
#include <algorithm>
struct Item {
int value;
int weight;
};
int totalValue = 0;
for (size_t i = 0; i < sortedItems.size(); ++i) {
capacity -= sortedItems[i].weight;
totalValue += sortedItems[i].value;
} else {
break;
return totalValue;
int main() {
std::vector<Item> items;
items.push_back(item1);
items.push_back(item2);
items.push_back(item3);
std::cout << "Maximum value in knapsack: " << maxValue << std::endl;
return 0;
}
OUTPUT:
RESUTL:
AIM:
PROGRAM:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
int n;
if (mask == (1 << n) - 1)
return dist[pos][0];
if (dp[mask][pos] != -1)
return dp[mask][pos];
}
return dp[mask][pos] = ans;
int main() {
std::cin >> n;
return 0;
OUTPUT:
RESULT:
AIM:
PROGRAM:
#include <iostream>
#include <vector>
#define N 8
if (board[row][i])
return false;
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 solveNQueens() {
if (solveNQueensUtil(board, 0)) {
printSolution(board);
return true;
} else {
return false;
int main() {
solveNQueens();
return 0;
OUTPUT:
RESULT: