0% found this document useful (0 votes)
25 views23 pages

How The Technical Term Derived

how the technical term derived

Uploaded by

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

How The Technical Term Derived

how the technical term derived

Uploaded by

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

Experiment: 1

Write a program to Implement FCFS


Source Code:
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);

printf("\nEnter Process Burst Timen");


for(i=0;i<n;i++)
{
printf("P[%d]:",i+1);
scanf("%d",&bt[i]);
}
wt[0]=0;

for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurn around Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);

return 0;
}
Output:
Experiment : 2
Write a program to Implement SJF
Source Code :
#include<stdio.h>
void main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("\nEnter Burst Time:\n");
for(i=0;i<n;i++)
{
printf("P%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1; //contains process number
}
//sorting burst time in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\nP%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=(float)total/n; //average turnaround time


printf("\n\nAverage Waiting Time = %f",avg_wt);
printf("\nAverage Turnaround Time = %f\n",avg_tat);
}
Output :
Experiment : 3
Write a program to Implement Priority Scheduling
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i;
printf("Enter the number of process : ");
scanf("%d",&n);
printf("\n Enter process : time priorities \n");
for(i=0;i<n;i++)
{
printf("\nProcess no %d : ",i+1);
scanf("%d %d",&pt[i],&pp[i]);
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(pp[i]<pp[j])
{
x=pp[i];
pp[i]=pp[j];
pp[j]=x;
x=pt[i];
pt[i]=pt[j];
pt[j]=x;
x=p[i];
p[i]=p[j];
p[j]=x;
}
}
}
w[0]=0;
awt=0;
t[0]=pt[0];
atat=t[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+pt[i];
atat+=t[i];
}
printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time Priority \n");
for(i=0;i<n;i++)
printf("\n %d \t\t %d \t\t %d \t\t %d \t\t %d \n",p[i],pt[i],w[i],t[i],pp[i]);
awt/=n;
atat/=n;
printf("\n Average Wait Time : %d \n",awt);
printf("\n Average Turn Around Time : %d \n",atat);
getch();
}
Output:
Experiment: 4
Write a program to Implement Implement Round Robin Scheduling
Source Code:
#include<stdio.h>
int main()
{
int i, limit, total = 0, x, counter = 0, time_quantum;
int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10];
float average_wait_time, average_turnaround_time;
printf("\nEnter Total Number of Processes: ");
scanf("%d", &limit);
x = limit;
for(i = 0; i < limit; i++)
{
printf("\nEnter Details of Process[%d]\n", i + 1);

printf("Arrival Time:\t");

scanf("%d", &arrival_time[i]);

printf("Burst Time:\t");

scanf("%d", &burst_time[i]);

temp[i] = burst_time[i];
}

printf("\nEnter Time Quantum:\t");


scanf("%d", &time_quantum);
printf("\nProcess ID\t\tBurst Time\t Turn around Time\t Waiting Time\n");
for(total = 0, i = 0; x != 0;)
{
if(temp[i] <= time_quantum && temp[i] > 0)
{
total = total + temp[i];
temp[i] = 0;
counter = 1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - time_quantum;
total = total + time_quantum;
}
if(temp[i] == 0 && counter == 1)
{
x--;
printf("\nProcess[%d]\t\t%d\t\t %d\t\t\t %d", i + 1, burst_time[i], total -
arrival_time[i], total - arrival_time[i] - burst_time[i]);
wait_time = wait_time + total - arrival_time[i] - burst_time[i];
turnaround_time = turnaround_time + total - arrival_time[i];
counter = 0;
}
if(i == limit - 1)
{
i = 0;
}
else if(arrival_time[i + 1] <= total)
{
i++;
}
else
{
i = 0;
}
}
average_wait_time = wait_time * 1.0 / limit;
average_turnaround_time = turnaround_time * 1.0 / limit;
printf("\n\nAverage Waiting Time:\t%f", average_wait_time);
printf("\nAvg Turn around Time:\t%f\n", average_turnaround_time);
return 0;
}

Output :
Experiment: 5
Write a program to implement Stack Operation using Link List.
i. Push
ii. Pop
iii. Search
Source Code:
#include <stdio.h>
#include <stdlib.h>
void push();
void pop();
void display();
struct node
{
int val;
struct node *next;
};
struct node *head;

void main ()
{
int choice=0;
while(choice != 4)
{
printf("Choose option(1-4): \n");
printf("\n1.Push\n2.Pop\n3.Display\n4.Exit");
printf("\nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:
{
printf("Exiting....");
break;
}
default:
{
printf("Please Enter valid choice!\n ");
}
};
}
}
void push ()
{
int val;
struct node *ptr = (struct node*)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("Not able to push the element!!");
}
else
{
printf("Enter the value: ");
scanf("%d",&val);
if(head==NULL)
{
ptr->val = val;
ptr -> next = NULL;
head=ptr;
}
else
{
ptr->val = val;
ptr->next = head;
head=ptr;

}
printf("Item pushed!!!\n\n");

}
}
void pop()
{
int item;
struct node *ptr;
if (head == NULL)
{
printf("Underflow");
}
else
{
item = head->val;
ptr = head;
head = head->next;
free(ptr);
printf("Item popped...\n");

}
}
void display()
{
int i;
struct node *ptr;
ptr=head;
if(ptr == NULL)
{
printf("Stack is empty!!!\n");
}
else
{
printf("Printing Stack elements: \n");
while(ptr!=NULL)
{
printf("%d\n",ptr->val);
ptr = ptr->next;
}
}
}

Output:
Push: Display: Pop:
Experiment: 6
Write a Program to implement Queue operation using Link List
i. Enqueue
ii. Dequeue
Source Code:
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *next;
};
struct node *front = NULL;
struct node *rear = NULL;
void enqueue(int value) {
struct node *ptr;
ptr = (struct node *)malloc(sizeof(struct node));
ptr->data = value;
ptr->next = NULL;
if ((front == NULL) && (rear == NULL)) {
front = rear = ptr;
} else {
rear->next = ptr;
rear = ptr;
}
printf("Node is Inserted\n\n");
}
int dequeue() {
if (front == NULL) {
printf("\nUnderflow\n");
return -1;
} else {
struct node *temp = front;
int temp_data = front->data;
front = front->next;
free(temp);
return temp_data;
}
}
void display() {
struct node *temp;
if ((front == NULL) && (rear == NULL)) {
printf("\nQueue is Empty\n");
} else {
printf("The queue is \n");
temp = front;
while (temp) {
printf("%d->", temp->data);
temp = temp->next;
}
printf("NULL\n\n");
}
}

int main() {
int choice, value;
printf("\nImplementation of Queue using Linked List\n");
while (choice != 4) {
printf("1.Enqueue\n2.Dequeue\n3.Display\n4.Exit\n");
printf("\nEnter your choice : ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\nEnter the value to insert: ");
scanf("%d", &value);
enqueue(value);
break;
case 2:
printf("Dequeued element is :%d\n", dequeue());
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\nWrong Choice\n");
}
}
return 0;
}

Output:
Enqueue: Display:

Dequeue:
Experiment-7

Write a program using linked list find sum of element on odd index number
Source code
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
};
void insert(Node** root, int item)
{
Node *ptr = *root, *temp = new Node;
temp->data = item;
temp->next = NULL;

if (*root == NULL)
*root = temp;
else {
while (ptr->next != NULL)
ptr = ptr->next;
ptr->next = temp;
}
}

void evenOdd(Node* root)


{
int odd = 0, even = 0;
Node* ptr = root;
while (ptr != NULL) {
if (ptr->data % 2 == 0)
even += ptr->data;
else
odd += ptr->data;
ptr = ptr->next;
}
cout << "Odd Sum = " << odd << endl;
}
int main()
{
Node* root = NULL;
insert(&root, 8);
insert(&root, 2);
insert(&root, 3);
insert(&root, 5);
insert(&root, 7);
evenOdd(root);
return 0;
}

Output-
Experiment-8
Write a program to print an array and size n to rotate by D either(calculate)
Source Code
#include <stdio.h>
int main()
{
int arr[] = {6, 5, 2, 8, 9};
int length = sizeof(arr)/sizeof(arr[0]);
int n = 3;
printf("Original array: \n");
for (int i = 0; i < length; i++)
{
printf("%d ", arr[i]);
}
for(int i = 0; i < n; i++)
{
int j, first;
first = arr[0];
for(j = 0; j < length-1; j++)
{
arr[j] = arr[j+1];
}
arr[j] = first;
}
printf("\n");
printf("Array after left rotation: \n");
for(int i = 0; i < length; i++)
{
printf("%d ", arr[i]);
}
return 0;
}
Output-
Experiment No-9

Write a program to print Graph Implementation


Source Code:-

#include <iostream>
using namespace std;
struct adjNode {
int val, cost;
adjNode* next;
};
struct graphEdge {
int start_ver, end_ver, weight;
};
class DiaGraph{
adjNode* getAdjListNode(int value, int weight, adjNode* head) {
adjNode* newNode = new adjNode;
newNode->val = value;
newNode->cost = weight;
newNode->next = head;
return newNode;
}
int N;
public:
adjNode **head;
DiaGraph(graphEdge edges[], int n, int N) {
head = new adjNode*[N]();
this->N = N;
for (int i = 0; i < N; ++i)
head[i] = nullptr;
for (unsigned i = 0; i < n; i++) {
int start_ver = edges[i].start_ver;
int end_ver = edges[i].end_ver;
int weight = edges[i].weight;
adjNode* newNode = getAdjListNode(end_ver, weight, head[start_ver]);
head[start_ver] = newNode;
}}
~DiaGraph() {
for (int i = 0; i < N; i++)
delete[] head[i];
delete[] head;
}};
void display_AdjList(adjNode* ptr, int i)
{
while (ptr != nullptr) {
cout << "(" << i << ", " << ptr->val
<< ", " << ptr->cost << ") ";
ptr = ptr->next;
}
cout << endl;
}
int main()
{
graphEdge edges[] = {
{0,1,2},{0,2,4},{1,4,3},{2,3,2},{3,1,4},{4,3,3}
};
int N = 6;
int n = sizeof(edges)/sizeof(edges[0]);
DiaGraph diagraph(edges, n, N);
cout<<"-----Mrinal Dev------"<<endl;
cout<<"Graph adjacency list "<<endl<<"(start_vertex, end_vertex, weight):"<<endl;
for (int i = 0; i < N; i++)
{
display_AdjList(diagraph.head[i], i);
}
return 0;
}

Output:-
Experiment No-10
Write a program to print check two string of Anagram
Source Code:-

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int checkAnagram(char *str1, char *str2);
int main()
{
char str1[100], str2[100];
printf("\n\n Function : whether two given strings are anagram :\n");
printf("\n\n Example : pears and spare, stone and tones :\n");
printf("-------------------------------------------------------\n");
printf(" Input the first String : ");
fgets(str1, sizeof str1, stdin);
printf(" Input the second String : ");
fgets(str2, sizeof str2, stdin);

if(checkAnagram(str1, str2) == 1)
{
str1[strlen(str1)-1] = '\0';
str2[strlen(str2)-1] = '\0';
printf(" %s and %s are Anagram.\n\n",str1,str2);
}
else
{
str1[strlen(str1)-1] = '\0';
str2[strlen(str2)-1] = '\0';
printf(" %s and %s are not Anagram.\n\n",str1,str2);
}
return 0;
}

//Function to check whether two passed strings are anagram or not


int checkAnagram(char *str1, char *str2)
{
int str1ChrCtr[256] = {0}, str2ChrCtr[256] = {0};
int ctr;
/* check the length of equality of Two Strings */
if(strlen(str1) != strlen(str2))
{
return 0;
}
//count frequency of characters in str1
for(ctr = 0; str1[ctr] != '\0'; ctr++)
{
str1ChrCtr[str1[ctr]]++;
}
//count frequency of characters in str2
for(ctr = 0; str2[ctr] != '\0'; ctr++)
{
str2ChrCtr[str2[ctr]]++;
}
//compare character counts of both strings
for(ctr = 0; ctr < 256; ctr++)
{
if(str1ChrCtr[ctr] != str2ChrCtr[ctr])
return 0;
}
return 1;
}
Output:-
Experiment No-11

Write a program to find Fibonacci series in Dynamic programming through


memorising
Source Code:-

#include<stdio.h>
int fib(int n)
{
int f[n+2];
int i;
f[0] = 0;
f[1] = 1;
printf("<______Mrinal Dev_______>\n\n");
for (i = 2; i <= n; i++)
{

f[i] = f[i-1] + f[i-2];


}
return f[n];
}
int main ()
{
int n = 8;
printf("%d", fib(n));
getchar();
return 0;
}

Output:-
Experiment No-12
Write a program to print longest common subsequence between two strings.
Source Code:-

#include <stdio.h>
#include <string.h>
int i, j, m, n, LCS_table[20][20];
char S1[20] = "ACADB", S2[20] = "CBDA", b[20][20];
void lcsAlgo() {
m = strlen(S1);
n = strlen(S2);
for (i = 0; i <= m; i++)
LCS_table[i][0] = 0;
for (i = 0; i <= n; i++)
LCS_table[0][i] = 0;
for (i = 1; i <= m; i++)
for (j = 1; j <= n; j++) {
if (S1[i - 1] == S2[j - 1]) {
LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1;
} else if (LCS_table[i - 1][j] >= LCS_table[i][j - 1]) {
LCS_table[i][j] = LCS_table[i - 1][j];
} else {
LCS_table[i][j] = LCS_table[i][j - 1];
}
}
int index = LCS_table[m][n];
char lcsAlgo[index + 1];
lcsAlgo[index] = '\0';
int i = m, j = n;
while (i > 0 && j > 0) {
if (S1[i - 1] == S2[j - 1]) {
lcsAlgo[index - 1] = S1[i - 1];
i--;
j--;
index--;
}
else if (LCS_table[i - 1][j] > LCS_table[i][j - 1])
i--;
else
j--;
}
printf("S1 : %s \nS2 : %s \n", S1, S2);
printf("LCS: %s", lcsAlgo);
}
int main() {
lcsAlgo();
printf("\n");
return 0;
}

Output:-
Experiment No-13
Write a program to print longest common subsequence between two string using
recursion
Source code:-

class Main {
static int lcs(String X, String Y, int m, int n) {
if (m == 0 || n == 0) {
return 0;
}
if (X.charAt(m - 1) == Y.charAt(n - 1)) {
return 1 + lcs(X, Y, m - 1, n - 1);
} else {
return Math.max(lcs(X, Y, m, n - 1),
lcs(X, Y, m - 1, n));
}
}
public static void main(String[] args) {
String X = "AGGTAB";
String Y = "GXTXAYB";
int m = X.length();
int n = Y.length();
System.out.println("Length of LCS: " + lcs(X, Y, m, n));

}
}

Output:-
Experiment: 14

Write a Program: Change Editor In G U: Check capital letter in This String

Source Code:

#include <stdio.h>
void check(char ch)
{

if (ch >= 'A' && ch <= 'Z')


printf("\n%c is an UpperCase character",ch);

else if (ch >= 'a' && ch <= 'z')


printf("\n%c is an LowerCase character",ch);

else
printf("\n%c is not an aplhabetic character",ch);
}
int main()
{
char ch;
ch = 'A';
check(ch);
ch = 'a';
check(ch);
ch = '0';
check(ch);
return 0;
}

Output:
Experiment No. 15
Write a program to find minimum no. of Coin Require to given value.

Source Code:-

class Main
{
static int minCoins(int coins[], int m, int sum)
{
if (sum == 0) return 0;

int res = Integer.MAX_VALUE;

for (int i=0; i<m; i++)


{
if (coins[i] <= sum)
{
int sub_res = minCoins(coins, m, sum-coins[i]);

if (sub_res != Integer.MAX_VALUE && sub_res + 1 < res)


res = sub_res + 1;
}
}
return res;
}
public static void main(String args[])
{
int coins[] = {1, 2, 3};
int m = coins.length;
int sum = 4;
System.out.println("Minimum coins required is "+ minCoins(coins, m, sum) );
}
}

Output:-

You might also like