Posts

Showing posts from 2022

Alpha beta

 #include<iostream> using namespace std; const int MAX = 1000; const int MIN = -1000; int minimax(int depth, int nodeIndex, bool maximizingPlayer, int values[], int alpha, int beta) { if (depth == 3) return values[nodeIndex]; if (maximizingPlayer) { int best = MIN; for (int i = 0; i < 2; i++) { int val = minimax(depth + 1, nodeIndex * 2 + i, false, values, alpha, beta); best = max(best, val); alpha = max(alpha, best); if (beta <= alpha) break; } return best; } else { int best = MAX; for (int i = 0; i < 2; i++) { int val = minimax(depth + 1, nodeIndex * 2 + i, true, values, alpha, beta); best = min(best, val); beta = min(beta, best); if (beta <= alpha) break; } return best; } } int main() { int values[8] = { 3, 5, 6, 9, 1, 2, 0, -1 }; cout <<"The optimal value is : "<< minimax(0, 0, true, values, MIN, MAX);; return 0; }

Pl/sql

 create procedure fine_calculation(IN rno int(3), bname varchar(20))  begin  declare i_date date;  declare diff int;  declare fine_amt int;  declare exit handler for sqlexception select'table not found';  select dateofIssue into i_date from borrower where rollin=rno and bname = bname;  select datediff(curedate(),i_date) into diff;  if(diff>15 and diff<=30) then  set fine_amt = diff*5;  insert into fine values (rno,curdate(),fine_amt);  elseif(diff>30)then  set fine_amt = 15*5 + (diff-30)*50;  insert into fine values (rno,curdate(),fine_amt);  end if;  update borrower set statu = 'r' where rollin=rno and bname = bname;  end;  $

Selection sort

 #include <bits/stdc++.h> using namespace std; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } void selectionSort(int arr[], int n) { int i, j, min_idx; for (i = 0; i < n-1; i++) { min_idx = i; for (j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; if(min_idx!=i) swap(&arr[min_idx], &arr[i]); } } void printArray(int arr[], int size) { int i; for (i=0; i < size; i++) cout << arr[i] << " "; cout << endl; } int main() { int arr[] = {64, 25, 12, 22, 11}; int n = sizeof(arr)/sizeof(arr[0]); selectionSort(arr, n); cout << "Sorted array: \n"; printArray(arr, n); return 0; }

Dfs

 #include <bits/stdc++.h> using namespace std; class Graph { public: map<int, bool> visited; map<int, list<int> > adj; void addEdge(int v, int w); void DFS(int v); }; void Graph::addEdge(int v, int w) { adj[v].push_back(w); } void Graph::DFS(int v) { visited[v] = true; cout << v << " "; list<int>::iterator i; for (i = adj[v].begin(); i != adj[v].end(); ++i) if (!visited[*i]) DFS(*i); } int main() { Graph g; 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 << "Following is Depth First Traversal" " (starting from vertex 2) \n"; g.DFS(2); return 0; }

Bfs

#include<bits/stdc++.h> using namespace std; class Graph { int V; vector<list<int>> adj; public: Graph(int V); // Constructor void addEdge(int v, int w); void BFS(int s); }; Graph::Graph(int V) { this->V = V; adj.resize(V); } void Graph::addEdge(int v, int w) { adj[v].push_back(w); } void Graph::BFS(int s) { vector<bool> visited; visited.resize(V,false); list<int> queue; visited[s] = true; queue.push_back(s); while(!queue.empty()) { s = queue.front(); cout << s << " "; queue.pop_front(); for (auto adjecent: adj[s]) { if (!visited[adjecent]) { visited[adjecent] = true; queue.push_back(adjecent); } } } } 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 << "Following is Breadth First Traversal " << "(starting from vertex 2) \n"; g....

Pl SQL new

delimiter $ create procedure fine_calculation(IN rno int(3), bname char(20))  begin declare i_date date; declare diff int: declare fine_amt int; declare exit handler for sqlexception select 'Table not Found';  select dateofIssue into i_date from borrower where rollin = rno and bname = bname select datediff(curdate(),i_date) into diff; if(diff>15 and diff<=38) then set fine_amt = diff*5; insert into fine values(rno, curdate(), fine_amt); elseif(diff>30) then set fine_amt - 15*5 + (diff-30)*50; insert into fine values(rno, curdate(), fine_amt); end if;  update borrower set status ='R' where rollin=rno and bname bname; end; $

Plsql

delimiter $ create procedure fine.calculation(IN rno int(3), brame char(20)) begin declare i date date; declare diff int; declare fine.ast int; declare exit handler for sqlexception select 'Table not Found";  select dateofIssue into i date from borrower where rollin rno and bname -bname; select datediff(curdate(),i_date) into diff; if(diff>15 and diffe30) then set fine ost diffe5; insert into fine values(rno, curdate(), fine.cat); elseif(diff>38) then set fine ont- 15°5 (diff-30)*50; insert into fine values(rno, curdote, fine,ast); end if; update borrower set status 'R' where rollin-rno and bnane -bname; end;