AMCAT Automata Questions: Program To Check If Two Given Matrices Are Identical in C Language
AMCAT Automata Questions: Program To Check If Two Given Matrices Are Identical in C Language
In Java
The same program written in Java is given below:
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
package org.sb.twoMatrices;
import java.util.Scanner;
public class TwoMatricesAreEqualOrNot {
private static int size;
public static int checkMatrices(int A[][], int B[][]) {
int i = 0, j = 0;
for (i = 0; i <= size - 1; i++) {
for (j = 0; j <= size - 1; j++) {
if (A[i][j] != B[i][j])
return 0;
}
}
return 1;
}
public static void main(String[] args) {
Scanner sc = null;
int i = 0, j = 0;
int result = 0;
// create scanner object
sc = new Scanner(in);
System.out.println("Please enter the size of array::");
size = sc.nextInt();
sc.nextLine();
int A[][] = new int[size][size];
int B[][] = new int[size][size];
for (i = 0; i <= size - 1; i++) {
for (j = 0; j <= size - 1; j++) {
System.out.println("Please enter Array A[" + i + "][" + j + "] value::");
A[i][j] = sc.nextInt();
sc.nextLine();
System.out.println("Please enter Array B[" + i + "][" + j + "] value::");
B[i][j] = sc.nextInt();
sc.nextLine();
} // inner for
} // outer for
// invoke the checkMatrices method
result = checkMatrices(A, B);
if (result == 1)
System.out.println("Matrices are identical..");
else
System.out.println("Matrices are not identical..");
// close scanner
sc.close();
}// main
}// class
Input:
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
In C
#include <stdio.h>
#define R 3
#define C 6
void spiralPrint(int m, int n, int a[R][C])
{
int i, k = 0, l = 0;
/* k - starting row index
m - ending row index
l - starting column index
n - ending column index
i - iterator */
while (k < m && l < n)
{
/* Print the first row from the remaining rows */
for (i = l; i < n; ++i)
{
printf("%d ", a[k][i]);
}
k++;
/* Print the last column from the remaining columns */
for (i = k; i < m; ++i)
{
printf("%d ", a[i][n-1]);
}
n--;
/* Print the last row from the remaining rows */
if ( k < m)
{
for (i = n-1; i >= l; --i)
{
printf("%d ", a[m-1][i]);
}
m--;
}
/* Print the first column from the remaining columns */
if (l < n)
{
for (i = m-1; i >= k; --i)
{
printf("%d ", a[i][l]);
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
l++;
}
}
}
/* Driver program for the above functions */
int main()
{
int a[R][C] = { {1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18}
};
spiralPrint(R, C, a);
return 0;
Output:
1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
Using Temp
#include <stdio.h>
#include <stdlib.h>
#define COL 4
#define ROW 4
int main() {
int arr[ROW][COL] = {
{1, 1, 1, 1},
{1, 1, 0, 0},
{1, 0, 0, 0},
{1, 1, 0, 0},
};
int rownum;
int i = 0, j = 0, temp, count = 0;
temp = count;
for (i = 0; i < 4; i++) {
count = 0;
for (j = 0; j < 4; j++) {
if (arr[i][j] == 0) {
count++;
}
if (count > temp) {
temp = count;
rownum = i;
}
}
}
printf("%d", rownum);
return 0;
}
This is because, 32 + 42 = 52 .
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
1) The simple way is to generate triplets smaller than t given limit and check if it
meets the given condition every time. If the condition is true, print the triplets. Even
though this method is simple, this is not effective as the code will be long for larger
limits.
2) The effective way to solve is problem is by using the variables m and n instead of
a, b and c by using the following relation:
a = m 2 - n2
b=2*m*n
c = m2 + n2 because,
a2 = m4 + n4 – 2 * m2 * n2
b2 = 4 * m2 * n2
c2 = m4 + n4 + 2* m2 * n2
In C
The above method is written in C program as given below:
}
// Driver program
int main()
{
int limit = 20;
pythagoreanTriplets(limit);
return 0;
}
In Java
public class Amcat2 {
public static void main(String[] args) {
Scanner sc = new Scanner(in);
int n = sc.nextInt();
int[] arrivingTime = new int[n];
int[] burstTime = new int[n];
int timeQuant;
int[] ans;
for(int i = 0; i < n; i++){
arrivingTime[i] = sc.nextInt();
}
for(int i = 0; i < n; i++)
burstTime[i] = sc.nextInt();
timeQuant = sc.nextInt();
ans = waitingTime(n, arrivingTime, burstTime, timeQuant);
for(int i = 0; i < n; i++)
out.print(ans[i] + " ");
out.println();
}
private static int[] waitingTime(int n, int[] a, int[] b, int q) {
int[] result = new int[n];
int[] processNo = new int[n];
for(int i = 0; i < n; i++)
processNo[i] = i;
b = sort(a,b,processNo);
sort(a);
int max = b[0];
int index = 0;
for(int i = 1; i < n; i++)
if(max < b[i]){
max = b[i];
index = i;
}
int[] c = new int[n];
int time = 0;
for(int i = 0; i < n; i++){
c[i] = b[i];
out.println(a[i] + " " + b[i]);
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
}
//System.out.println("max : " + max);
while(b[index] != 0){
for(int i = 0; i < n; i++){
if(b[i] == 0)
continue;
if(b[i] >= q){
b[i] -= q;
time += q;
if(b[i] == 0)
result[i] = time - a[i] - c[i];
}else{
time += q - b[i];
b[i] = 0;
result[i] = time - a[i] - c[i];
}
}
}
int temp;
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
if(processNo[i] < processNo[j]){
temp = result[i];
result[i] = result[j];
result[j] = temp;
}
}
}
return result;
}
private static int[] sort(int[] a, int[] b, int[] processNo) {
int temp;
for(int i = 1; i < a.length; i++){
for(int j = 0; j < i; j++){
if(a[i] < a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
temp = b[i];
b[i] = b[j];
b[j] = temp;
temp = processNo[i];
processNo[i] = processNo[j];
processNo[j] = temp;
}
}
}
return b;
}
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
In C++
#include<iostream>
#include<climits>
using namespace std;
int maxSubArraySum(int a[], int size)
{
int max_so_far = INT_MIN, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
/*Driver program to test maxSubArraySum*/
int main()
{
int a[] = {-2, -3, 4, -1, -2, 1, 5, -3};
int n = sizeof(a)/sizeof(a[0]);
int max_sum = maxSubArraySum(a, n);
cout << “Maximum contiguous sum is ” << max_sum;
return 0;
}
The simple way to solve this is to compare two adjacent numbers in an array and
swap their position if the second number is greater than the first. Continue this until
the output is obtained.
In C:
#include <stdio.h>
void swap(int *, int *);
void bubble(int[], int);
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
printf("Enter %d Element\n", i);
scanf("%d", &arr[i]);
}
printf("Array before sorting\n");
for (int i = 0; i < n; i++)
{
printf("%d\t", arr[i]);
}
bubble(arr, n);
printf("\nArray after sorting\n");
for (int i = 0; i < n; i++) {
printf("%d\t", arr[i]);
}
printf("\n");
return 0;
}
void bubble(int a[], int n) {
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
if (a[j] > a[j + 1]) {
swap(&a[j], &a[j + 1]);
}
}
}
}
void swap(int *a, int *b)
{
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
In Java
package arrayProject;
import java.util.*;
import java.math.*;
public class GCDPhrSe
{
public static int gcd(int n1,int n2)
{
if(n1==0)
return n2;
if(n2==0)
return n1;
if(n1>n2)
return gcd(n1-n2,n2);
else
return gcd(n2-n1,n1);
}
public static void main(String args[])
{
Scanner sc=new Scanner(in);
int n1,n2;
System.out.println("Enter two no");
n1=sc.nextInt();
n2=sc.nextInt();
int n3=gcd(n1,n2);
System.out.println(n3);
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
}
}
In C Using Pointers
#include < stdio.h >
#include < stdlib.h >
#include < string.h >
#define TRUE 1
# define FALSE 0
int check_vowel(char);
main() {
char string[100], * temp, * pointer, ch, * start;
printf(“Enter a string\n”);
gets(string);
temp = string;
pointer = (char * ) malloc(100);
if (pointer == NULL) {
printf(“Unable to allocate memory.\n”);
exit(EXIT_FAILURE);
}
start = pointer;
while ( * temp) {
ch = * temp;
if (!check_vowel(ch)) { * pointer = ch;
pointer++;
}
temp++;
} * pointer = ‘\0’;
pointer = start;
strcpy(string, pointer); /* If you wish to convert original string */
free(pointer);
printf(“String after removing vowel is \”%s\”\n”, string);
return 0;
}
int check_vowel(char a) {
if (a >= ‘A’ && a <= ‘Z’) a = a + ‘a’ – ‘A’;
if (a == ‘a’ || a == ‘e’ || a == ‘i’ || a == ‘o’ || a == ‘u’) return TRUE;
return FALSE;
}
#include <stdio.h>
#include <string.h>
int check_vowel(char);
int main()
{
char s[100], t[100];
int i, j = 0;
printf("Enter a string to delete vowels\n");
gets(s);
for(i = 0; s[i] != '\0'; i++) {
if(check_vowel(s[i]) == 0) { //not a vowel
t[j] = s[i];
j++;
}
}
t[j] = '\0';
strcpy(s, t); //We are changing initial string
printf("String after deleting vowels: %s\n", s);
return 0;
}
int check_vowel(char c)
{
switch(c) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
return 1;
default:
return 0;
}
}
{
// Concatenate two arrays
int i = 0, j = 0, k = 0;
while (i < n)
{
res[k] = a[i];
i += 1;
k += 1;
}
while (j < m) {
res[k] = b[j];
j += 1;
k += 1;
}
// sorting the res array
sort(res, res + n + m);
}
// Driver code
int main()
{
int a[] = { 10, 5, 15 };
int b[] = { 20, 3, 2, 12 };
int n = sizeof(a) / sizeof(a[0]);
int m = sizeof(b) / sizeof(b[0]);
// Final merge list
int res[n + m];
sortedMerge(a, b, res, n, m);
cout << “Sorted merged list :”;
for (int i = 0; i < n + m; i++)
cout << ” ” << res[i];
cout << “n”;
return 0;
}
In Java
public class SortedArray {
public static void main(String[] args) {
int a[]= {8,7,9};
int b[]= {10,5};
sort(a,b);
}
public static void sort(int[] a,int[] b) {
int[] c= new int[a.length+b.length];
for (int i = 0; i < a.length; i++) {
c[i]=a[i];
}
for (int i = 0, j=a.length; i < b.length; i++,j++) {
c[j]=b[i];
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
}
for (int i = 0; i < c.length; i++) {
for (int j = i+1; j < c.length; j++) {
if(c[i]>c[j]) {
int temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
out.print("Sorted Array : ");
for (int i = 0; i < c.length; i++) {
System.out.print(c[i]+" ");
}
}
}
1) Using + and -
#include<stdio.h>
intmain()
{
inta=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return0;
}
2) Using * and /
#include<stdio.h>
#include<stdlib.h>
intmain()
{
inta=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a*b;//a=200 (10*20)
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
b=a/b;//b=10 (200/20)
a=a/b;//a=20 (200/10)
system("cls");
printf("\nAfter swap a=%d b=%d",a,b);
return0;
}
2) Divide the input integer by 10, obtain its remainder and quotient.
4) Repeat the step 2 & 3 with the quotient obtained until the quotient becomes zero.
In C
/*C program to accept an integer & find the sum of its digits*/
#include <stdio.h>
void main()
{
long num, temp, digit, sum = 0;
printf("Enter the number \n");
scanf("%ld", &num);
temp = num;
while (num > 0)
{
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
task hast to run when, and how to break them up, called
“scheduling”. The Round-Robin policy for scheduling
runs each job for a fixed amount of time before switching
to the next job. The waiting time for a job is the total time
that it spends waiting to be run. Each job arrives at
particular time for scheduling and certain time to run,
when a new job arrives, It is scheduled after existing
jobs already waiting for CPU time
Given list of job submission, calculate the average
waiting time for all jobs using Round-Robin policy.
The input to the function waitingTimeRobin consist of
two integer arrays containing job arrival and run times,
an integer n representing number of jobs and am integer
q representing the fixed amount of time used by Round-
Robin policy. The list of job arrival time and run time
sorted in ascending order by arrival time. For jobs
arriving at same time, process them in the order they are
found in the arrival array. You can assume that jobs
arrive in such a way that CPU is never idle.
The function should return floating point value for the
average waiting time which is calculated using round
robin policy.
Assume 0<=jobs arrival time < 100 and 0<job run time
<100.
In C
#include<stdio.h>
int waitingtimerobin(int *job,int *run,int n,int tq)
{
int j,count,time,remain,flag=0;
int wait_time=0,turnaround_time=0,rt[10];
remain=n;
for(count=0;count<n;c++)
{
rt[count]=run[count];
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=tq && rt[count]>0)
{
time += rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count] -= time_quantum;
time += time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
wait_time += time-job[count]-run[count];
flag=0;
}
if(count==n-1)
count=0;
else if(job[count+1]<=time)
count++;
else
count=0;
}
printf("waiting time %f",wait_time*1.0/n);
return 0;
}
int main()
{
int ja[],at[];
int n,tq;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d", &ja[i],&at[i]);
}
scanf("%d",&tq);
int *cellsptr=ja;
int *cellsptr1=at;
waitingtimerobin(cellsptr,cellsptr1,n,tq);
return 0;
}
Test case 2:
Input:
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
[[0,0,0],[9,1,1],[0,1,1]]
Expected return value:0
Explanation:
Mooshak cannot move anywhere as there exists a wall
right on (0,0)
In C
Int isPath(int **grid,int m,int n)
{
if (x,y outside maze) return false
if (x,y is goal) return true
if (x,y not open) return false
mark x,y as part of solution path
if (FIND-PATH(North of x,y) == true) return true
if (FIND-PATH(East of x,y) == true) return true
if (FIND-PATH(South of x,y) == true) return true
if (FIND-PATH(West of x,y) == true) return true
unmark x,y as part of solution path
return false*/
public boolean findPath(int x, int y){
// check x,y are outside maze.
if(x < 0 || x >= mazelength || y < 0 || y >= mazelength )
{
return false;
}
if(maze[x][y] == 9)
{
return true;
}
if(maze[x][y] != 1) return false; //mark x, y as part of the solution path
if(maze[x][y] == 1)
{
maze[x][y] = 3;
}
// move North
if( findPath(x-1,y)){
return true;
}
//move East
if( findPath(x,y+1)) return true;
//move South
if( findPath(x+1,y)) return true;
//move West
if( findPath(x,y-1)) return true;
// unMark x,y as part of the solution.
{
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
maze[x][y] = 0;
return false;
}
public void printSolution(){
out.println("Final Solution : ");
for(int i=0;i<mazelength;i++){
for(int j=0;j<mazelength;j++){
out.print(" "+maze[i][j]+" ");
}
out.println();
}
}
public static void main(String args[])
{
RatMazeProblem ratMazeProblem = new RatMazeProblem();
out.println(" is Path exist : "+ratMazeProblem.findPath(0,0));
printSolution();
}
}
}
Test Case 1:
INPUT: 3,[7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0],16
EXPECTED RETURN VALUE: 11
Test Case 2:
INPUT: 2,[2,3,1,3,2,1,4,3,2],9
EXPECTED RETURN VALUE: 8
In C
#include<iostream>
using namespace std;
int lruCountMiss(int max_cache_size, int *pages,int len)
{
int miss=0,cache[max_cache_size];
/*variable miss and cache declared*/
for (int i=0;i<max_cache_size;i++)
{
/*this is for clearing value of cache i.e. to empty cache. I used any value here*/
cache[i]=0x87787;
}
for (int i=0;i<len;i++)
{
/*for loop for all the value from list one by one*/
for(int j=0;j<max_cache_size;j++)
{
/*loop to check the cache value, if it matches the value*/
if (pages[i]==cache[j]){ for (int k=i; k<max_cache_size;k++)
{
/*if the value is already present in the cache then shifting values from the present
value.*/
cache[i]=cache[i+1];
}
cache[max_cache_size-1]=pages[i];
/*updating the last value of cache*/
break;
}
else if(j==(max_cache_size-1))
{
for (int l=0; l<max_cache_size;l++)
{
/*if the value is not present in the cache then shifting values from starting.*/
cache[l]=cache[l+1];
}
cache[max_cache_size-1]=pages[i];
/*updating the last value of cache*/
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
{
//WRITE YOUR CODE HERE
}
//FUNCTION SIGNATURE ENDS
Test Case 1:
Input: [3->4->6->1->2->^],5
Expected Return Value: [5->6->1->2->3->4->^]
Test Case 2:
Input: [1->2->3->4->5->^],0
Expected Return Value: [0->1->2->3->4->5->^]
Algorithm:
Allocate memory for the newly inserted node and put data in it. Let the pointer to the
new node be new_node. After memory allocation, following three cases needs to be
handled.
new_node->next = new_node;
*head_ref = new_node;
while(current->next != *head_ref)
current = current->next;
current->next = new_node;
new_node->next = *head_ref;
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
*head_ref = new_node;
{ current = current->next; }
new_node->next = current->next;
current->next = new_node;
In C
#include<stdio.h>
#include<stdlib.h>
/* structure for a node */
struct Node
{
int data;
struct Node *next;
};
/* function to insert a new_node in a list in sorted way.
Note that this function expects a pointer to head node
as this can modify the head of the input linked list */
void sortedInsert(struct Node** head_ref, struct Node* new_node)
{
struct Node* current = *head_ref;
// Case 1 of the above algo
if (current == NULL)
{
new_node->next = new_node;
*head_ref = new_node;
}
// Case 2 of the above algo
else if (current->data >= new_node->data)
{
/* If value is smaller than head's value then
we need to change next of last node */
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
while(current->next != *head_ref)
current = current->next;
current->next = new_node;
new_node->next = *head_ref;
*head_ref = new_node;
}
// Case 3 of the above algo
else
{
/* Locate the node before the point of insertion */
while (current->next!= *head_ref &&
current->next->data < new_node->data)
current = current->next;
new_node->next = current->next;
current->next = new_node;
}
}
/* Function to print nodes in a given linked list */
void printList(struct Node *start)
{
struct Node *temp;
if(start != NULL)
{
temp = start;
printf("\n");
do {
printf("%d ", temp->data);
temp = temp->next;
} while(temp != start);
}
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 56, 2, 11, 1, 90};
int list_size, i;
/* start with empty linked list */
struct Node *start = NULL;
struct Node *temp;
/* Create linked list from the array arr[].
Created linked list will be 1->2->11->12->56->90 */
for (i = 0; i< 6; i++)
{
temp = (struct Node *)malloc(sizeof(struct Node));
temp->data = arr[i];
sortedInsert(&start, temp);
}
printList(start);
return 0;
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
These are the most commonly asked AMCAT Automata questions with their
answers. Even if the candidate can’t derive an output for the question, it is advisable
to try to write the code as much as he can. This is because, even partial answers
and getting input carries marks.
Q1. There is a colony of 8 cells arranged in a straight line where each day every cell competes
with its adjacent cells (neighbour). Each day, for each cell, if its neighbours are both active and
both inactive, the cell becomes inactive the next day, otherwise it becomes active the next day.
Assumptions: The two cells on the ends have single adjacent cell, so the other adjacent cell
can be assumed to be always inactive.
Even after updating the cell state. Consider its previous state for updating the state of other cells.
Update the cell information of all cells simultaneously.
Write a function cell Compete which takes one 8 element array of integer’s cells representing the
current state of 8 cells and one integer days representing the number of days to simulate.
An integer value of 1 represents an active cell and value of 0 represents an inactive cell.
Existing Program
{/
Test Cases
TESTCASES 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]
TESTCASE 2:
INPUT:
[1,1,1,0,1,1,1,1,],2
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]
Solution:
#include<iostream>
cells[-1]=0; //assumptions
cells[8]=0;//assumptions
u[i]=cells[i];
for(int j=0;j<8;j++){
else
cells[j]=1;
}}
cout<<cells[i];
return 0;}
cin>>days;
cout<<"n[1,0,0,0,0,1,0,0]n";
return 0;
Q2. Mooshak the mouse has been placed in a maze. There is a huge chunk of cheese
somewhere in the maze. The maze is represented as a two-dimensional array of integers, where
0 represents walls.1 represents paths where Mooshak can move and 9 represents the huge
chunk of cheese.
EX: 8 by 8(8*8) matrix maze where Mooshak can get the cheese.
10111001
10001111
10000000
10109011
11101001
10101101
10000101
11111111
Test Cases:
Case 1:
Input:[[1,1,1,][9,1,1],[0,1,0]]
Expected return value :1
Explanation:
The piece of cheese is placed at(1,0) on the grid Mooshak can move from (0,0) to (1,0) to reach
it or can move from (0,0) to (0,1) to (1,1) to (1,0)
Test case 2:
Input: [[0,0,0],[9,1,1],[0,1,1]]
Expected return value: 0
Explanation:
Mooshak cannot move anywhere as there exists a wall right on (0,0)
Existing Program
{/*
*/}
Solution:
return false*/
return false;
if(maze[x][y] == 9) {
return true;
if(maze[x][y] == 1){
maze[x][y] = 3;
// move North
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
if( findPath(x-1,y)){
return true;
//move East
//move South
//move West
maze[x][y] = 0;
return false;
for(int i=0;i<mazelength;i++){
for(int j=0;j<mazelength;j++){
System.out.println();
ratMazeProblem.printSolution();
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
Q1. The least recently used (LRU) cache algorithm exists the element from the
cache(when it’s full) that was least recently used. After an element is requested from
the cache, it should be added to the cache (if not already there) and considered the
most recently used element in the cache.
Initially, the cache is empty. The input to the function LruCountMiss shall consist of
an integer max_cache_size, an array pages and its length Len
The function should return an integer for the number of cache misses using the LRU
cache algorithm.
Assume that the array pages always have pages numbered from 1 to 50.
TEST CASES:
TEST CASE1:
INPUT:
3,[7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0],16
TESTCASE 2:
INPUT:
2,[2,3,1,3,2,1,4,3,2],9
EXPLANATION:
The following page numbers are missed one after the other 2,3,1,2,1,4,3,2.This
results in 8 page misses.
Existing Program
{/
}
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
Solved Program
#include<iostream>
/*this is for clearing value of cache i.e. to empty cache. I used any value here*/
cache[i]=0x87787;
for (int i=0;i<len;i++){ /*for loop for all the value from list one by one*/
for(int j=0;j<max_cache_size;j++){
if (pages[i]==cache[j]){
/*if the value is already present in the cache then shifting values from the present
value.*/
cache[i]=cache[i+1];
break;
else if(j==(max_cache_size-1)){
/*if the value is not present in the cache then shifting values from starting.*/
cache[l]=cache[l+1];
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
cache[max_cache_size-1]=pages[i];
miss++;
}}
int days,pages[]={7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0};
int *cellsptr=pages;
int pages2[]={2,3,1,3,2,1,4,3,2};
int *cellsptr2=pages2;
return 0;
Write a function to insert an integer into a circular linked _list whose elements are
sorted in ascending order 9smallest to largest). The input to the function insert
JOIN PLACEMENT FELLAS ON TELEGRAM (CLICK HERE)
Sorted List is a pointer start to some node in the circular list and an integer n
between 0 and 100. Return a pointer to the newly inserted node...
Int value;
Cnode* next;
};C
node* insertSortedList (cnode* start,int n
{/
/WRITE YOUR CODE HERE
}/
/FUNCTION SIGNATURE ENDS
Test Case 1:
Input:
[3>4>6>1>2>^],5
Expected Return Value:
[5>6>1>2>3>4>^]
Test Case 2:
Input:
[1>2>3>4>5>^],0
Expected Return Value:
[0>1>2>3>4>5>^]
Given the maximum size of the cache and a list of integers (to request from the
cache), calculate the number of cache misses using the LRU cache algorithm. A
cache miss occur when the requested integer does not exist in the cache.