GATE-CS-2005


Question 1
What does the following C-statement declare? [1 mark]
int ( * f) (int * ) ;
Cross
A function that takes an integer pointer as argument and returns an integer.
Cross
A function that takes an integer as argument and returns an integer pointer.
Tick
A pointer to a function that takes an integer pointer as argument and returns an integer.
Cross
A function that takes an integer pointer as argument and returns a function pointer


Question 1-Explanation: 
The steps to read complicated declarations : 1)Convert C declaration to postfix format and read from left to right. 2)To convert expression to postfix, start from innermost parenthesis, If innermost parenthesis is not present then start from declarations name and go right first. When first ending parenthesis encounters then go left. Once the whole parenthesis is parsed then come out from parenthesis. 3)Continue until complete declaration has been parsed. At First, we convert the following given declaration into postfix:
int ( * f) (int * )
Since there is no innermost bracket, so first we take declaration name f, so print “f” and then go to the right, since there is nothing to parse, so go to the left. There is * at the left side, so print “*”.Come out of parenthesis. Hence postfix notation of given declaration can be written as follows:
f * (int * ) int
Meaning: f is a pointer to function (which takes one argument of int pointer type) returning int . Refer http://www.geeksforgeeks.org/complicated-declarations-in-c/ This solution is contributed by Nirmal Bharadwaj.
Question 2

An Abstract Data Type (ADT) is:

Cross

Same as an abstract class

Cross

A data type that cannot be instantiated

Tick

A data type for which only the operations defined on it can be used, but none else

Cross

All of the above



Question 2-Explanation: 

Explanation:

The correct answer is (C) A data type for which only the operations defined on it can be used, but none else.

An Abstract Data Type (ADT) is a high-level description of a data type that defines a set of operations on the data and their behavior, without specifying the implementation details. It provides an abstraction and encapsulation of the data, allowing users to interact with the data through a defined set of operations.

Option (A) "Same as an abstract class" is not correct. While abstract classes in object-oriented programming languages can be used to define ADTs, not all ADTs are implemented using abstract classes. ADTs can be implemented in various ways, including using interfaces, data structures, or other language constructs.

Option (B) "A data type that cannot be instantiated" is also not entirely accurate. ADTs can be instantiated or used to create objects, but they typically restrict the direct access to the underlying data and enforce the use of operations defined on the ADT to manipulate and interact with the data. The key point is that an ADT provides a well-defined interface and hides the internal representation and implementation details.

Therefore, the correct answer is (C) A data type for which only the operations defined on it can be used, but none else.



Quiz of this Question
 

Question 3

A common property of logic programming languages and functional languages is:

Cross

both are procedural languages

Cross

both are based on λ-calculus

Tick

both are declarative

Cross

both use Horn-clauses



Question 3-Explanation: 

Explanation: 

The correct answer is (C) both are declarative.

Both logic programming languages and functional languages share the characteristic of being declarative languages. Declarative programming focuses on specifying what needs to be done rather than how to do it. In both logic programming and functional programming, the programmer describes the desired result or the properties of the solution without explicitly defining the steps or the order of execution.

In logic programming languages, such as Prolog, programs are built on a set of logical rules and facts. The programmer defines relationships between entities and the logic engine determines the appropriate answers by performing logical inference.

Functional programming languages, on the other hand, are based on the concept of functions as first-class entities. Programs are constructed by composing functions and applying them to data. Functional languages emphasize immutability and avoid side effects, allowing for a more declarative and concise programming style.

While options (A) and (B) are not true for both logic programming and functional programming languages, option (D) is partially correct. Logic programming languages, such as Prolog, commonly use Horn clauses as a way to express logical rules. However, not all functional languages use Horn clauses. Therefore, the most accurate answer is (C) both are declarative.

Quiz of this Question

Question 4

Which one of the following are essential features of an object-oriented programming language? (GATE CS 2005) (i) Abstraction and encapsulation (ii) Strictly-typedness (iii) Type-safe property coupled with sub-type rule (iv) Polymorphism in the presence of inheritance

Cross

(i) and (ii) only

Tick

(i) and (iv) only

Cross

(i), (ii) and (iv) only

Cross

(i), (iii) and (iv) only



Question 4-Explanation: 

Abstraction, Encapsulation, Polymorphism and Inheritance are the essential features of a OOP Language.

Question 5

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

Tick

An array of 50 numbers

Cross

An array of 100 numbers

Cross

An array of 500 numbers

Cross

A dynamically allocated array of 550 numbers



Question 5-Explanation: 

Explanation:

The program needs to store the frequency of each score above 50, which means it only needs to track the frequencies for scores ranging from 51 to 100. Since the scores are in the range [0..100], and the program is only interested in scores above 50, the possible scores to consider are from 51 to 100.

Given that the scores range from 51 to 100, there are 50 possible scores in this range. Therefore, using an array of 50 numbers is sufficient to store the frequencies for each score. Each element in the array can correspond to a specific score, where the index represents the score itself, and the value at that index represents the frequency.

For example, index 0 of the array can represent score 51, index 1 can represent score 52, and so on, up to index 49 representing score 100. By using an array of 50 numbers, the program can directly access the frequency for each score by its corresponding index.

Using an array of 50 numbers is a compact and efficient way to store the frequencies since it precisely matches the number of distinct scores above 50. It avoids unnecessary memory allocation and provides a direct mapping between scores and frequencies.

Therefore, the correct explanation is that option (A) An array of 50 numbers is the best way for the program P to store the frequencies of scores above 50.

See Question 1 of https://www.geeksforgeeks.org/data-structures-and-algorithms-set-22/

Quiz of this Question

Question 6

An undirected graph C has n nodes. Its adjacency matrix is given by an n × n square matrix whose (i) diagonal elements are 0's, and (ii) non-diagonal elements are l's. Which one of the following is TRUE?

Cross

Graph G has no minimum spanning tree (MST)

Cross

Graph G has a unique MST of cost n-1

Tick

Graph G has multiple distinct MSTs, each of cost n-1

Cross

Graph G has multiple spanning trees of different costs



Question 6-Explanation: 

Explanation:


The correct answer is (C).

An MST is a tree that connects all the vertices of a graph with the minimum possible total edge weight. An MST does not contain any cycles.

The adjacency matrix of an undirected graph shows which vertices are connected by edges. In this case, the adjacency matrix is given by an n × n square matrix whose diagonal elements are 0's and non-diagonal elements are 1's. This means that every vertex is connected to every other vertex by an edge.

Since every vertex is connected to every other vertex, there are multiple MSTs for this graph. Each MST will have n-1 edges, because there are n vertices and an MST cannot have any cycles. The cost of each MST will be n-1, because the cost of an edge is 1.

Therefore, the answer is (C).

https://www.geeksforgeeks.org/data-structures-and-algorithms-set-22/

See Question 2 of

Quiz of this Question

Question 7

The time complexity of computing the transitive closure of a binary relation on a set of n elements is known to be

Cross

O (n)

Cross

O (n log n)

Cross

O(n3/2)

Tick

O(n3)



Question 7-Explanation: 

Answer : (D)


Explanation:

The correct answer is (D), O(n3).

The transitive closure of a binary relation on a set of n elements can be computed using the Floyd–Warshall algorithm. This algorithm has a time complexity of O(n3).

The other options are incorrect. Option (A), O(n), is the time complexity of simply iterating over the set of n elements. Option (B), O(n log n), is the time complexity of sorting the set of n elements. Option (C), O(n3/2), is not a valid time complexity. https://www.geeksforgeeks.org/data-structures-and-algorithms-set-22/

See question 3 of

Quiz of this Question

Question 8

Let A, B and C be non-empty sets and let X = (A - B) - C and Y = (A - C) - (B - C). Which one of the following is TRUE?

Tick

X = Y

Cross

X ⊂ Y

Cross

Y ⊂ X

Cross

none of these



Question 8-Explanation: 

Answer : (A)
 

Explanation:

The correct answer is (A), X = Y.

Let's take a look at the sets X and Y again.

  • X = (A - B) - C
    • This means that X is the set of elements that are in A but not in B, and also not in C.
  • Y = (A - C) - (B - C)
    • This means that Y is the set of elements that are in A but not in C, and also not in the set of elements that are in B but not in C.

In other words, X is the set of elements that are in A but not in B and C, and Y is the set of elements that are in A but not in the set of elements that are in B but not in C.

Since X and Y are both the set of elements that are in A but not in B and C, then X = Y.

Therefore, the answer is (A).

Venn diagram

We can solve it by making

Quiz of this Question

Question 9
The following is the Hasse diagram of the poset [{a, b, c, d, e}, ≤] GATECS2005Q9 The poset is
Cross
not a lattice
Tick
a lattice but not a distributive lattice
Cross
a distributive lattice but not a Boolean algebra
Cross
a Boolean algebra


Question 9-Explanation: 
It is a lattice but not a distributive lattice.

Table for Join Operation of above Hesse diagram

V |a b c d e
________________
a |a a a a a
b |a b a a b
c |a a c a c
d |a a a d d
e |a b c d e

Table for Meet Operation of above Hesse diagram

^ |a b c d e
_______________
a |a b c d e
b |b b e e e
c |c e c e e
d |d e e d e
e |e e e e e

Therefore for any two element p, q in the lattice (A,<=)

p <= p V q ; p^q <= p

This satisfies for all element (a,b,c,d,e).

which has 'a' as unique least upper bound and 'e' as unique 
greatest lower bound.

The given lattice doesn't obey distributive law, so it is 
not distributive lattice,

Note that for b,c,d we have distributive law

b^(cVd) = (b^c) V (b^d). From the diagram / tables given above 
we can verify as follows,

(i) L.H.S. = b ^ (c V d) = b ^ a = b

(ii) R.H.S. = (b^c) V (b^d) = e v e = e

b != e which contradict the distributive law. 
Hence it is not distributive lattice.

so, option (B) is correct. 
Question 10

Let G be a simple connected planar graph with 13 vertices and 19 edges. Then, the number of faces in the planar embedding of the graph is

Cross

6

Tick

8

Cross

9

Cross

13



Question 10-Explanation: 

An undirected graph is called a planar graph if it can be drawn on a paper without having two edges cross and such a drawing is called Planar Embedding. We say that a graph can be embedded in the plane, if it planar. A planar graph divides the plane into regions (bounded by the edges), called faces. Graph K4 is planar graph, because it has a planar embedding as shown in figure below. 

"P_graph" 

Euler's Formula : For any polyhedron that doesn't intersect itself (Connected Planar Graph),the 

• Number of Faces(F) 
• plus the Number of Vertices (corner points) (V) 
• minus the Number of Edges(E), 
always equals 2. This can be written: F + V − E = 2. 

Solution: 
Here as given, F=?,V=13 and E=19 
-> F+13-19=2 
-> F=8 
So Answer is (B). 

This solution is contributed by Nirmal Bharadwaj 

We can apply Euler's Formula of planar graphs. The formula is v − e + f = 2.

There are 90 questions to complete.
  • Last Updated : 11 Oct, 2021

Similar Reads