Sunteți pe pagina 1din 8

CoCubes Practice Sheet-1

Programming Questions:

Q:1 Implement the following function:

int AreaOfTriangle(int a,int b,int c);

The function accepts 3 integer a,b,c as its argument which are sides of a triangle. Implement the
function to calculate the area of triangle and return the square of are.

(area of triangle)​2 ​= (s)*(s-a)*(s-b)*(s-c)

Where, semiperimeter (s) = (a+b+c)/2

Note:

1. Computed value lies within integer range.


2. Consider division operation as integer division.

Example:

Input: a: 5 b: 4 c: 3

Output: 36

Q2. Steel is classified on the basis of following conditions:

1. Hardness must be grater than 60


2. Carbon content must be grater than 0.8
3. Tensile strength must be grater than 5700

Implement the following function:

Char ClassifyGivenSteel(int h, float c,int ts);

The function accepts three integers h hardness of steel, c carbon content in steel and ts tensile
strength of steel as its argument. Implement the function to classify the steel according to the
following rules:

● If all three conditions are satisfied, then the steel is of class ‘A’.
● If condition 1 and 2 are satisfied, then the steel is of class ‘B’.
● If condition 1 and 3 are satisfied, then the steel is of class ‘C’.
● If condition 2 and 3 are satisfied, then the steel is of class ‘D’.
● If only condition is satisfied, then the steel is of class ‘E’.
● If none of three conditions are satisfied, then the steel is of class ‘F’.

Return the class of the steel.

Assumption: h>0 , ts>0 and 0<c<=1

Example:
Input: h: 70 c: 0.9 ts: 5800

Output: A

Objective Questions:

1. Consider a situation when ‘p’ processes share ‘r’ resources of the same type. The maximum
requirement of each process doesn’t known, their maximum requirement is always less than
p+r. In such situation deadlock:
A) has to occur
B) can never occur
C) none of the mentioned options
D) may occur
2. Which of the following statements is true about storage class of variable?
1) It tells us where the variable is to be stored.
2) It tells us about the initial value of the variable.
3) It tells us about the scope of the variable.
4) It tells us about the life of variable.
Choose the correct answer from the options given below.
A) Only 2 and 4
B) Only 1, 2 and 3
C) All 1,2,3 and 4
D) Only 1 and 2
3. Which of the following is a legal declaration of Floating-point literal in C++?
A) 510E
B) 210f
C) .e55
D) 314159E-5L
4. At least how many 2-input NAND gates are required to implement the given function?
F = (a’+b’)(c+d)
A) 6
B) 3
C) 5
D) 4
5. Suppose we are given two strings, where one is pattern(P) and the other is text(T) and we
have to find the number of occurrences of P in T using the Brute-force solution. Which of the
following options is the correct time complexity for the execution of the solution?
A) None of the mentioned options
B) O(P)
C) O(|P|.|T|)
D) O(T)
6. Which of the following is the correct algorithm for implementing a leaky bucket algorithm if
the traffic consists of variable-length packets?
A) 1. Initialize a counter to n-1 at the tick of the clock.
2. If n < the size of the packet, send the packet and decrement the counter by the packet size.
Repeat this step until n is equal to the packet size.
3. Reset the counter and go to step 1.

B) 1. Initialize a counter to 0 at the tick of the clock.


2. If n < the size of the packet, send the packet and decrement the counter by the packet size.
Repeat this step until n is greater than the packet size.
3. Reset the counter and go to step 1.

C) 1. Initialize a counter to n at the tick of the clock.

2. If n > the size of the packet, send the packet and decrement the counter by the packet size.
Repeat this step until n is smaller than the packet size.
3. Reset the counter and go to step 1.

D) 1. Initialize a counter to n at the tick of the clock.

2. If n > the size of the packet, send the packet and decrement the counter by the packet size.
Repeat this step until n is equal to the packet size.
3. Reset the counter and go to step 1.

7. For which of the following purposes, FTP uses well-known TCP port 21?
A) Data Control Process
B) Server Control Process
C) Control Connection
D) Data Connection
8. Which of the following statements is TRUE regarding a simple connected undirected graph
with more than 2 vertices?
A) At least two vertices have the same degree.
B) At least three vertices have the same degree.
C) All the vertices have the same degree.
D) No two vertices have the same degree.
9. What is the maximum number of spanning trees that the complete undirected graph with n
nodes have?
A) n
B) n​n-1
C) n​n-2
D) n​n
10. Let ​A(p, q, r)​ and ​B(s, t, u)​ be two relations in which s is the foreign key of B that refers to
the primary key of A. Now, if we want to perform the following four operations, then which
of the following is true about the referential integrity constraint?
1) Insert into A
2) Insert into B
3) Delete from A
4) Delete from B
A) None of them will cause a violation
B) Operation 1 and 3 will cause a violation
C) Operation 2 and 3 will cause a violation
D) All of them will cause violation
11. In C language, which of the following can ​not​ be a character literal?
A) Plain character
B) None of the mentioned options
C) Universal character
D) Escape sequence
12. In which of the following tier of 3-tier architecture, the end users are operated on?
A) Data tier
B) Presentation Tier
C) Middle Tier
D) Application Tier
13. Which of the following problems can be solved by Dijkstra’s banking algorithm in an
operating system?
A) Deadlock recovery
B) Mutual Exclusion
C) Deadlock Avoidance
D) Context switching
14. Which of the following statements is correct about flooding?
1. Flooding always selects the shortest path.
2. In selective flooding, the packets are sent to those lines that are going approximately in
the right direction

Choose the correct answer from the options given below.


A) Only 2
B) Both 1 and 2
C) Neither 1 nor 2
D) Only 1
15. If LASTPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder and
preorder traversal respectively of a complete binary tree, then which of the following is
always true?
A) LASTIN = LASTPRE
B) None of the mentioned options
C) LASTIN = LASTPOST
D) LASTPRE = LASTPOST
16. Consider the lengths of the sorted sequences A, B, C, D and E are 20, 24, 30, 35 and 50
respectively. If they are required to be merged in a single sequence by taking two sequences
at a time, what will be the number of comparisons required in the worst case by the optimal
algorithm?
A) 256
B) 544
C) 358
D) 423
17. Suppose X is a two-dimensional array declared as follows:
X: array{1…..10][1……..15] of integer;
In the array suppose each integer takes one memory location if the array is stored in row-major
order and the first element of the array is stored at location 100. Which of the following is
the address of the element x[i][j]?
A) 10i + j + 89
B) 10i + j + 100
C) i + 15j + 89
D) j +15j + 100
18. Splay trees are similar to which of the following trees?
A) Red-black trees
B) AVL tree
C) 2-3 trees
D) Binary Search trees
19. Which of the following is correct about trivial dependency?
A) A dependency X -> Y in a relation schema R is said to be a trivial dependency if there is
any attribute A, where A is a proper subset of X such that A->Y
B) A dependency X -> Y in a relation schema R is said to be a trivial dependency if there is
no A, where A is a proper subset of X such that A->Y
C) An instance r of R satisfies trivial dependency X->Y, if and only if two tuple t​1​ and t​2​ in r
that has t​1​[X] = t​2​[X]
D) X->Y is satisfied by all relations having attribute X and XY->X is satisfied by all relations
having attribute X and Y.
20. In DBMS, which of the following ensures the data consistency?
A) Application Programmer
B) Isolation
C) Serializability
D) Recovery management
21. Which of the following is an external level in the architecture of a database system?
A) Physical level
B) Conceptual level
C) Logical level
D) View level
22. If a system uses round robin algorithm for CPU scheduling of ‘n’ processes, then which of the
following data structure is best suited ready queue of the processes?
A) Stack
B) Circular Queue
C) Tree
D) Queue
23. In the analysis of the algorithm, approximate relationship between the size of the job and
the amount of work required to do is expressed by using____________.
A) Differential equation
B) Central tendency
C) Order of execution
D) Order of magnitude
24. Consider a sliding window ARQ schema. The size of the transmitter’s and receiver’s window
respectively are ‘m’ and ‘n’. What would be the minimum requirement of distinct sequence
numbers to ensure correct operation of the ARQ scheme?
A) Maximum of m, n
B) Minimum of m, n
C) m+n
D) mn
25. Which of the following is the tightest upper bound that represents the time complexity of
inserting an object into a binary search tree of M nodes?
A) O(1)
B) O(log M)
C) O(M)
D) O(M log M)
26. Consider the minimum weight of all the edges in an undirected connected graph is ‘m’ and
‘e’ be a particular edge of that graph. Which of the following statements is ​FALSE​?
A) There must be a minimum spanning tree containing e.
B) Every spanning tree must have an edge of weight m.
C) e is present in every minimum spanning tree.
D) If e is not in a minimum spanning tree T then in the cycle formed by adding e to T, all
edges have the same weight.
27. Consider the following set of functional dependencies and choose the option which is
correct with respect to that.

A = {P -> Q, P -> S, QR -> T, Q -> RS, S -> P, T -> Q}

B = {P -> Q, Q -> P, P -> T, Q -> S}

A) Q canonically covers P
B) Both P and Q canonically covers each other
C) P canonically covers Q
D) None of them canonically covers each other
28. The concept of hierarchical classification is supported by _________
A) Encapsulation
B) Inheritance
C) Abstraction
D) Polymorphism
29. Consider the following statements:
1. As the number of entries in the hash table increases, the number of collision increase
2. The worst time complexity of quicksort is O(n​2​).
3. Binary Search implemented using a linked list is efficient.
4. A real-world example of queue can be a two-way single road.

Which of the following statements are correct?

A) Only 2, 3 and 4
B) Only 1 and 2
C) Only 1 and 4
D) All 1, 2, 3 and 4
30. What is the maximum data rate of a channel for a noiseless 5-kHz binary channel?
A) 10000bps
B) 6000bps
C) 2500bps
D) 5000bps
31. What will be the output of the following pseudocode for a=5, b=10?

​int​ c = a - b

for​ i = ​1​ to ​4
c = c-a
​for​ j = ​3​ to i
a = a+i
c = c+a+j
end ​for
end ​for
print c
A. 393
B. None of the mentioned option
C. 92
D. 18
32. What will be the output of the following code?

​#include​<iostream>

using​ ​namespace​ ​std​;


int​ ​&​dosomething​(){
​int​ a = ​5​;
​return​ a;
}
int​ ​main​(){
​int​ &x = ​dosomething​();
x = x-​2​;
cout<<​dosomething​();
​return​ ​0​;
}
A. -2
B. Runtime Error
C. Compile time error
D. 3
33. Which of the following is used to link the devices in a building?
A. None of the mentioned options
B. Metropolitan area network
C. Local area network
D. Wide area network
34. In a hash table, there are 10 buckets and linear probing is used to remove collisions. The key
values are integers and the hash function used is key mod 10. If the values 43, 165, 62, 123,
142 are inserted in the table, then in which of the following locations, the key value 142
would be inserted?
A. 6
B. 4
C. 2
D. 3
35. Which of the following approaches is taken into consideration during Binary search
operation?
A. Dynamic programming approach
B. Backtracking approach
C. Greedy approach
D. Divide and Conquer approach
36. Suppose the initial value of a counting semaphore is 7. What will be the resultant value of
the semaphore after completely performing 20 P operations and 15 V operations?
A. 1
B. 7
C. 12
D. 20
37. Consider an entity set vehicle that is further classified as car and bike. This process is known
as:
A. Specialization
B. Constraint generalization
C. Generalization
D. Inheritance
38. In DBMS, E-R modelling technique follows:
A. Top-down approach
B. Left-right approach
C. None of the mentioned options
D. Bottom-up approach
39. It is given that the clock input applied to a cascade Mod-6 & Mod-4 counter is 48KHz, what
would be the output of the cascade arrangement?
A. 4.8 KHz
B. 8 KHz
C. 2 KHz
D. 12 KHz

Answers: 1 (d) 2 (c) 3(d) 4(d) 5(d) 6(e) 7(c) 8(a) 9(c) 10(c) 11(b) 12(b) 13(c) 14(b) 15(b) 16(c) 17 (b)
18(d) 19 (a) 20(c) 21(d) 22(b) 23(d) 24(c) 25(c) 26(c) 27(b) 28(d) 29(b) 30(a) 31(d) 32(b) 33(c)
34(a) 35(d) 36(c) 37(a) 38(a) 39(c)

S-ar putea să vă placă și