Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

Multiple choice question for engineering

Set 1

1. When discussing feed mixers, what is the range of manufacturers recommended mixing times?
a) 1-2 minutes
b) 3-6 minutes
c) 10-15 minutes
d) 7-9 minutes

View Answer

Answer: b [Reason:] 3-6 minutes is the minimum mixing time for (single-auger) vertical feed mixers. The feed is mixed into the acceptable mixing range (below 10%) until 3 minutes had elapsed.

2. The letters FSIS stand for what?
a) Food Service and Inspection Safety
b) Free State Inspection Service
c) Food Sanitation and Inquiry Service
d) Food Safety and Inspection Service

View Answer

Answer: d [Reason:] The Food Safety and Inspection Service (FSIS), an agency of the United States Department of Agriculture (USDA), is the public health regulatory agency responsible for ensuring that United States’ commercial supply of meat, poultry, and egg products is safe, wholesome, and correctly labeled and packaged.

3. What do the letters FARAD stand for?
a) Food Animal Resistance Activity Database
b) Food Animal Residue Avoidance Data
c) Food Animal Resistance Activity Data
d) Food Animal Residue Avoidance Databank

View Answer

Answer: d [Reason:] The Food Animal Residue Avoidance Databank (FARAD) is part of the Food Animal Residue Avoidance & Depletion Program, which has served the veterinary profession for more than 35 years.

4. What bacterium causes cattle tuberculosis (TB)?
a) Mycobacterium canine
b) Mycobacterium ovius
c) Mycobacterium avious
d) Mycobacterium bovis

View Answer

Answer: d [Reason:] Bovine tuberculosis (TB) is a chronic disease of animals caused by bacteria called Mycobacterium bovis, (M.bovis) which is closely related to the bacteria that cause human and avian tuberculosis.

5. Oxytocin causes what to happen in a dairy cow?
a) Milk letdown
b) Uterine contractions
c) Milk letdown and urine contraction
d) Pregnancy

View Answer

Answer: c [Reason:] Release of the hormone oxytocin from the cow’s pituitary gland in the brain into the bloodstream, where it travels to the udder and causes several important processes to occur. Processes include milk letdown and urine contraction.

6. How frequently should an average cow freshen?
a) Once every 24 months
b) Once every 12 months
c) Once every 20 months
d) Only once in her lifetime

View Answer

Answer: b [Reason:] Under perfect conditions, the cow has a calf every year. When the cow freshens for the first time and becomes part of the milking herd.

7. What do the letters NRC stand for?
a) National Research Company
b) National Research Council
c) National Research Chapter
d) National Rehabilitation Center

View Answer

Answer: b [Reason:] The National Research Council (NRC) is the Government’s premier research organization supporting industrial innovation, the advancement of knowledge and technology development, and fulfilling government mandates.

8. When discussing nutrition, what does NPN stand for?
a) Nonprotein nitrogen
b) Normal protein necessities
c) Natural protein nitrogen
d) No protein in nitrogen

View Answer

Answer: a [Reason:] Non-protein nitrogen (or NPN) is a term used in animal nutrition to refer collectively to components such as urea, biuret, and ammonia, which are not proteins but can be converted into proteins by microbes in the ruminant stomach.

9. Corn silage, stored in upright, top-unloading silos, should be chopped at what percent moisture?
a) 72 to 75 percent moisture
b) 82 to 85 percent moisture
c) 92 to 95 percent moisture
d) 62 to 65 percent moisture

View Answer

Answer: d [Reason:] Cattle are easily changed from corn silage to a high-grain finishing ration. Corn silage is often used to furnish minimum roughage levels in high-grain finishing rations. Corn silage, stored in upright, top-unloading silos, should be chopped at 62 to 65 percent moisture.

Set 2

1. What does GnRH stand for?
a) Gestation Repression Hormone
b) Genotype Reflection Hormone
c) Goonie Resusitation Hoovermobile
d) Gonadotropin Releasing Hormone

View Answer

Answer: d [Reason:] GnRH is Gonadotropin Releasing Hormone. GnRH is the harmone which stimulates the synthesis and secretion of the two gonadotropins—luteinizing hormone (LH) and follicle-stimulating hormone (FSH)—by the anterior pituitary gland.

2. What is the average duration of standing heat in cattle?
a) 4 hours
b) 12 hours
c) 70 hours
d) 8 hours

View Answer

Answer: b [Reason:] The average duration of standing heat is 15 to 18 hours, but heat duration may vary from 8 to 30 hours among cows. An estrous cow usually stands to be mounted 20 to 55 times during her estrous period. Each mount lasts three to seven seconds.

3. What is the approximate time of ovulation in cattle after the beginning of heat?
a) 60 hours
b) 90 hours
c) 30 hours
d) 3 hours

View Answer

Answer: c [Reason:] Traditionally, the cow that stands still and allows others to mount her is in “standing heat.” Standing is the primary sign of estrus. Ovulation occurs at approximately 24 to 32 hours after the onset of standing estrus in dairy cows.

4. What hormone is responsible for maintaining pregnancy?
a) Progesterone
b) Lutalyse
c) Prostaglandin
d) Oxytocin

View Answer

Answer: a [Reason:] This group of hormones is responsible for the development of the female sexual characteristics. Usually formed in the ovaries, estrogen is also made by the placenta during pregnancy to help maintain a healthy pregnancy. Progesterone hormone is made by the ovaries and by the placenta during pregnancy.

5. What is the scientific term for birth?
a) Domino
b) Parturition
c) Calving
d) Dystocia

View Answer

Answer: b [Reason:] Parturition, also called birth or childbirth, process of bringing forth a child from the uterus, or womb. The prior development of the child in the uterus is described in the article human embryology. The process and series of changes which take place in a woman’s organs and tissues as a result of the developing fetus are discussed in the article pregnancy.

6. In reference to reproduction, what does CL stand for?
a) Cattle Lutalysis
b) Cervix Lymphocyte
c) Compound Luteum
d) Corpus Luteum

View Answer

Answer: d [Reason:] The corpus luteum is a temporary endocrine structure involved in ovulation and early pregnancy. During ovulation, the primary follicle leads to formation of the secondary follicle and subsequently the mature vesicular follicle. At ovulation the follicle ruptures expelling the ovum into the fallopian tube.

7. To the hundredth, how many pounds of milk are in one gallon?
a) 8.52 pounds
b) 8.72 pounds
c) 8.92 pounds
d) 8.62 pounds

View Answer

Answer: d [Reason:] This is because a gallon of milk weighs about 8.6 pounds, give or take, based upon whether it is whole milk (heavier) or skim (lighter). But for our purposes, the 8.6 and 11.63 are accurate enough.

8. What pathway in young calves directs milk into the abomasum, bypassing the rumen, reticulum, and omasum?
a) Rumen bypass groove
b) Masticulas passinomis
c) Esophageal groove
d) Rumen passinomis

View Answer

Answer: c [Reason:] The esophageal groove is a curved muscle that lies in the throat of the calf. When a calf drinks water from a trough or eats meal and grains, the esophageal groove stays curved to direct these foods to the rumen for digestion. It is also a pathway in young cows to direct milk into the abomasums.

9. Milk fever is also (scientifically) known as what?
a) Postpartum paresis
b) Mamogenesis
c) Masticular Paresis
d) Parturient paresis

View Answer

Answer: d [Reason:] Milk fever, postparturient hypocalcemia, or parturient paresis is a disease, primarily in dairy cattle, but also seen in beef cattle, characterized by reduced blood calcium levels.

10. What is Parturient paresis caused by?
a) Low blood levels of ionized calcium
b) Low blood levels of ionized sodium
c) Low blood levels of ionized zinc
d) Low blood levels of ionized vitamin-D

View Answer

Answer: a [Reason:] Parturient paresis, also called milk fever, in cattle, a disorder characterized by abnormally low levels of calcium in the blood (hypocalcemia). It occurs in cows most commonly within three days after they have calved, at a time when the cow’s production of milk has put a severe strain on its calcium stores.

11. According to the NRC, what percent calcium should a dry cow ration contain?
a) 1 percent
b) 2 percent
c) 10 percent
d) 39 percent

View Answer

Answer: d [Reason:] The required dietary energy concentration is a function of the energy requirement and the feed intake rate. The cow ration should contain about 39 percent of calcium.

12. High potassium intake will decrease a cows ability to mobilize what?
a) Bone phosphorus
b) Lymphocytes
c) Bone calcium
d) Immunoglobulins

View Answer

Answer: c [Reason:] Having a diet with too much potassium in the weeks before calving can make the cows weak and make them downer cows. It can make them susceptible to milk fever, hence affecting the ability to mobilize bone calcium. The critical time is 4-6 weeks before calving.

13. Cows that are at risk of developing ketosis can be fed what vitamin to help prevent ketosis?
a) Niacin
b) Zinc
c) B-complex
d) Vitamin-C

View Answer

Answer: a [Reason:] Another supplement that might be useful to people who consume the ketogenic diet is Niacin. Vitamin D is a fat-soluble nutrient that also functions as a hormone in the body.

14. Hairy Heel Wart is scientifically known as what?
a) Digital Divide
b) Digital Dermatitis
c) Intraheel laminitis
d) Digital phlegmon

View Answer

Answer: b [Reason:] Bovine digital dermatitis is an infectious condition of the foot caused by bacteria called Treponemes. Infections typically result in ulcers and/or warts.

15. Foot Rot is scientifically known as what?
a) Intraheel laminitis
b) Digital Dermatitis
c) Interdigital phlegmon
d) Phlegmon

View Answer

Answer: c [Reason:] Footrot is a subacute or acute necrotic infection that originates in the interdigital skin, leading to cellulitis in the digital region.

Set 3

1. Given a string, you have to find the minimum number of characters to be inserted in the string so that the string becomes a palindrome. Which of the following methods can be used to solve the problem?
a) Greedy algorithm
b) Recursion
c) Dynamic programming
d) Both recursion and dynamic programming

View Answer

Answer: d [Reason:] Dynamic programming and recursion can be used to solve the problem.

2. In which of the following cases will the number of insertions to form a palindrome be minimum?
a) String of length one
b) String with all same characters
c) Palindromic string
d) All of the mentioned

View Answer

Answer: d [Reason:] In all the mentioned cases, the number of insertions will be zero since the strings are already palindromes.

3. In the worst case, the minimum number of insertions to be made to convert the string into a palindrome is equal to the length of the string.
a) True
b) False

View Answer

Answer: b [Reason:] In the worst case, the minimum number of insertions to be made to convert the string into a palindrome is equal to length of the string minus one. For example, consider the string “abc”. The string can be converted to “abcba” by inserting “a” and “b”. The number of insertions is two, which is equal to length minus one.

4. Consider the string “efge”. What is the minimum number of insertions required to make the string a palindrome?
a) 0
b) 1
c) 2
d) 3

View Answer

Answer: b [Reason:] The string can be converted to “efgfe” by inserting “f” or to “egfge” by inserting “g”. Thus, only one insertion is required.

5. Consider the string “abbccbba”. What is the minimum number of insertions required to make the string a palindrome?
a) 0
b) 1
c) 2
d) 3

View Answer

Answer: a [Reason:] The given string is already a palindrome. So, no insertions are required.

6. Which of the following problems can be used to solve the minimum number of insertions to form a palindrome problem?
a) Minimum number of jumps problem
b) Longest common subsequence problem
c) Coin change problem
d) None of the mentioned

View Answer

Answer: b [Reason:] A variation of longest common subsequence can be used to solve the minimum number of insertions to form a palindrome problem.

7. Consider the following dynamic programming implementation:

#include<stdio.h>
#include<string.h>
int max(int a, int b)
{
if(a > b)
return a;
return b;
}
int min_ins(char *s)
{
int len = strlen(s), i, j;
int arr[len + 1][len + 1];
char rev[len + 1];
strcpy(rev, s);
strrev(rev);
for(i = 0;i <= len; i++)
arr[i][0] = 0;
for(i = 0; i <= len; i++)
arr[0][i] = 0;
for(i = 1; i <= len; i++)
{
for(j = 1; j <= len; j++)
{
if(s[i - 1] == rev[j - 1])
arr[i][j] = arr[i - 1][j - 1] + 1;
else
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
return _____________;
}
int main()
{
char s[] = "abcda";
int ans = min_ins(s);
printf("%d",ans);
return 0;
}

Which of the following lines should be added to complete the code?
a) arr[len][len].
b) len + arr[len][len].
c) len
d) len – arr[len][len].

View Answer

Answer: d [Reason:] arr[len][len] contains the length of the longest palindromic subsequence. So, len – arr[len][len] gives the minimum number of insertions required to form a palindrome.

8. What is the time complexity of the above dynamic programming implementation of the minimum number of insertions to form a palindrome problem?
a) O(1)
b) O(n)
c) O(n2)
d) None of the mentioned

View Answer

Answer: c [Reason:] The time complexity of the above dynamic programming implementation is O(n2).

9.What is the space complexity of the above dynamic programming implementation of the minimum number of insertions to form a palindrome problem?
a) O(1)
b) O(n)
c) O(n2)
d) None of the mentioned

View Answer

Answer: c [Reason:] The space complexity of the above dynamic programming implementation is O(n2).

10. What is the output of the following code?

#include<stdio.h>
#include<string.h>
int max(int a, int b)
{
if(a > b)
return a;
return b;
}
int min_ins(char *s)
{
int len = strlen(s), i, j;
int arr[len + 1][len + 1];
char rev[len + 1];
strcpy(rev, s);
strrev(rev);
for(i = 0;i <= len; i++)
arr[i][0] = 0;
for(i = 0; i <= len; i++)
arr[0][i] = 0;
for(i = 1; i <= len; i++)
{
for(j = 1; j <= len; j++)
{
if(s[i - 1] == rev[j - 1])
arr[i][j] = arr[i - 1][j - 1] + 1;
else
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
return len - arr[len][len];
}
int main()
{
char s[] = "abcda";
int ans = min_ins(s);
printf("%d",ans);
return 0;
}

a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] The length of the longest palindromic subsequence is 3. So, the output will be 5 – 3 = 2.

11. What is the value stored in arr[2][4] when the following code is executed?

#include<stdio.h>
#include<string.h>
int max(int a, int b)
{
if(a > b)
return a;
return b;
}
int min_ins(char *s)
{
int len = strlen(s), i, j;
int arr[len + 1][len + 1];
char rev[len + 1];
strcpy(rev, s);
strrev(rev);
for(i = 0;i <= len; i++)
arr[i][0] = 0;
for(i = 0; i <= len; i++)
arr[0][i] = 0;
for(i = 1; i <= len; i++)
{
for(j = 1; j <= len; j++)
{
if(s[i - 1] == rev[j - 1])
arr[i][j] = arr[i - 1][j - 1] + 1;
else
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
return len - arr[len][len];
}
int main()
{
char s[] = "abcda";
int ans = min_ins(s);
printf("%d",ans);
return 0;
}

a) 2
b) 3
c) 4
d) 5

View Answer

Answer: a [Reason:] The value stored in arr[2][4] when the above code is executed is 2.

12. What is the output of the following code?

#include<stdio.h>
#include<string.h>
int max(int a, int b)
{
if(a > b)
return a;
return b;
}
int min_ins(char *s)
{
int len = strlen(s), i, j;
int arr[len + 1][len + 1];
char rev[len + 1];
strcpy(rev, s);
strrev(rev);
for(i = 0;i <= len; i++)
arr[i][0] = 0;
for(i = 0; i <= len; i++)
arr[0][i] = 0;
for(i = 1; i <= len; i++)
{
for(j = 1; j <= len; j++)
{
if(s[i - 1] == rev[j - 1])
arr[i][j] = arr[i - 1][j - 1] + 1;
else
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
return len - arr[len][len];
}
int main()
{
char s[] = "efgfe";
int ans = min_ins(s);
printf("%d",ans);
return 0;
}

a) 0
b) 2
c) 4
d) 6

View Answer

Answer: a [Reason:] Since the string “efgfe” is already a palindrome, the number of insertions required is 0.

Set 4

1. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
a) AB+ CD*E – FG /**
b) AB + CD* E – F **G /
c) AB + CD* E – *F *G /
d) AB + CDE * – * F *G /

View Answer

Answer: a [Reason:] Applying the postfix expression evaluation.

2. The data structure required to check whether an expression contains balanced parenthesis is?
a) Stack
b) Queue
c) Array
d) Tree

View Answer

Answer: a [Reason:] Self Explanatory.

3. What data structure would you mostly likely see in a non recursive implementation of a recursive algorithm?
a) Linked List
b) Stack
c) Queue
d) Tree

View Answer

Answer: b [Reason:] Self Explanatory.

4. The process of accessing data stored in a serial access memory is similar to manipulating data on a ________
a) Heap
b) Binary Tree
c) Array
d) Stack

View Answer

Answer: d [Reason:] Self Explanatory.

5. The postfix form of A*B+C/D is?
a) *AB/CD+
b) AB*CD/+
c) A*BC+/D
d) ABCD+/*

View Answer

Answer: b [Reason:] Applying the postfix expression evaluation.

6. Which data structure is needed to convert infix notation to postfix notation?
a) Branch
b) Tree
c) Queue
d) Stack

View Answer

Answer: d [Reason:] Self Explanatory.

7. The prefix form of A-B/ (C * D ^ E) is?
a) -/*^ACBDE
b) -ABCD*^DE
c) -A/B*C^DE
d) -A/BC*^DE

View Answer

Answer: c [Reason:] Applying the prefix expression evaluation.

8. What is the result of the following operation
Top (Push (S, X))
a) X
b) Null
c) S
d) None

View Answer

Answer: a [Reason:] Self Explanatory.

9. The prefix form of an infix expression p + q – r * t is?
a) + pq – *rt
b) – +pqr * t
c) – +pq * rt
d) – + * pqrt

View Answer

Answer: c [Reason:] Applying the prefix expression evaluation.

10. Which data structure is used for implementing recursion?
a) Queue
b) Stack
c) Array
d) List

View Answer

Answer: b [Reason:] Stacks are used for implementation of Recursion.

Set 5

1. Express -15 as a 6-bit signed binary number.
a) 001111
b) 101111
c) 101110
d) 001110

View Answer

Answer: b [Reason:] The first 4 1s from the right represent the number 15, 2 more bits are padded to make it 6 digits and the leftmost bit is a 1 to represent that it is -15.

2. Which of the following code snippet is used to convert decimal to binary numbers?
a)

public void convertBinary(int num)
{
int bin[] = new int[50];
int index = 0;
while(num > 0)
{
bin[index++] = num%2;
num = num/2;
}
for(int i = index-1;i >= 0;i--)
{
System.out.print(bin[i]);
}
}

b)

public void convertBinary(int num)
{
int bin[] = new int[50];
int index = 0;
while(num > 0)
{
bin[++index] = num%2;
num = num/2;
}
for(int i = index-1;i >= 0;i--)
{
System.out.print(bin[i]);
}
}

c)

public void convertBinary(int num)
{
int bin[] = new int[50];
int index = 0;
while(num > 0)
{
bin[index++] = num/2;
num = num%2;
}
for(int i = index-1;i >= 0;i--)
{
System.out.print(bin[i]);
}
}

d)

public void convertBinary(int num)
{
int bin[] = new int[50];
int index = 0;
while(num > 0)
{
bin[++index] = num/2;
num = num%2;
}
for(int i = index-1;i >= 0;i--)
{
System.out.print(bin[i]);
}
}

View Answer

Answer: a [Reason:] Take the modulus by 2 of the number and store in an array while halving the number during each iteration and then display the contents of the array.

3. Which is the predefined method available in Java to convert decimal to binary numbers?
a) toBinaryInteger(int)
b) toBinaryValue(int)
c) toBinaryNumber(int)
d) toBinaryString(int)

View Answer

Answer: d [Reason:] The method toBinaryString() takes an integer argument and is defined in java.lang package. Usage is java.lang.Integer.toBinaryString(int) this returns the string representation of the unsigned integer value.

4. Using stacks, how to obtain the binary representation of the number?
a)

public void convertBinary(int num)
{
Stack<Integer> stack = new Stack<Integer>();
while (num != 0)
{
int digit = num / 2;
stack.push(digit);
num = num % 2;
} 
System.out.print("nBinary representation is:");
while (!(stack.isEmpty() ))
{
System.out.print(stack.pop());
}
}

b)

public void convertBinary(int num)
{
Stack<Integer> stack = new Stack<Integer>();
while (num != 0)
{
int digit = num % 2;
stack.push(digit);
} 
System.out.print("nBinary representation is:");
while (!(stack.isEmpty() ))
{
System.out.print(stack.pop());
}
}

c)

public void convertBinary(int num)
{
Stack<Integer> stack = new Stack<Integer>();
while (num != 0)
{
int digit = num % 2;
stack.push(digit);
num = num / 2;
} 
System.out.print("nBinary representation is:");
while (!(stack.isEmpty() ))
{
System.out.print(stack.pop());
}
}

d) None of the above

View Answer

Answer: c [Reason:] Here instead of adding the digits to an array, you push it into a stack and while printing, pop it from the stack.

5. What is the time complexity for converting decimal to binary numbers?
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)

View Answer

Answer: c [Reason:] Since each time you are halving the number, it can be related to that of a binary search algorithm, hence the complexity is O(logn).

6. Write a piece of code which returns true if the string contains balanced parenthesis, false otherwise.
a)

public boolean isBalanced(String exp)
{
int len = exp.length();
Stack<Integer> stk = new Stack<Integer>();
for(int i = 0; i < len; i++)
{
char ch = exp.charAt(i);
if (ch == '(')
stk.push(i);
else if (ch == ')')
{
if(stk.peek() == null)
{
return false;
}
stk.pop();
}
}
return true;
}

b)

public boolean isBalanced(String exp)
{
int len = exp.length();
Stack<Integer> stk = new Stack<Integer>();
for(int i = 0; i < len; i++)
{
char ch = exp.charAt(i);
if (ch == '(')
stk.push(i);
else if (ch == ')')
{
if(stk.peek() != null)
{
return true;
}
stk.pop();
}
}
return false;
}

c)

public boolean isBalanced(String exp)
{
int len = exp.length();
Stack<Integer> stk = new Stack<Integer>();
for(int i = 0; i < len; i++)
{
char ch = exp.charAt(i);
if (ch == ')')
stk.push(i);
else if (ch == '(')
{
if(stk.peek() == null)
{
return false;
}
stk.pop();
}
}
return true;
}

d)

public boolean isBalanced(String exp)
{
int len = exp.length();
Stack<Integer> stk = new Stack<Integer>();
for(int i = 0; i < len; i++)
{
char ch = exp.charAt(i);
if (ch == '(')
stk.push(i);
else if (ch == ')')
{
if(stk.peek() != null)
{
return false;
}
stk.pop();
}
}
return true;
}

View Answer

Answer: a [Reason:] Whenever a ‘(‘ is encountered, push it into the stack, and when a ‘)’ is encountered check the top of the stack to see if there is a matching ‘(‘, if not return false, continue this till the entire string is processed and then return true.

7. What is the time complexity of the above code?
a) O(logn)
b) O(n)
c) O(1)
d) O(nlogn)

View Answer

Answer: b [Reason:] All the characters in the string have to be processed, hence the complexity is O(n).

8. For every matching parenthesis, print their indices.
a)

public void dispIndex(String exp)
{
Stack<Integer> stk = new Stack<Integer>();
for (int i = 0; i < len; i++)
{    
char ch = exp.charAt(i);
if (ch == '(')
stk.push(i);
else if (ch == ')')
{
try
{
int p = stk.pop() + 1;
System.out.println("')' at index "+(i+1)+" matched with ')' at index "+p);
}
catch(Exception e)
{
System.out.println("')' at index "+(i+1)+" is unmatched");
}
}            
}
while (!stk.isEmpty() )
System.out.println("'(' at index "+(stk.pop() +1)+" is unmatched");
}

b)

public void dispIndex(String exp)
{
Stack<Integer> stk = new Stack<Integer>();
for (int i = 0; i < len; i++)
{    
char ch = exp.charAt(i);
if (ch == '(')
stk.push(i);
else if (ch == ')')
{
try
{
int p = stk.pop() + 1;
System.out.println("')' at index "+(i)+" matched with ')' at index "+p);
}
catch(Exception e)
{
System.out.println("')' at index "+(i)+" is unmatched");
}
}            
}
while (!stk.isEmpty() )
System.out.println("'(' at index "+(stk.pop() +1)+" is unmatched");
}

c)

public void dispIndex(String exp)
{
Stack<Integer> stk = new Stack<Integer>();
for (int i = 0; i < len; i++)
{    
char ch = exp.charAt(i);
if (ch == ')')
stk.push(i);
else if (ch == '(')
{
try
{
int p = stk.pop() + 1;
System.out.println("')' at index "+(i+1)+" matched with ')' at index "+p);
}
catch(Exception e)
{
System.out.println("')' at index "+(i+1)+" is unmatched");
}
}            
}
while (!stk.isEmpty() )
System.out.println("'(' at index "+(stk.pop() +1)+" is unmatched");
}

d) None of the mentioned

View Answer

Answer: a [Reason:] Whenever a ‘(‘ is encountered, push the index of that character into the stack, so that whenever a corresponding ‘)’ is encountered, you can pop and print it.