Thursday 6 October 2016

Amcat Automata Paper II

AMCAT-Q1 : 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

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



AMCAT-Q2 : 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 itbecomes 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 pervious state for updating the state of other cells. Update the cell informationof allcells simultaneously.

Write a fuction cellCompete 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

Test Case 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]

Test Case 2:
INPUT:
[1,1,1,0,1,1,1,1,],2
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]

No comments:

Post a Comment