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.
Which data structure is 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?
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.
Which forms have a relation that contains information about a single entity?
_____ operations do not preserve 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 __
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.
Which of the following command is correct to delete the values in the relation teaches?
DELETE FROM teaches WHERE Id = 'Null';: This command would only delete rows where the Id column has a NULL value. It wouldn't delete all rows.
REMOVE TABLE teaches;: There's no standard SQL command named REMOVE.
DROP TABLE teaches;: This command would delete the entire table structure, including its data and definition, which is typically not desired when you just want to clear the data.
So, the simple and effective way to delete all data from the teaches table is by using DELETE FROM teaches;.
Which of the following set should be associated with weak entity set for weak entity to be meaningful?
A weak entity set must be associated with an identifying set for it to be meaningful.
Here's a breakdown:
Weak Entity Set: An entity set that cannot exist independently and depends on another entity set (strong entity set) for its existence.
Identifying Set: A set of attributes in a strong entity set that uniquely identifies each entity in the weak entity set.
Essentially, a weak entity set needs a "parent" strong entity set to provide it with a unique identifier. This is because a weak entity set doesn't have sufficient attributes on its own to form a primary key.
Example:
Strong Entity Set: Employee (Employee_ID, Employee_Name, Department)
Weak Entity Set: Dependent (Dependent_Name, Relationship, Employee_ID)
Which command is used to remove a relation from an SQL?
Here's a breakdown of why the other options are incorrect:
DELETE: This command removes rows (tuples) from a table, but it doesn't remove the table itself.
PURGE: This command is not a standard SQL command. It might exist in specific database systems with particular functionalities, but it's not generally used for removing tables.
REMOVE: This is also not a standard SQL command for removing tables.
So, DROP TABLE is the correct choice for permanently deleting a table from a database.