Automata Old Quetions
Automata Old Quetions
Automata Old Quetions
There is a colony of 8 cells arranged in a straight line where each day every cell competes with its
adjacent cells (neighbours).
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 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 cellCompetewhich takes an 8
element array of integers cells representing the current state of 8 cells and an integer days
representing the number of days to simulate. The function should return an array representing the
state of cells after the given number of days.
An integer value of 1 represents an active cell and value of 0 represents an inactive cell.
TestCase 1:
[0. 1, 0, 0, 1, 0, 1, 0]
TestCase 2:
Input:
[1, 1, 1, 0, 1, 1, 1, 1] 2
[0. 0, 0, 0, 0, 1, 1, 0]
2) The current selected programming language is C. We emphasize the submission of a fully working
code over partially correct but efficient code. Once submitted, you cannot review this problem
again. You can use printfOto debug your code. The printrnmay not work in case of syntax/runtime
error. The version of GCC being used is 5.2.0.
The Least-Recently-Used (LRU) cache algorithm evicts 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 occurs when the requested
integer does not exist in the cache.
The input to the function IruCountMiss 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 LPL) cache
algorithm.
Assume that the array pages always has pages numbered from 1 to 50.
TestCase 1:
11
TestCase 2:
3) The current selected programming language is C. We emphasize the submission of a fully working
code over partially correct but efficient code. Once submitted, you cannot review this problem
again. You can use printf() to debug your code. The printf() may not work in case of syntax/runtime
error. The version of GCC being used is 52.0. A sequence of parentheses is called balanced if it
consists entirely of pairs of opening/closing parentheses (in that order), which is well nested. For
example, sequences "(0)()", "0" and "(()(()))" are balanced, while "(0" and "(()))(" are not.
Write a function to determine if a given string contains balanced sequence of parentheses. The input
to the function balancedParentheses is a string str. Each character in the string will be "(' or ")". The
output is the count of balanced pairs if the sequence is balanced or -1 otherwise.
TestCase 1:
Input: (())
TestCase 2:
Input:
()(
-1
4) The current selected programming language is C. We emphasize the submission of a fully working
code over partially correct but efficient code. Once submitted, you cannot review this problem
again. The version of CCC being used is 5.2.0
Given a linked list, reverse the second half of the linked list. That is, the linked list from the middle
node to the last node should get reversed.
For example, if the linked list is {2->3->6->1->4->8->9->7} then the resulting list would be 12->3->6-
>1->7->9->8->41
The input to the function reverseLinkedList shall be a pointer list to a linked list and the output shall
also be a pointer to a linked list
If there is an odd-number of elements in the list, then the middle element will be part of the portion
reversed. The middle element is the one located at position (WW2, where N is the total number of
elements in the list.
The following structure is used to represent the node of the linked list and is already implemented in
the default code (Do not write this definition again in your code):
struct Inode
int value;
);
TestCase 1:
Input:
Abc, cab
TestCase 2:
Input:
ab, aa
-1