Computer Science MCQS

Computer Science MCQ with detailed explanations for students & freshers preparing for entrance exams, various tests, interviews, competitive exams like GATE exam, interview, competitive examination and entrance exam.

What is the value of the postfix expression 6 3 2 4 + – *?

A. a) 74
B. b) -18
C. c) 22
D. d) 40
Correct answer is: B. b) -18
Postfix notation evaluates expressions by processing operands first, followed by operators.

Given expression: 6 3 2 4 + - *

Scan the expression from left to right:

6, 3, 2, 4: These are operands, so we push them onto a stack.

+: We encounter an operator. Pop the top two elements from the stack (4 and 2), add them (4 + 2 = 6), and push the result (6) back onto the stack.

-: We encounter another operator. Pop the top two elements from the stack (6 and 3), subtract them (3 - 6 = -3), and push the result (-3) back onto the stack.

*: We encounter the last operator. Pop the top two elements from the stack (6 and -3), multiply them (6 * -3 = -18), and push the result (-18) back onto the stack.

Since we've reached the end of the expression, the final result is the only element left on the stack, which is -18.

Therefore, the value of the postfix expression 6 3 2 4 + - * is -18.

Which data structure is needed to convert infix notation to postfix notation?

A. a) Tree
B. b) Branch
C. c) Stack
D. d) Queue
Correct answer is: C. c) Stack
LIFO (Last In, First Out) property: This is crucial for handling operators and their precedence.

Efficient push and pop operations: The stack allows for quick insertion and removal of operators, which is necessary for the conversion process.

How it works:

Scan the infix expression from left to right:

If an operand is encountered, add it to the postfix expression.

If an operator is encountered:While the stack is not empty and the precedence of the top operator is greater than or equal to the precedence of the current operator, pop the top operator from the stack and add it to the postfix expression. Push the current operator onto the stack.

When the end of the expression is reached:

Pop all remaining operators from the stack and add them to the postfix expression.

By using a stack and following these steps, we can effectively convert infix expressions to their postfix equivalents.

Which of the following is not the application of stack?

A. a) Data Transfer between two asynchronous process
B. b) Compiler Syntax Analyzer
C. c) Tracking of local variables at run time
D. d) A parentheses balancing program
Correct answer is: A. a) Data Transfer between two asynchronous process
Stacks follow LIFO (Last In, First Out) principle: This means the last element added is the first one to be removed.

Data transfer between asynchronous processes requires a FIFO (First In, First Out) structure, where the first element added is the first one to be removed.

Queues are the ideal data structure for this purpose, as they adhere to the FIFO principle.

Other options:

b) Compiler Syntax Analyzer: Stacks are used extensively in compilers for parsing expressions and checking for syntax errors.

c) Tracking of local variables at run time: Function calls and their corresponding local variables are managed using stacks.

d) A parentheses balancing program: As we discussed earlier, stacks are essential for checking the balance of parentheses in an expression.

Therefore, while stacks are crucial for many applications, they are not suitable for data transfer between asynchronous processes.

The data structure required to check whether an expression contains a balanced parenthesis is?

A. ”a)
B. ”b)
C. ”c)
D. ”d)
Correct answer is: B. ”b)
”LIFO

Which data structure is used for implementing recursion?

A. a) Stack
B. b) Queue
C. c) List
D. d) Array
Correct answer is: A. a) Stack
Stack is the data structure used for implementing recursion.

Explanation:

Recursion involves a function calling itself directly or indirectly.

Each time a function is called, a new activation record is created. This record contains information about the function's parameters, local variables, and return address.

To keep track of these activation records and ensure proper execution, a LIFO (Last In, First Out) data structure is needed.

Stack is the perfect LIFO data structure for this purpose.

When a function is called, its activation record is pushed onto the stack.

When the function returns, its activation record is popped off the stack.

This process allows the system to manage multiple function calls efficiently and correctly.

What are the disadvantages of arrays?

A. a) Index value of an array can be negative
B. b) Elements are sequentially accessed
C. c) Data structure like queue or stack cannot be implemented
D. d) There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size
Correct answer is: D. d) There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size
There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size is the correct answer.

Explanation:

Fixed size: Arrays have a fixed size, which means you need to specify the number of elements it can hold when you declare it.

Memory allocation: The system allocates a contiguous block of memory for the array based on the specified size.

Wastage: If you only need to store fewer elements than the allocated size, the remaining memory space in the array goes unused, leading to memory wastage.

Other options:

a) Index value of an array can be negative: This is incorrect. Array indices typically start from 0 and go up to the length of the array minus 1. Negative indices are not valid.

b) Elements are sequentially accessed: This is a characteristic of arrays, not a disadvantage. Sequential access means elements can be accessed one after the other, which is often efficient.

c) Data structure like queue or stack cannot be implemented: This is also incorrect. While arrays are not the optimal choice for implementing queues or stacks, it's possible to do so with additional logic.

Therefore, the most significant disadvantage of arrays in terms of memory efficiency is the potential wastage of space when the array is not fully utilized.

What is a data structure?

A. A programming language
B. A collection of algorithms
C. A way to store and organize data
D. A type of computer hardware
Correct answer is: C. A way to store and organize data

Which forms have a relation that contains information about a single entity?

A. a) 4NF
B. b) 2NF
C. c) 5NF
D. d) 3NF
Correct answer is: D. d) 3NF
A table is in its 3rd NF if it has already completed in 2NF, and non-key attributes are not dependent on any non-key attributes. This means that all non-key attributes must depend on primary key. When a table represents a single entity, the primary key will identify the instance row and all attributes in 3NF are dependent on the primary key. So, the primary key in the 3th NF captures the whole information of this single entity.

_____ operations do not preserve non-matched tuples.

A. a) Left outer join
B. b) Inner join
C. c) Natural join
D. d) Right outer join
Correct answer is: B. b) Inner join
Inner Join and Non-Matched Tuples

Inner join returns only the rows that have matching values in both tables. This means that any tuples that don't have a corresponding match in the other table are excluded from the result.

Other Join Types

Left outer join: Preserves all tuples from the left table, even if there are no matches in the right table.

Right outer join: Preserves all tuples from the right table, even if there are no matches in the left table.

Natural join: Similar to inner join, but only considers columns with the same name for matching.

In summary, while outer joins include unmatched tuples in the result, inner join strictly focuses on matching rows and discards any that don't have a corresponding match.

Procedural language among the following is __

A. a) Domain relational calculus
B. b) Tuple relational calculus
C. c) Relational algebra
D. d) Query language
Correct answer is: C. c) Relational algebra
Relational Algebra is a Procedural Language

Relational algebra is indeed a procedural language. This means it specifies a sequence of operations that must be performed in a specific order to achieve the desired result. It's like providing a recipe for manipulating data within a database.

Why not the others?

Domain relational calculus and tuple relational calculus are declarative languages. They specify what data is desired without specifying how to compute it.

Query language is a broad term that can encompass both procedural and non-procedural languages.

Key point: Relational algebra provides a step-by-step approach to manipulating data, making it a procedural language.

Join Our WhatsApp Channel! ×
Scroll to Top