0% found this document useful (0 votes)
183 views

Amcat Coding

This document contains 27 multiple choice questions about programming concepts like data types, operators, loops, and patterns. The questions cover topics like minimum number of bits required to store different data types, output of arithmetic operations on integers, correcting errors in loop programs, and using loops to print patterns. Each question is followed by 4 answer options and the correct option is provided. The questions help assess understanding of fundamental programming and problem solving concepts.

Uploaded by

Mahesh Babu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

Amcat Coding

This document contains 27 multiple choice questions about programming concepts like data types, operators, loops, and patterns. The questions cover topics like minimum number of bits required to store different data types, output of arithmetic operations on integers, correcting errors in loop programs, and using loops to print patterns. Each question is followed by 4 answer options and the correct option is provided. The questions help assess understanding of fundamental programming and problem solving concepts.

Uploaded by

Mahesh Babu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Amcat Study Material

1
Automata and Programming
Question 0:-
There is a new data-type which can take as values natural numbers between
(and including) 0 and 25. How many minimum bits are required to store this
datatype.

Op 1: 4

Op 2: 5

Op 3: 1

Op 4: 3

Correct Op : 2

Question 1:-
A data type is stored as an 6 bit signed integer.Which of the following cannot
be represented by this data type?

Op 1: -12

Op 2: 0

Op 3: 32
Op 4: 18

Correct Op : 3

Question 3:-
A language has 28 different letters in total. Each word in the language is composed
of maximum 7 letters. You want to create a data-type to store a word of this
language. You decide to store the word as an array of letters. How many bits will
you assign to the data-type to be able to store all kinds of words of the language.

Op 1: 7

Op 2: 35

Op 3: 28

Op 4: 196

Correct Op : 2

2
Question 4:-
A 10-bit unsigned integer has the following range:

Op 1: 0 to 1000

Op 2: 0 to 1024

Op 3: 1 to 1025

Op 4: 0 to 1023

Correct Op : 4

Question 5:-
Rajni wants to create a data-type for the number of books in her book case. Her
shelf can accommodate a maximum of 75 books. She allocates 7 bits to the
datatype. Later another shelf is added to her book-case. She realizes that she
can still use the same data-type for storing the number of books in her book-
case. What is the maximum possible capacity of her new added shelf?

Op 1: 52

Op 2: 127

Op 3: 53

Op 4: 75
Correct Op : 1

Question 6:-
A new language has 15 possible letters, 8 different kinds of punctuation marks and
a blank character. Rahul wants to create two data types, first one which could sto-
re the letters of the language and a second one which could store any character in
the language.The numberof bits required to store these two data-types will
respectively be:

Op 1: 3 and 4

Op 2: 4 and 3

Op 3: 4 and 5

Op 4: 3 and 5

Correct Op : 3

3
Question 7:-
Parul takes as input two numbers: a and b. a and b can take integer values betwe-
en 0 and 255. She stores a, b and c as 1byte data type. She writes the following co-
de statement to process a and b and put the result in c.

c = a + 2*b

To her surprise her program gives the right output with some input values of a and
b, while gives an erroneous answer for others. For which of the following inputs
will it give a wrong answer?

Op 1: a = 10 b = 200

Op 2: a = 200 b = 10

Op 3: a = 50 b = 100

Op 4: a = 100 b = 50

Correct Op : 1

Question 8:-
Prashant takes as input 2 integer numbers, a and b, whose value can be between 0
and 127. He stores them as 7 bit numbers. He writes the following code to process
these numbers to produce a third number c.

c=a-b
In how many minimum bits should Prashant store c?

Op 1: 6 bits

Op 2: 7 bits

Op 3: 8 bits

Op 4: 9 bits

Correct Op : 3

Question 9:-
Ankita takes as input 2 integer numbers, a and b, whose value can be between 0 a
nd 31. He stores them as 5 bit numbers. He writes the following code to process th
ese numbers to produce a third number c.

c = 2*(a - b)

In how many minimum bits should Ankita store c?

4
Op 1: 6 bits

Op 2: 7 bits

Op 3: 8 bits

Op 4: 9 bits

Correct Op : 2

Question 10:-
A character in new programming language is stored in 2 bytes. A string is represen-
ted as an array of characters. A word is stored as a string. Each byte in the memory
has an address. The word "Mahatma Gandhi" is stored in the memory with starti-
ng address 456. The letter 'd' will be at which memory address?

Op 1: 468

Op 2: 480

Op 3: 478

Op 4: 467

Correct Op : 3

Question 11:-
Stuti is making a questionnaire of True-false questions. She wants to define a data-
type which stores the response of the candidate for the question. What is the
most-suited data type for this purpose?

Op 1: integer

Op 2: boolean

Op 3: float

Op 4: character

Correct Op : 2

Question 12:-
What will be the output of the following pseudo-code statements:

integer a = 456, b, c, d =10

b = a/d

c=a-b

5
print c

Op 1: 410

Op 2: 410.4

Op 3: 411.4

Op 4: 411

Correct Op : 4

Question 13:-
What will be the output of the following pseudo-code statements:

integer a = 984, b, c, d =10

print remainder(a,d) // remainder when a is divided by d

a = a/d

print remainder(a,d) // remainder when a is divided by d

Op 1: 48

Op 2: Error

Op 3: 84
Op 4: 44

Correct Op : 1

Question 14:-
What will be the output of the following code statements?

integer a = 50, b = 25, c = 0

print ( a > 45 OR b > 50 AND c > 10 )

Op 1: 1

Op 2: 0

Op 3: -1

Op 4: 10

Correct Op : 1

Question 15:-
What will be the output of the following code statements?

6
integer a = 50, b = 25, c = 5

print a * b / c + c

Op 1: 120

Op 2: 125

Op 3: 255

Op 4: 250

Correct Op : 3

Question 16:-
What will be the output of the following code statements?

integer a = 10, b = 35, c = 5

print a * b / c - c

Op 1: 65

Op 2: 60

Op 3: Error
Op 4: 70

Correct Op : 1

Question 17:-
integer a = 10, b = 35, c = 5

Comment about the output of the two statements?

print a * b + c / d

print c / d + a * b

Op 1: Differ due to left-to-right precedence

Op 2: Differ by 10

Op 3: Differ by 20

Op 4: Same

Correct Op : 4

Question 18:-
integer a = 40, b = 35, c = 20, d = 10

7
Comment about the output of the following two statements:

print a * b / c - d

print a * b / (c - d)

Op 1: Differ by 80

Op 2: Same

Op 3: Differ by 50

Op 4: Differ by 160

Correct Op : 1

Question 19:-
What will be the output of the following code statements?

integer a = 10, b = 35, c = 5

print a * b / c - c
Op 1: 65

Op 2: 60

Op 3: Error

Op 4: 70

Correct Op : 1

Question 20:-
integer a = 60, b = 35, c = -30

What will be the output of the following two statements:

print ( a > 45 OR b > 50 AND c > 10 )

print ( ( a > 45 OR b > 50 ) AND c > 10 )

Op 1: 0 and 1

Op 1: No error, the program is correct.

Op 2: Statement 1

Op 3: Statement 4

Op 4: statement 6

8
Correct Op : 3

Question 21:-
Shashi wants to make a program to print the sum of the first 10 multiples
of 5.She writes the following program, where statement 5 is missing:

integer i = 0

integer sum = 0

while ( i <= 50 )

sum = sum + i

-- MISSING STATEMENT 5 --

}
print sum

Which of the following will you use for statement 5?

Op 1: i = 5

Op 2: i = 5 * i

Op 3: i = i + 1

Op 4: i = i + 5

Correct Op : 4

Question 22:-
Shantanu wants to make a program to print the sum of the first 7 multiples of 6.
He writes the following program:

integer i = 0 // statement 1

integer sum // statement 2

while ( i <= 42 ) // statement 3

sum = sum + i // statement 4

i = i + 6;

9
}

print sum // statement 6

Does this program have an error? If yes, which one statement will you modify to

correct the program?

Op 1: Statement 1

Op 2: Statement 2

Op 3: Statement 3

Op 4: Statement 4

Correct Op : 2

Question 23:-
Sharmili wants to make a program to print the sum of all perfect cubes, where the
value of the cubes go from 0 to 100. She writes the following program:

integer i = 0, a // statement 1

integer sum = 0;

a=(i*i*i)

while ( i < 100 ) // statement 2

sum = sum + a // statement 3

i=i+1

a = ( i * i * i ) // statement 4

print sum

Does this program have an error? If yes, which one statement will you modify to

correct the program?

Op 1: Statement 1

Op 2: Statement 2

Op 3: Statement 3

10
Op 4: Statement 4

Op 5: No error

Correct Op : 2

Question 24:-
Bhavya wants to make a program to print the sum of all perfect squares, where
the value of the squares go from 0 to 50. She writes the following program:

integer i = 1, a // statement 1

integer sum = 0

while ( a < 50 ) // statement 2

{
sum = sum + a // statement 3

i=i+1

a = ( i * i ); // statement 4

print sum

Does this program have an error? If yes, which one statement will you modify to

correct the program?

Op 1: Statement 1

Op 2: Statement 2

Op 3: Statement 3

Op 4: Statement 4

Correct Op : 1

Question 25:-
Vijay wants to print the following pattern on the screen:

24

246

11
2468

He writes the following program:

integer i = 1, j=2 // statement 1

while ( i <= 4 ) // statement 2

j = 2;

while ( j <= ? ) // Statement 3

{
print j

print blank space

j=j+2

print end-of-line \takes the cursor to the next line

i=i+1

What is the value of ? in statement 3 ?

Op 1: 8

Op 2: i

Op 3: 2*i

Op 4: 4

Correct Op : 3

Question 26:-
Shravanti writes the following program:

integer i = 0, j

while ( i < 2 )

{j = 0;

while ( j <= 3*i )

12
{print j

print blank space

j = j + 3}

print end-of-line \takes the cursor to the next line

i=i+1

}
What will be the output of the program?

Op 1:

03

Op 2:

03

036

Op 3:

036

0369

Op 4:

036

0369

0 3 6 9 12

Correct Op : 1

Question 27:-
Vijay wants to print the following pattern on the screen:

12

123

13
He writes the following program:

integer i = 1 // statement 1

while ( i <= 3 )

int j // Statement 2
while ( j <= i ) // Statement 3

print j

print blank space

j = j + 1 // Statement 4

print end-of-line \takes the cursor to the next line

i=i+1

Will this program function correctly? If not which one statement will you modify
to make the program function correctly?

Op 1: Statement 1

Op 2: Statement 2

Op 3: Statement 3

Op 4: Statement 4

Op 5: Program does not have error.

Correct Op : 2

Question 28:-
Charu writes the following program:

integer i = 1, j, a

while ( i <= 4 )

14
j = 1;

a = 0;

while ( a <= 5*i )

{
a = 2^j;

print a

print blank space

j=j+1

print end-of-line \takes the cursor to the next line

i=i+1

What will be the output of the program?

Op 1:2
24

248

2 4 8 16

Op 2: 2 4

248

2 4 8 16

2 4 8 16 32

Op 3: 2 4

248

248
2 4 8 16

15
Op 4: 2
24

24

2 4 8 16

Correct Op : 3

Question 29:-
Himanshu wants to write a program to print the larger of the two inputted
number. He writes the following code:

int number1, number 2

input number1, number 2

if (??) // Statement 1

print number1

else print number2

end if

Fill in the ?? in statement 1.

Op 1: number1>number2

Op 2: number2>number1

Op 3: number2 equals number1

Op 4: number1 <= number2

Correct Op : 1

Question 30:-
Shalini wants to program to print the largest number out of three inputted
numbers. She writes the following program:

int number1, number 2, number3, temp;

input number1, number2, number3;

if (number1>number2)

temp = number1

else

16
temp = number2

end if

if (??) // Statement 1

temp = number3

end if print temp

Fill in the ?? in Statement 1

Op 1: number3 > number2

Op 2: number3 > temp

Op 3: number3 < temp

Op 4: number3 > number1

Correct Op : 2

17
Question 1:-
Rohit writes the following program which inputs a number and prints "Double
digit" if the number is composed of two digits and "Not a double digit" if it is not.

int number;

if (number>10 AND number < 100)

print "Double digit"

else

print "Not a double digit"

end if

Rohit tries the following inputs: 5 and 66. The program works fine. He asks his bro
ther Ravi to try the program. When Ravi enters a number, the program doesn't wo
rk correctly. What did Ravi enter?

Op 1: 8

Op 2: 100

Op 3: 99
Op 4: 10

Correct Op : 4

Question 2:-
Rohan writes the following program which inputs a number and prints "Triple digit
" if the number is composed of three digits and "Not triple digit" if it is not.

int number;

if (number>99)

print "Triple digit"

else

print "Not triple digit"

end if

Rohan tries the following inputs: 25 and 566. The program works fine. He asks his
brother Ravi to try the program. When Ravi enters a number, the program doesn't
work correctly. What did Ravi enter?

18
Op 1: 99

Op 2: 100

Op 3: 0

Op 4: 1000

Correct Op : 4

Question 3:-
Abhinav wants to find the largest number in a given list of 20 numbers. Which of
the following is an efficient approach to do this?

Op 1: Use bubble sort to sort the list in descending order and then print the first number of
the series.

Op 2: Use selection sort to sort the list in descending order and then print the first number
of the series.

Op 3: Implement one iteration of selection sort for descending order and print the first num
ber in the series.

Op 4: None of these
Correct Op : 3

Question 4:-
Lavanya wants to find the smallest number out of 26 inputted numbers. How ma-
ny minimum comparisons he has to make?

Op 1: 25

Op 2: 13

Op 3: 26

Op 4: 52

Correct Op : 1

Question 5:-
A company offers commission for selling it products to its salesperson. The comm-
ission rate is Rs. 5 per product. However if the salesperson sells more than 200
items, he gets a commission of Rs. 10 on all items he sold after the first 200. Kanu
writes a program to calculate the commission for the salesperson:

integer numberProducts, commission

input numberProducts

19
if ( numberProducts > 200 )

-- MISSING STATEMENT --

else

commission = numberProducts * 5

end if

print commission

Fill in the missing statement.

Op 1: commission = (numberProducts - 200) * 10

Op 2: commission = 200 * 5 + (numberProducts - 200) * 10

Op 3: commission = numberProducts * 10

Op 4: None of these
Correct Op : 2

Question 6:-
Vikram wants to write a program which checks whether the inputted number is
divisible by any of the first 6 natural numbers (excluding 1). He writes the followi-
ng efficient code for it.

int number, n = 2, isdivisible=0

input number

while ( n <=6) // Statement 1

if ( remainder (number, n) == 0)

isdivisible = 1

end

n = n+1 // Statement 2

if (isdivisible equals 1)

print "It is divisible"

20
else

print "It is not divisible"

end

Vikram takes the program to Hari. Hari tells Vikram that though the code is correct
, it can be made more efficient. Hari modifies a single statement and makes the co
de more efficient. Which statement does he modify and how?

Op 1: Statement 1 is changed to:

while (n <=6 AND isdivisible=0)

Op 2: Statement 1 is changed to:

while (n <=6 OR isdivisible=0)

Op 3: Statement 1 is changed to:while (isdivisible=0)

Op 4: Statement 2 is changed to:

n=n+2

Correct Op : 1

Question 7:-
Rajiv wants to make a program which inputs two numbers: a and b (a>b) and
computes the number of terms between a and b (including a and b). What will be
code statement to do this:

Op 1: a - b

Op 2: a - b + 1

Op 3: a + b

Op 4: a - b - 1

Correct Op : 2

Question 8:-
I have a problem to solve which takes as input a number n. The problem has a pr-
operty that given the solution for (n-1), I can easily solve the problem for n. Which
programming technique will I use to solve such a problem?

Op 1: Iteration

Op 2: Decision-making

21
Op 3: Object Oriented Programming

Op 4: Recursion

Correct Op : 4

Question 9:-
What is the output of the following code statements? The compiler saves the first
integer at the memory location 4062. Integer is one byte long.

integer a

pointer b

a = 20

b = &a

print *b

Op 1: 4062

Op 2: 4063

Op 3: 20

Op 4: 10

Correct Op : 3

Question 10:-
What is the output of the following code statements? The compiler saves the first
integer at the memory location 4165 and the rest at consecutive memory spaces
in order of declaration. Integer is one byte long.

integer a, b

pointer c, d

a = 30

c = &a

b = *c

a = a + 10

print b

Op 1: 30

22
Op 2: 4165

Op 3: 40

Op 4: 4166

Correct Op : 1

Question 11:-
What is the output of the following code statements? The compiler saves the first
integer at the memory location 4165 and the rest at consecutive memory spaces
in order of declaration. Integer is one byte long.
integer a

pointer c, d

a = 30

c = &a

d=c

a = a + 10

print *c

Op 1: 30

Op 2: 4165

Op 3: 40

Op 4: 4166

Correct Op : 3

Question 12:-
What is space complexity of a program?

Op 1: Amount of hard-disk space required to store the program

Op 2: Amount of hard-disk space required to compile the program

Op 3: Amount of memory required by the program to run

Op 4: Amount of memory required for the program to compile

Correct Op : 3

Question13:-

23
The memory space needed by an algorithm has a fixed part independent of the
problem instance solved and a variable part which changes according to the
problem instance solved. In general, which of these two is of prime concern to an
algorithm designer?

Op 1: Fixed part

Op 2: Variable Part

Op 3: Product of fixed part and variable part


Op 4: None of these

Correct Op : 2

Question 14:-
While calculating time complexity of an algorithm, the designer concerns himself/
herself primarily with the run time and not the compile time. Why?

Op 1: Run time is always more than compile time.

Op 2: Compile time is always more than run time.

Op 3: Compile time is a function of run time.

Op 4: A program needs to be compiled once but can be run several times.

Correct Op : 4

Question 15:-
Pankaj and Mythili were both asked to write the code to evaluate the following
expression:

a - b + c/(a-b) + (a-b)2

Pankaj writes the following code statements (Code A):

print (a-b) + c/(a-b) + (a-b)*(a-b)

Mythili writes the following code statements (Code B):

d = (a-b) print d + c/d + d*d

If the time taken to load a value in a variable, for addition, multiplication or divisi-
on between two operands is same, which of the following is true?

Op 1: Code A uses lesser memory and is slower than Code B

Op 2: Code A uses lesser memory and is faster than Code B

24
Op 3: Code A uses more memory and is faster than Code B

Op 4: Code A uses more memory and is slower than Code B

Correct Op : 1

Question 16:-
Vrinda writes an efficient program to sum two square diagonal matrices (matrices
with elements only on diagonal). The size of each matrix is nXn. What is the time
complexity of Vrinda's algorithm?

Op 1: &theta(n^2)

Op 2: &theta(n)

Op 3: &theta(n*log(n))

Op 4: None of these

Correct Op : 2

Question 17:-
Tarang writes an efficient program to add two upper triangular 10X10 matrices
(elements on diagonal retained). How many total additions will his program make?

Op 1: 100

Op 2: 55

Op 3: 25

Op 4: 10

Correct Op : 2

Question 18:-
Ravi and Rupali are asked to write a program to sum the rows of a 2X2 matrices
stored in the array A.

Ravi writes the following code (Code A):

for n = 0 to 1

sumRow1[n] = A[n][1] + A[n][2]

end

Rupali writes the following code (Code B):

sumRow1[0] = A[0][1] + A[0][2]

25
sumRow1[1] = A[1][1] + A[1][2]

Comment upon these codes (Assume no loop-unrolling done by compiler):

Op 1: Code A will execute faster than Code B.

Op 2: Code B will execute faster than Code A

Op 3: Code A is logically incorrect.

Op 4: Code B is logically incorrect.

Correct Op : 2

Question 19:-
There is an array of size n initialized with 0. Akanksha has to write a code which in
serts the value 3k at position 3k in the array, where k=0,1…(till possible). Akanksha
writes an efficient code to do so. What is the time complexity of her code?

Op 1: &theta(n^2)

Op 2: &theta(n)

Op 3: &theta(log3(n))

Op 4: &theta(3n )

Correct Op : 3

Question 20:-
There are two matrices A and B of size nXn.The data in both these matrices resides
only at positions where both the indices are a perfect square. Rest all positions
have 0 as the data. Manuj has available a third matrix initialized with 0's at all
positions. He writes an efficient code to put the sum of A and B in C. What is the
time complexity of Manuj's program?

Op 1: &theta(n^2)

Op 2: &theta(n)

Op 3: &theta(n1/2)

Op 4: &theta(log(n))

Correct Op : 2

Question 21:-
Ravi has to add an strictly upper triangular (no elements at diagonal) and a strictly

26
lower triangular square matrix (no elements at diagonal) and put the result in a
third matrix. What is the time complexity of Ravi's algorithm? Assume that storing
a value in a memory space takes negligible time, while each addition between
values takes the dominating amount of time.

Op 1: &theta(n^2)
Op 2: &theta(n)

Op 3: &theta(1)

Op 4: None of these

Correct Op : 3

Question 22:-
We have two 100X3 (rowsXcolumn) matrices containing mid-term exam marks and
end-term exam marks of 100 students. Each row refers to a particular student,
while columns refer to marks in English, Social Sciences and Maths. The end-term
and mid-term marks of each student in each subject have to be added to get his
total score in each subject, to be put in a third matrix (100X3). Parinidhi writes a
code (Code A), where the outer loop iterates over the rows, while the inner loop
iterates over the columns. Shashi writes a code (Code B), where the outer loop
iterates over the columns, while the inner loop iterates over rows. Which of the
following is true with regard to their code ignoring any caching or memory storage
effects?

Op 1: Code A is faster than Code B

Op 2: Code B is faster than Code A

Op 3: Code A and Code B will run in the same amount of time

Op 4: The comparison between the speed of the codes cannot be made.

Correct Op : 2

Question23:-
A code takes the following code steps (equivalently time unit) to execute:

5*n3 + 6*n2 + 1.

Which of the following is not true about the time complexity of the program?

Op 1: It has a time complexity of O(n3 )

Op 2: It has a time complexity of O(n4 )

Op 3: It has a time complexity of O(n2 )

27
Op 4: It has a time complexity of &theta(n3 )

Correct Op : 3

Question 24:-
We have two programs. We know that the first has a time complexity O(n2 ),
while the second has a complexity &omega(n2 ). For sufficiently large n, which of
the following cannot be true?

Op 1: Both codes have same complexity

Op 2: The first code has higher time complexity than the second

Op 3: The second code has lower time complexity than the first code.

Op 4: Both codes are the same.

Correct Op : 2

Question 25:-
The time complexity of code A is &theta(n), while for Code B it is &theta(log(n)).
Which of the following is true for sufficiently large n?

Op 1: Both code have the same time complexity

Op 2: Code A has higher time complexity

Op 3: Code B has higher time complexity

Op 4: No comparison can be made between the time complexity of the two codes.

Correct Op : 2

Question 26:-
Rajini is given an efficient code for summing two nXn matrices and putting the
result in a third matrix. She is asked to find it's time complexity. She realizes that
the number of iterations required is more than n. What can she claim with regard
to the complexity of the code?

Op 1: It is O(n)

Op 2: It is O(n2)

Op 3: It is theta(n)

Op 4: It is omega(n)

Correct Op : 4

Question 27:-

28
Gautam is given two codes, A and B, to solve a problem, which have complexity
theta(n) & theta(n2) respectively. His client wants to solve a problem of size k,
which Gautam does not know. Which code will Gautam deliver to the client, so
that the execution is faster?

Op 1: Code A

Op 2: Code B

Op 3: Gautam cannot determine

Op 4: Both codes have the same execution time, so deliver any.

Correct Op : 3

Question 28:-
Surbhi is given two codes, A and B, to solve a problem, which have complexity
O(n3) & Omega(n4) respectively. Her client wants to solve a problem of size k,
which is sufficiently large. Which code will Surbhi deliver to the client, so that the
execution is faster?

Op 1: Code A

Op 2: Code B

Op 3: Surbhi cannot determine

Op 4: Both codes have the same execution time, so deliver any.

Correct Op : 1

Question 29:-
Vibhu is given two codes, A and B, to solve a problem, which have complexity
O(n4) & Omega(n3) respectively. Her client wants to solve a problem of size k,
which is sufficiently large. Which code will Gautam deliver to the client, so that the
execution is faster?

Op 1: Code A

Op 2: Code B

Op 3: Vibhu cannot determine

Op 4: Both codes have the same execution time, so deliver any.

Correct Op : 3

Question 30:-
Pavithra is given two codes, A and B, to solve a problem, which have complexity

29
&theta(n3) and &omega(n3) respectively. Her client wants to solve a problem of
size k, which is sufficiently large. Which code should she deliver to the client in
the present scenario?

Op 1: Code A

Op 2: Code B

Op 3: Both codes have the same execution time, so deliver any.

Op 4: None of these

Correct Op : 1

30
1) Problem: 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 inactivethe 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 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

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

31
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]
2) Question 2: 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
{I
nt value;
Cnode*
next;
};C
node* 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>^]
3) Question 3: The LeastRecentlyUsed(LRU) cache algorithm exists the element
from the cache(when it's full) that was leastrecentlyused. After an element is

32
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 shallconsist 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 usingthe
LRU cache algorithm.
Assume that the array pages always has 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
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
}
4) Question 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 RoundRobin 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 thatit
spends waiting to be run. Each job arrives at particular time for scheduling and certain

33
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 RoundRobin 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 RoundRobin policy. The list of job arrival
time and run time sorted in ascending order by arrival time. For jobs arriving atsame 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 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.
6) Question 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 RoundRobin 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 thatit
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 RoundRobin policy.

34
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 RoundRobin policy. The list of job arrival
time and run time sorted in ascending order by arrival time. For jobs arriving atsame 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.

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

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

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

8) Test whether an input string of opening and closing parentheses was balanced or
not. If yes , return the no. of parentheses. If no, return -1.

36
• Reverse the second half of an input linked list. If the input linked list contained
oddnumber of elements , consider the middlemost element too in the second
half.
9) Write a program to Merge sort using pointers
10) Merge two sorted singly linked lists into one sorted list
11) Reverse a linked list using recursion and without recursion
12) Removal of vowel from string
13) Print and count all the numbers which are less than a given key element from a
given array.
14) Eliminate repeated letters in Array
15) String Reversal
16) Find a target value in a two-dimensional matrix given the number of rows as
rowCount and number of columns as columnCount, and return its coordinates. If the
value didn't exist, the program had to return (-1,-1).
17) Obtain a output as follows:
1
23
456
7 8 9 10
11 12 13 14 15
11 12 13 14 15
7 8 9 10
456
23
1

18) Write a C program to print below,when n=4 and s=3


3
44
555
555
44
3

37
19) Input: num1 and num2 such that 0 <= num1 <= 99999999 and 0 <= num2 <=
9. You have to find number of occurences of input num2 in input num1 and
return it with function int isOccured(int num1, int num2).
Example:
Input: num1= 199294, num2= 0
Output: 3
Test Case 1:
Input:
1222212
2
Expected Output:
5
Test Case 2:
Input:
1001010
0
Expected Output:
4

20) Find a sub string in a given string and replace it with another string?
21) Remove all the vowels from a given string using pointers concept
22) Program to check for prime number:
23) To find GCD of two number.
24) Find the GCD of N numbers using pointers
25) Print all the prime numbers which are below the given number separated by
comma.
26) C program to find out prime factors of given number
27) C Program to Display Prime Numbers between Two Intervals
28) C Program to Display Armstrong Number Between Two Intervals
29) Write a function to return a sorted array after merging two unsorted arrays, the
parameters will be two integer pointers for referencing arrays and two int variable, the
length of arrays (Hint: use malloc() to allocate memory for 3rd array):
30) Get an unsorted array and convert into alternate array(alternate array-
ascending order array by taking alternate elements).Half elements of array in
ascending remaining half in descending.The first n elements should be sorted in
ascending order and the next part should be sorted in descending and print it

38
Test Case Input: [1,5,6,8,4,7]6; 6 is the length of array
31) Given 5,1,4,7,9..... do alternate sort for this..and print 1,5,9
32) Pattern Question:- For n=5
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15
33) Pattern Question:-
1
22
333
4444
55555
4444
333
22
1
34) Pattern Question:-
To print the pattern like for n=3 the program should
print1 1 1 2
3222
3334
35) print n=6; n stands for number of lines
1111112
3222222
3333334
5444444
5555556
7666666
36) To print the trapezium pattern. for example , we have n=4 the output should
be like
1*2*3*4*17*18*19*20
- -5*6*7*14*15*16
- - - -8*9*12*13
- - - - - -10*11
37) C program to print following pyramid pattern of stars

39
38) Write a c program to print Pascal triangle.
In mathematics, Pascal's triangle is a triangular array of the binomial coefficients.In
much of the Western world it is named after French mathematician Blaise Pascal,
although other mathematicians studied it centuries before him in India, Iran, China,
Germany, and Italy.

38) 1
3*2
4*5*6
9*8*7
14*13*12*11

39) 1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1

40) 1
2 2
3 3 3
44 4
4

41) 1*2*3*4
9*10*11*12
13*14*15*1
65*6*7*8

41

You might also like