Which of the below statement is FALSE?
1.Insertion sort is an example ofnon-stable sort.
2.Selection sort is quadratic in both the worst and theaverage case and requires no extra memory.
3.Bubble sort requires extra memory.
-
Solution
Bubble sort requires extra memory and selection sort is quadratic in both the worst and average case and no extra memory is required. Insertion sort is an example of stable sort.
Consider the following code fragment :
if (fork() ==0)
{
a =a +10;
printf (“%d”, a);
}
else printf(“%d”, a);
What will be the output of above code if initial value of a is 10 ?
-
Solution
Parent process will print 10 and child process will print 20
Consider the following C program :
char c [10]
char * s = “string”;
int str-length= strlen (s);
for (i = 0; i < length; i++)
c [i]= s [length –i];
print f(“% s”, c);
The output of program is
-
Solution
As s is character pointer in above program and c is character variable. In c, we cannot assign the value of pointer variable.So no output will be printed or garbage value can be printed
What will be the output of the following C program?
main ( )
{
const int x = 5;
constint * ptrx;
ptrx = &x;
*ptrx = 10;
printf (“%d”, x);
}
-
Solution
In the given program, *ptr x is declared as a constant variable and the statement *ptr x = 10 is trying to change the value of * ptr x.It is known that a variable, declared as a constant, cannot bemodified. So, this program will give error.
Consider the following C function :int f (int n)
{
static int i = 1;
if (n >= 5)
return n:
n =n + 1;
i ++;return f(n);
}
The value returned by f(1) is _________
-
Solution
The output will be 7. Here, it is declared as static. So, the new value of i will be persist in the function. It will not be reinitialized by 1
Consider the following function that expects a non-negative integer argument:unsigned int h (unsigned int n)
{
unsigned int m;
m =0 ;
while(n > 0) {
m = (m *10) + (n %10):
n = n/10;
}
return m;
}
If we call h(4321), the given program will print ________
-
Solution
1234
In the figure, as long as X1= 1 and X2= 1, the output Q will be
-
Solution
There will be toggle condition continuously
Consider the following k-map:
What is the nominal form of above K-map?
(1)\(\overline{A}\overline{B}+CD\)
(2)\(C\overline{D}+\overline{A}\overline{B}\)
(3)\(CD+\overline{A}\overline{B}D\)
(4)\(\overline{A}D+AC\overline{D}\)
-
Solution
If there are 64 segments, each of size 2 kB, then the logical address should have
-
Solution
To specify a particular segment, 6 bits arerequired.(since 26= 64). Having selected a page, to select a particularbyte oneaddress11 bits (since 211= 2 kB).Sototally 6 + 11 =17 bits are needed
A CPU has a five-stage pipeline and runs at a frequency of 1 GHz. Instruction fetch happens in the first stage of the pipeline. Aconditional branch instruction computes the target address and evaluates the condition in the third stage of the pipeline. The processor stops fetching new instructions following a conditional branch until the branch outcome is known. A program executes 109 instructions out of which 20% are conditional branches. If each instruction takes one cycle to complete on average,the total execution time of the program is
-
Solution
As given,there is no conditional loop for the 80% of 109 instructions, thus only single cycle is required for them and rest require 2 extra cycles.
Thus, the total timerequires= Time of one cycle ×\(\left ( \frac{80}{100}\times 10^{9}\times 1+\frac{20}{100}\times 10^{9}\times 2 \right )\)
\(=\frac{1}{10^{9}}\left ( \frac{80}{100}\times 10^{9}\times 1+\frac{20}{100}\times 10^{9}\times 2 \right )=1.2\: s\)