Search Previous Year Questions

Find real questions from previous competitive exam papers with answers and solutions.

Leave the keyword blank to browse saved questions for your selected exam, newest papers first. Add a keyword, year or topic to narrow the results.

Browse complete papers
Showing 10 question(s)
Clear

Question 131

HPCL Engineer 2017• Professional Knowledge

Two concurrent processes P and Q execute the following code.

Process P:

While (True){

W:_____

Print(‘0’); print(‘0’);

X:____

}

Process q;

While (True){

Y;

print(‘1’); print(‘1’);

Z:_____

}

Given S and T are binary semaphore variables, and P() and V() as standard “wait” and “signal” functions respectively. What should be the semaphore operations W, X, Y, and Z for the output string: 11001100…?

  1. AOption (a)

    W = P (T), X = V(S), Y = P(S), Z = V (T), S = T = 1

  2. BOption (b)

    W = P (T), X = V(T), Y = P(S), Z = V(S), S = T = 1

  3. COption (c)

    W = P (T), X = V (T), Y = P(S), Z = V(S), S = 1, T = 0

  4. DOption (d)

    W = P(T), X = V(S), Y = P(S), Z = V(T), S = 1, T = 0

View answer & explanation

Correct answer

Answer: (d)D.

W = P(T), X = V(S), Y = P(S), Z = V(T), S = 1, T = 0

Why this answer is correct

For the output string: 11001100…….

We have to take,

For process P:

W = P(T)

X = V (S)

For process q:

Y = P(S)

Z = V (T), where, S = 1 and T = 0

So, in this when we try to execute process P, it will go to P(T) as T = 0, it cannot enter into critical section.

So, we try to execute process Q.

It will go to P(S), As S = 1, so process q will enter into critical section and make S = 0 and print 11, then after its exit from critical section only, we can execute process P and print 00.

So, both process P and Q depends on each other to enter the critical section. In this way, it prints the sequence 11001100……

Question 132

HPCL Engineer 2017• Professional Knowledge

Consider the following segment of codes related to process creation. How many times the message “child process created” will be printed?

#include<stdio.h>

void main() {

fork(); fork(); fork();

printf(“child process created”);

}

  1. AOption (a)

    3

  2. BOption (b)

    7

  3. COption (c)

    9

  4. DOption (d)

    8

View answer & explanation

Correct answer

Answer: (d)D.

8

Why this answer is correct

Concept:

Fork system call is used to create a new process also called as child processes.

Formula:

With n fork system calls, number of child processes created are 2n – 1.

Printf statement will be executed 2n times with n system calls.

Explanation:

Here there are 3 fork system calls in the given program.

So, 23 times printf statement will be executed.

i.e. 8 times “child process created” will be printed.

Question 133

HPCL Engineer 2017• Professional Knowledge

Consider a cache memory organization with m lines in which the cache is divided into v sets, each of which consists of k lines. The set associative mapping technique reduces to direct mapping when:

  1. AOption (a)

    v = m and k = 1

  2. BOption (b)

    v = 1 and k = m

  3. COption (c)

    v = m and k = m

  4. DOption (d)

    v = 1 and k = 1

View answer & explanation

Correct answer

Answer: (a)A.

v = m and k = 1

Why this answer is correct

Answer: Option 1

Explanation: 

We have given a cache memory organization with m lines in which the cache is divided into v sets, each of which consists of k lines.

Consider m = 8, v = 4, k = 2

Representation for this organization is:

To reduce it to direct mapping:

Make v = m, because in both direct mapping and set associative mapping, we have to take the mod operation to find the line number and set number respectively.

Also, make k = 1, because each set starts behaving like a line as in the case of direct mapping.

Question 134

HPCL Engineer 2017• Professional Knowledge

If a connected graph G does not contain any vertex whose removal disconnects the rest of the graph, then G is called;

  1. AOption (a)

    Diagraph

  2. BOption (b)

    Separable graph

  3. COption (c)

    Biconnected graph

  4. DOption (d)

    Forest

View answer & explanation

Correct answer

Answer: (c)C.

Biconnected graph

Why this answer is correct

An undirected graph is called biconnected if there are two vertex – disjoint paths between any two vertices. A biconnected graph is connected and non-separable graph means, there is no vertex in the graph whose removal disconnects the graph.

Example:

This graph doesn’t have any vertex whose removal disconnects this graph.

Question 135

HPCL Engineer 2017• Professional Knowledge

The data type of the variable “var 1” declared in the following ‘C’ language statement is:

unsigned var1;

  1. AOption (a)

    float

  2. BOption (b)

    int

  3. COption (c)

    double

  4. DOption (d)

    char

View answer & explanation

Correct answer

Answer: (b)B.

int

Why this answer is correct

When we declare a variable as unsigned, it doesn’t mean that data type is invalid. It means that the data type contains only positive values. Negative values are not allowed in that data type.

Unsigned data types include:

int, char, short, long.

In C programming language, unsigned is a shortcut to unsigned int data type. That is when we declare a variable as unsigned var; in C language then it by default consider it as int.

Question 136

HPCL Engineer 2017• Professional Knowledge

In a B-tree of order m (m >1), every non-leaf node (except root node) has the number of children between:

  1. AOption (a)

    |m/2| and m

  2. BOption (b)

    m/2 and m

  3. COption (c)

    \(\left\lfloor {m/2} \right\rfloor ,,and,,m\)

  4. DOption (d)

    \(\left\lfloor {m/2} \right\rfloor ,,and;\left| {m/2} \right|\)

View answer & explanation

Correct answer

Answer: (a)A.

|m/2| and m

Why this answer is correct

Concept:

B- Trees provide a multilevel access structure that is a balanced tree structure in which each node is at-least half full. Each node in a B- tree of order p can have at most p – 1 search values.

Explanation:

Each node in a B- Tree contains a number of ascending values {k1, k2, k3, ……..km-1} and pointers {p1, p2, …..pm} where m determines the maximum number of children a node can point to. Value m is the order of the tree.

To maintain the binary search tree property, B- Tree nodes store key values such that all values in the subtree pointed to by p1 are smaller than k1.All values in the subtree pointed to by pi are greater than or equal to ki and smaller than ki-1.

Properties of a m- way B – Tree:

  1. All leaf nodes must be at same level

  2. All nodes except root node must have at-least [m/2]-1 keys and maximum m-1 keys.

  3. All non – leaf nodes except the root node must have at least m/2 children.

  4. Every node contains at most m children.

  5. root must have at least 2 nodes.

Example:

Question 137

HPCL Engineer 2017• Professional Knowledge

What is the output when the following segment of ‘C’ code is executed?

void main(){

float a = 123.456;

printf(“%7.2f, %7.3f, %12e”,a,a,a);

}

  1. AOption (a)

    123.450, 123.4560, 1.234560e +02

  2. BOption (b)

    123.45, 123.4560, 1.234560e +02

  3. COption (c)

    123.456000, 123.456, 0.1234560e +03

  4. DOption (d)

    123.45, 123.456, 1.234560e +02

View answer & explanation

Correct answer

Answer: (d)D.

123.45, 123.456, 1.234560e +02

Why this answer is correct

In case of C programming language,

%f stands for float.

%7.2f means to print a float in a field atleast 7 spaces wide but have two digits only after decimal point. So, it will display 123.45.

%7.3f means to print a float in a field atleast 7 spaces wide but after decimal point must have only 3 digits. So, it will display 123.456

%12e – e is used for scientific notation. One digit before the decimal point and must have exponent for scaling purpose. So, it will display 1.234560e +02

Question 138

HPCL Engineer 2017• Professional Knowledge

Let K2, 2 be a complete bipartite graph given below. Which of the following is the total number of paths of length 3 from vertex 1 to vertex 4?

  1. AOption (a)

    1

  2. BOption (b)

    2

  3. COption (c)

    3

  4. DOption (d)

    4

View answer & explanation

Correct answer

Answer: (d)D.

4

Why this answer is correct

Concept:

  • A graph G is bipartite if its vertex set can be partitioned into two sets X and Y in such a way that every edge of G has one end vertex in X and the other in Y. In this case, X and Y are called the partite sets.
  • A complete bipartite graph is a graph whose vertices can be partitioned into two subsets X and Y such that no edge has both endpoints in the same subset, and every possible edge that could connect vertices in different subsets is part of the graph

K2,2

1 → 3 → 2 → 4

1 → 4 → 2 → 3

2 → 3 → 1 → 4

3 → 1 → 4 → 2

There are four distinct paths from vertex 1 to vertex 4 which has length 3:

Important point:

Since starting and ending vertex is not specified and very path from vertex 1 to vertex 4 is valid. There 1 → 4 → 2 → 3, 2 → 3 → 1 → 4

and 3 → 1 → 4 → 2 are valid path from vertex 1 to vertex 4 which has length 3.

A path should have distinct edge and vertex.

Question 139

HPCL Engineer 2017• Professional Knowledge

The number of tokens in the following ‘C’ language statement is:

printf(“The number of tokens are %d”, &tcount);

  1. AOption (a)

    8

  2. BOption (b)

    11

  3. COption (c)

    10

  4. DOption (d)

    9

View answer & explanation

Correct answer

Answer: (a)A.

8

Why this answer is correct

Tokens are the smallest elements of a program, which are meaningful to the compiler. Tokens types are keywords, identifiers, constant, strings, operators etc.

Number of tokens in the given C language statement is:

Total 8 tokens are possible in this.

1- printf

2- (

3- “The number of tokens are %d”

4- ,

5-&

6- tcount

7-)

8- ;

Question 140

HPCL Engineer 2017• Professional Knowledge

Which of the following file-type arguments is used in fopen() library function to open a new file for both reading and writing, and destroys the file if a file with the specified file-name already exists in the current directory?

  1. AOption (a)

    “a+”

  2. BOption (b)

    “r+”

  3. COption (c)

    “w”

  4. DOption (d)

    “w+”

View answer & explanation

Correct answer

Answer: (d)D.

“w+”

Why this answer is correct

fopen() opens the file whose pathname is the string pointed to by filename.

There are two parameters in this:

Filename- this is name of the file to be opened

Mode or file type argument – it contains a file access mode.

Various type of file access methods or arguments are:

“r” – opens a file for reading. That file must exist.

“w” – it creates an empty text file for writing. If the file already exists, its contents are destroyed, and file is considered as new file.

“a”- appends to a file. File created if it does not exist.

“r+” – opens a file to update both reading and writing. File must exist

“a+” – Opens a file for reading and append at the end of the file.

“w+” – creates a new file for both reading and writing and destroys the file if a file with the specified file-name already exists in the current directory.