**1)**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 or 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 assumsed 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 takes one 8
element array of integers cells representing the current state of 8 cells and
one integer days representing te number of days to simulate.

An integer value of 1 represents an active cell and value
of 0 represents an inactive cell.

**Program:**

int* cellCompete(int* cells,int days)

{

//write your code here

}

//function signature ends

**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]

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 repersents paths where mooshak can move and 9 represents the huge chunk of cheese.

```
#include<iostream>
using namespace std;
```

int cellCompete(int *cells ,int day){ //write your code here for (int i=0;i<day;i++){ cells[-1]=0; //assumptions cells[8]=0;//assumptions int u[8]; //another array to copy value for (int i=-1;i<9;i++){ u[i]=cells[i]; } for(int j=0;j<8;j++){ if(u[j-1]==u[j+1]){ //comparing the value of the neighbouring cells of u[] cells[j]=0; //changing value of cell according to condition } else cells[j]=1; } } for (int i=0;i<8;i++){ cout<<cells[i]; } return 0;} int main(){ //main function int days,cells[]={1,0,0,0,0,1,0,0}; //array to pass through function int *cellsptr=cells; //creating array values to pointer cout<<"enter days:"; //for days cin>>days; cout<<"n[1,0,0,0,0,1,0,0]n"; cellCompete(cellsptr, days); //passing to function return 0; }

**2)****Problem:**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 repersents paths where mooshak can move and 9 represents the huge chunk of cheese.

Mooshak starts in the top left corner at 0.

Write a method is Path of class Maze Path to determine if Mooshak can reach the huge chunk of cheese. The input to is Path consists of a two dimensional array gnd for the maze matrix. the method should return 1 if there is a path from Mooshak to the cheese.and 0 if not Mooshak is not allowed to leave the maze or climb on walls.

Write a method is Path of class Maze Path to determine if Mooshak can reach the huge chunk of cheese. The input to is Path consists of a two dimensional array gnd for the maze matrix. the method should return 1 if there is a path from Mooshak to the cheese.and 0 if not Mooshak is not allowed to leave the maze or climb on walls.

EX: 8 by 8(8*8) matrix maze where Mooshak can get the cheese. 1 0 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 0 9 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1

**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)

**Code format:**(C Language)

//include header files needed by your program // some library functionality may be restricted // define any function needed // function signature begins, this function is required Int isPath(int **grid,int m,int n) {/ / write your code here }/ /function signature ends

**Java Code format:**

//import libray's packages needed by your program // some classes with in a package may be restricted //define any class and method needed //class begins ,this class is required Public class MazePath { Public static int isPath(int[][] grid) // insert your code here }/ / method signature ends }

**In Java Program Code:**

Int isPath(int **grid,int m,int n) { Return SolveMazeUtil(grid,0,0,m,n); }I nt SolveMazeUtil(int **grid,x,y,m,n) { If(x>=0 && x < m && y>=0 && y<n) { if(grid[x][y]==9)) { return 1; } // Check if maze[x][y] is valid if(grid[x][y] == 1) { /* Move forward in x direction */ if (solveMazeUtil(grid, x+1, y, m,n) == 1) return 1; /* If moving in x direction doesn't give solution then Move down in y direction */ if (solveMazeUtil(grid, x, y+1, m,n) == 1) return 1; /* If none of the above movements work then BACKTRACK: unmark x,y as part of solution path */ return 0; } return 0; } return 0; }

**3)**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.

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.

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 has pages numbered
from 1 to 50.

**TESTCASES:**

**TESTCASE1:**

**INPUT:**

**3,[7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0],16**

**EXPECTED RETURN VALUE:**

**11**

**TESTCASE 2:**

**INPUT:**

**2,[2,3,1,3,2,1,4,3,2],9**

**EXPECTED RETURN VALUE:**

**8**

**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.

**CODE:**

int lruCountMiss(int max_cache_size, int *pages,int len)

{

//write tour code

}

**3)**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 insertSortedList 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.

The structure to follow for a node of the circular linked
list is_

Struct CNode ;

Typedef struct CNode cnode;

Struct CNode

{

Int value;

Cnode* next;

};

Cnode* insertSortedList (cnode* start,int n

{

//WRITE YOUR CODE HERE

}

//FUNCTION SIGNATURE ENDS

TestCase 1:

Input:

[3->4->6->1->2->^],5

Expected Return Value:

[5->6->1->2->3->4->^]

TestCase 2:

Input:

[1->2->3->4->5->^],0

Expected Return Value:

[0->1->2->3->4->5->^]

Cnode* insertSortedList (cnode* start,int n)

{

int count=1,i,count1=0;

Cnode* temp=start;

Cnode* temp1=start;

Cnode* temp2=start;

Cnode* newHead=NULL;

while(temp!=NULL)

{

temp=temp->next;

count ++;

}

int arr[count];

while(temp2!=NULL)

{

for(j=0;j<count;j++)

{

arr[j]=temp->data;

temp2=temp2->next;

}

}

while(n>=temp2->value)

{

temp2=temp2->next;

}

newHead=temp2;

for(i=0;i<count;i++)

{

Cnode* newNode=new Cnode();

newNode->data=arr[i];

newNode->next=NULL;

}

}

**Solution :**Cnode* insertSortedList (cnode* start,int n)

{

int count=1,i,count1=0;

Cnode* temp=start;

Cnode* temp1=start;

Cnode* temp2=start;

Cnode* newHead=NULL;

while(temp!=NULL)

{

temp=temp->next;

count ++;

}

int arr[count];

while(temp2!=NULL)

{

for(j=0;j<count;j++)

{

arr[j]=temp->data;

temp2=temp2->next;

}

}

while(n>=temp2->value)

{

temp2=temp2->next;

}

newHead=temp2;

for(i=0;i<count;i++)

{

Cnode* newNode=new Cnode();

newNode->data=arr[i];

newNode->next=NULL;

}

}

**4)**A system that can run multiple concurrent jobs on a single CPU have a process of choosing which 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 fora 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.

5)

**Problem:**
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-dimentional array of
integers, where 0 represents walls.1
repersents paths where mooshak can move and 9 represents the huge chunk of
cheese. Mooshak starts in the top-left corner at 0.0

Write a method isPath of class MazePath to determine if
Mooshak can reach the huge chunk of cheese. The input to isPath consists of a two- dimentional array gnd for
the maze matrix. the method should
return 1 if there is a path from Mooshak to the cheese.and 0 if not Mooshak is
not allowed to leave the maze or climb on walls.

EX:8 by 8(8*8)
matrix maze where Mooshak can get the cheese.

1 0 1 1 1 0 0 1

1 0 0 0 1 1 1 1

1 0 0 0 0 0 0 0

1 0 1 0 9 0 1 1

1 1 1 0 1 0 0 1

1 0 1 0 1 1 0 1

1 0 0 0 0 1 0 1

1 1 1 1 1 1 1 1

**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)

**Code**:

(C Language)

//include header files needed by your program

// some libray functionality may be restricted

// define any function needed

// function signature begins, this function is required

Int isPath(int **grid,int m,int n)

{

// write your code here

}

//function signature ends

Java Code:

//import librays packages needed by your program

// some clases with in a package may be restricted

//define any class and method needed

//class begins ,this class is required

Public class MazePath

{

Public static int
isPath(int[][] grid)

// insert your code here

}

// method signature ends

}

Program :

Int isPath(int **grid,int m,int n)

{

Return SolveMazeUtil(grid,0,0,m,n);

}

Int SolveMazeUtil(int **grid,x,y,m,n)

{

If(x>=0
&& x < m && y>=0 && y<n)

{

if(grid[x][y]==9))

{

return 1;

}

//
Check if maze[x][y] is valid

if(grid[x][y]
== 1)

{

/* Move forward in x direction */

if (solveMazeUtil(grid, x+1, y, m,n) == 1)

return
1;

/* If moving in x direction doesn't give solution
then

Move down in y direction
*/

if (solveMazeUtil(grid, x, y+1, m,n) == 1)

return
1;

/* If
none of the above movements work then BACKTRACK:

unmark x,y as part of solution
path */

return
0;

}

return
0;

}

return
0;

}

**6)**Matching parenthesis