DSSSB TGT / PGT · Topic-wise previous year questions
Computer Science Previous Year Questions (page 39)
2444 Computer Science questions asked in DSSSB TGT / PGT previous year papers, each with the correct answer and explanation. Read them free on UTpaper, or attempt the full papers as timed online tests.
Which of the following is NOT a benefit of distributed systems?
AScalability
BHigh communication latency
CResource sharing
DFault tolerance
Show answerHide answer
Correct answer: (B) High communication latency
Explanation
High communication latency is a drawback of distributed systems caused by network delays. Scalability, resource sharing and fault tolerance are their main benefits.
The schema is the overall logical design (structure) of the database, which rarely changes. An instance is the data stored in the database at a particular moment.
In an acyclic graph directory structure, what is a common method used to implement shared
directories or files?
AFile duplication
BSymbolic (soft) links
CHard links
DDirectory pointers
Show answerHide answer
Correct answer: (B) Symbolic (soft) links
Explanation
In an acyclic-graph directory, a shared file or subdirectory is usually implemented with a link, a special directory entry (symbolic link) that holds the path of the real file, so the same file appears in several directories without copying.
What is the ARP reply's scope in terms of message type?
AAnycast
BUnicast
CMulticast
DBroadcast
Show answerHide answer
Correct answer: (B) Unicast
Explanation
An ARP request is broadcast to all hosts on the LAN, but the reply is sent unicast directly to the requesting host, whose MAC address is already known from the request.
Which technology is commonly used in Wi-Fi to enhance signal range and reliability?
AMIMO (Multiple Input Multiple Output)
BWEP (Wired Equivalent Privacy)
CTDMA (Time Division Multiple Access)
DCDMA (Code Division Multiple Access)
Show answerHide answer
Correct answer: (A) MIMO (Multiple Input Multiple Output)
Explanation
MIMO uses several antennas at the transmitter and receiver (spatial multiplexing, diversity), which raises throughput, range and reliability in 802.11n/ac/ax Wi-Fi. WEP is an old security protocol, not a range technique.
In which scheduling algorithm does the disk head move in one direction, satisfying all
requests until it reaches the end, and then reverses direction?
ASCAN
BSSTF
CLOOK
DFCFS
Show answerHide answer
Correct answer: (A) SCAN
Explanation
SCAN (elevator algorithm) moves the head in one direction serving requests all the way to the end of the disk, then reverses. LOOK reverses at the last request instead of the disk end.
How does the receiver handle out-of-order frames in Selective Repeat?
ARequests retransmission of all frames
BSends a cumulative acknowledgment
CBuffers them until all missing frames arrive
DDiscards them immediately
Show answerHide answer
Correct answer: (C) Buffers them until all missing frames arrive
Explanation
In Selective Repeat the receiver accepts and buffers correctly received out-of-order frames, and only the missing frames are retransmitted; it then delivers them in order. Go-Back-N is the protocol that discards them.
____________ is NOT allowed in a SQL:1999 view definition.
AUse of subqueries
BUse of nested queries
CUse of aggregate formulas
DUse of ORDER BY clause
Show answerHide answer
Correct answer: (D) Use of ORDER BY clause
Explanation
A view is a virtual table, and standard SQL (SQL:1999) does not allow ORDER BY in the view's defining query; ordering is applied when the view is queried. Subqueries and aggregates are allowed.
Select the correct SQL statement which will correctly insert a new row into the Customer table
with only the CustomerID, Name, and Product columns specified, assuming the table allows
NULLs for other columns.
AINSERT Customer SET CustomerID=101, Name='Alice', Product='Pen';
BINSERT INTO Customer VALUES (101, 'Alice', 'Pen');
CINSERT INTO Customer (101, 'Alice', 'Pen');
DINSERT INTO Customer (CustomerID, Name, Product) VALUES (101, 'Alice', 'Pen');
To insert values into only some columns, list those columns after the table name and give matching values: INSERT INTO table (cols) VALUES (...). Option B gives no column list, so it expects values for all columns.
Which SQL statement is used to update data in a table?
ACHANGE
BMODIFY
CUPDATE
DSET
Show answerHide answer
Correct answer: (C) UPDATE
Explanation
UPDATE ... SET ... WHERE ... is the DML command that changes existing rows. SET is only a clause of UPDATE, and MODIFY is used with ALTER TABLE in some systems.
What does the TCP service model guarantee about the order of data delivery?
AData is delivered in the order it is transmitted.
BData is not guaranteed to arrive in any specific order.
CData may arrive out of order and is handled by the application layer.
DData is delivered as fast as possible.
Show answerHide answer
Correct answer: (A) Data is delivered in the order it is transmitted.
Explanation
TCP provides a reliable, in-order byte stream: sequence numbers let the receiver reorder segments, so the application gets data in the same order it was sent. UDP gives no ordering guarantee.
class Parent {
protected void protectedMethod() {
System.out.println("Protected method in Parent");
}
}
class Child extends Parent {
public void childMethod() {
protectedMethod();
}
}
public class Test {
public static void main(String[] args) {
Child child = new Child();
child.childMethod();
}
}
What will happen when the code is executed?
AThe code will compile and print 'Protected method in Parent'.
BCompilation Error: The protectedMethod is not visible in the Child class.
CCompilation Error: childMethod is not visible due to access restrictions.
DRuntime Error: Cannot access protectedMethod from the Child class.
Show answerHide answer
Correct answer: (A) The code will compile and print 'Protected method in Parent'.
Explanation
A protected member is accessible in a subclass, so Child can call protectedMethod() directly. The code compiles and prints "Protected method in Parent".
What happens when the following code executes?
#include <stdio.h>
int main() {
char buffer[50];
int n = sprintf(buffer, "Hello, World!");
printf("%d %s", n, buffer);
return 0;
}
APrints '13 Hello'
BPrints '12 Hello'
CPrints '12 Hello, World!'
DPrints '13 Hello, World!'
Show answerHide answer
Correct answer: (D) Prints '13 Hello, World!'
Explanation
sprintf writes "Hello, World!" into buffer and returns the number of characters written, which is 13 (5 + comma + space + 5 + !). printf then prints "13 Hello, World!".
Which of the following is true about nested switch statements in C?
ABoth inner and outer switch statements must have a default case.
BA switch statement cannot contain another switch.
CInner switch cases should not contain break statement
DA switch statement can contain another switch statement inside any of its cases.
Show answerHide answer
Correct answer: (D) A switch statement can contain another switch statement inside any of its cases.
Explanation
C allows switch statements to be nested: any case of an outer switch can contain a complete inner switch. A default case is optional and break is allowed inside inner cases.
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = -1, y = 0, z = 1;
int result = (x > 0) ? x : (y == 0) ? z : y;
printf("%d", result);
return 0;
}
Acompile time error
B−1
C1
D0
Show answerHide answer
Correct answer: (C) 1
Explanation
x > 0 is false, so the second conditional (y == 0) ? z : y is evaluated. y is 0, so the result is z = 1.
How many times will the innermost loop execute in the below code?
#include <stdio.h>
int main() {
for(int i=0; i<3; i++)
{
for(int j=0; j<2; j++)
{
printf("%d ",i);
}
}
return 0;
}
A6 times
B3 times
C5 times
D2 times
Show answerHide answer
Correct answer: (A) 6 times
Explanation
The outer loop runs 3 times (i = 0,1,2) and the inner loop runs 2 times for each, so the inner body executes 3 x 2 = 6 times.
while (1) has a condition that is always true (non-zero) and nothing inside the body to break out, so it never ends. The for loops terminate and do { } while (0) runs once.
super refers to the immediate parent (superclass) object; it is used to call parent constructors and access parent methods or fields. The current object is referred to by this.
What will be the output of the following code snippet?
#include<stdio.h>
int main() {
int a = 5, b = 3, c = 0;
if (a > b > c) {
printf("True\n");
} else {
printf("False\n");
}
return 0;
}
Acompile time error
Bundefined behavior
CTRUE
DFALSE
Show answerHide answer
Correct answer: (C) TRUE
Explanation
Relational operators are evaluated left to right: (5 > 3) gives 1, then 1 > 0 gives 1 (true), so "True" is printed.
Which of the following statements is false about simplification of Boolean functions using
Karnaugh Map technique?
AKarnaugh Map technique is used to simplify Product of Sum (POS) form of Boolean
functions.
BIn Karnaugh Map, the rows and columns are represented in binary code sequence.
CIn Karnaugh Map, you group adjacent squares in the form of power of two and try to
cover as many minterms or maxterms as you can in one group.
DKarnaugh Map technique is used to simplify Sum of Product (SOP) form of Boolean
functions.
Show answerHide answer
Correct answer: (B) In Karnaugh Map, the rows and columns are represented in binary code sequence.
Explanation
In a K-map, rows and columns are labelled in Gray code (00, 01, 11, 10) so adjacent cells differ by one bit; plain binary order (00, 01, 10, 11) would break adjacency. K-maps simplify both SOP and POS forms.
public class ExceptionTest {
public static void main(String[] args) {
try {
System.out.println("Result: " + calculate(10, 0));
} catch (ArithmeticException e) {
System.out.println("ArithmeticException caught: " + e.getMessage());
} catch (Exception e) {
System.out.println("General exception caught: " + e.getMessage());
} finally {
System.out.println("In finally block.");
}
}
public static int calculate(int a, int b) throws Exception {
try {
return a / b;
} catch (ArithmeticException e) {
throw new Exception("Division by zero not allowed");
} finally {
System.out.println("Inner finally block executed.");
}
}
}
What will be the output of the program?
AInner finally block executed. General exception caught: / by zero In finally block.
BInner finally block executed.
General exception caught: Division by zero not allowed
In finally block.
CInner finally block executed.
Result: 0
In finally block.
DInner finally block executed.
ArithmeticException caught: / by zero
In finally block.
Show answerHide answer
Correct answer: (B) Inner finally block executed.
General exception caught: Division by zero not allowed
In finally block.
Explanation
10/0 throws ArithmeticException inside calculate, which is caught and replaced by new Exception("Division by zero not allowed"). The inner finally prints first, then main's catch (Exception) prints that message, and finally main's finally block runs.
What is the objective of encapsulation in object-oriented programming?
ATo create multiple instances of a class
BTo enable one class to inherit from another class
CTo allow objects to take multiple forms
DTo combine data and methods that operate on that data within a single unit
Show answerHide answer
Correct answer: (D) To combine data and methods that operate on that data within a single unit
Explanation
Encapsulation bundles data and the methods that act on it into one unit (class) and hides internal details. Inheritance and polymorphism are options B and C.
What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 10, b = 20;
int max = (a > b) ? a : b;
printf("%d", max);
return 0;
}
A30
Bcompile time error
C10
D20
Show answerHide answer
Correct answer: (D) 20
Explanation
a > b (10 > 20) is false, so the conditional operator returns b, and 20 is printed.
What will be the output of the following program?
class CustomException extends Exception {
public CustomException(String message) {
super(message);
}
}
public class TestCustomException {
public static void main(String[] args) {
try {
validateAge(15);
} catch (CustomException e) {
System.out.println("Caught Exception: " + e.getMessage());
} finally {
System.out.println("Execution finished.");
}
}
public static void validateAge(int age) throws CustomException {
if (age < 18) {
throw new CustomException("Age must be 18 or above.");
}
System.out.println("Age is valid.");
}
}
ACaught Exception: null
Execution finished.
BCompilation error because custom exceptions cannot extend Exception.
CAge is valid.
Execution finished.
DCaught Exception: Age must be 18 or above.
Execution finished.
Show answerHide answer
Correct answer: (D) Caught Exception: Age must be 18 or above.
Execution finished.
Explanation
validateAge(15) throws CustomException with the message "Age must be 18 or above.", so "Age is valid." is never printed. The catch prints the message and the finally block prints "Execution finished.".
What does the first dimension and the second dimension represents in a two-dimensional
character array?
AThe first dimension stores the length of each name, and the second stores the number
of names.
BThe first dimension represents the number of names in the array, and the second
dimension represents the maximum length of each name.
CThe first dimension represents the maximum length of the names, and the second
dimension represents the number of names.
DThe first dimension holds the total number of characters, and the second dimension
stores the number of names.
Show answerHide answer
Correct answer: (B) The first dimension represents the number of names in the array, and the second
dimension represents the maximum length of each name.
Explanation
In char names[N][L], the first dimension is the number of strings (rows) and the second is the maximum length of each string, including the null character.
Which of the following asymptotic notation gives asymptotically tight upper bound as well as
asymptotically tight lower bound?
AOmega (Ω)
BBig Oh (O)
CTheta (Θ)
DSmall Omega (ω)
Show answerHide answer
Correct answer: (C) Theta (Θ)
Explanation
Theta notation bounds a function both from above and below by constant multiples of g(n), giving an asymptotically tight bound. Big O gives only an upper bound and Omega only a lower bound.
Correct answer: (D) To display and navigate web pages
Explanation
A web browser retrieves, renders and displays web pages and lets the user navigate between them through links. Creating websites and email are done with other software.
What will be the output of the C program given below?
#include <stdio.h>
int* func()
{
static int arr[5] = { 1, 2, 3, 4, 5 };
return arr;
}
int main()
{
int* ptr = func();
printf("Array Elements: ");
for (int i = 0; i < 5; i++) {
printf("%d ", *ptr);
}
return 0;
}
A1 1 3 4 1
B2 3 4 5 0
C1 2 3 4 5
D1 1 1 1 1
Show answerHide answer
Correct answer: (D) 1 1 1 1 1
Explanation
ptr is never incremented inside the loop, so *ptr always reads arr[0] = 1, printing 1 five times (after "Array Elements: "). To print 1 2 3 4 5 the loop would need ptr[i] or *(ptr + i).
In DHTML, a style is changed at run time by assigning to the element's style object, e.g. element.style.backgroundColor = "red". There is no setCSS() method, and resize is an event, not a styling method.
Which of the following statements is INCORRECT about the storage classes in C?
AThe scope of variable in automatic storage class is local to the block in which the
variable is defined.
BIn Register storage class, the default initial value of the variable is zero.
CIn static storage class, the default initial value of the variable is zero.
DIn Register storage class, the storage of a variable is CPU register.
Show answerHide answer
Correct answer: (B) In Register storage class, the default initial value of the variable is zero.
Explanation
Register variables, like automatic ones, have a garbage (undefined) initial value if not initialised; only static and global variables default to zero. So statement B is incorrect.
What will be the output of the given C program?
#include <stdio.h>
int main()
{
{
int x = 10, y = 20;
{
{
int y = 40;
x++;
y++;
}
printf("x = %d, y = %d\n", x, y);
}
}
return 0;
}
Ax = 11, y = 41
Bx = 10, y = 41
Cx = 10, y = 20
Dx = 11, y = 20
Show answerHide answer
Correct answer: (D) x = 11, y = 20
Explanation
The inner block declares a new y = 40, which shadows the outer y; y++ changes only that inner copy. x is not redeclared, so x++ changes the outer x to 11. The printf sees x = 11 and the outer y = 20.
Which advantage of AJAX helps in reducing bandwidth consumption?
AAJAX uses less JavaScript.
BAJAX only loads images on the page.
CAJAX increases data transfer.
DAJAX sends and retrieves only small amounts of data from the server.
Show answerHide answer
Correct answer: (D) AJAX sends and retrieves only small amounts of data from the server.
Explanation
AJAX exchanges only the small pieces of data needed in the background and updates part of the page, instead of reloading the whole page, so less data is transferred.
Which of the following cases DOES NOT exist when one computes the time complexity of an
algorithm?
AAverage case
BWorst case
CTest Case
DBest Case
Show answerHide answer
Correct answer: (C) Test Case
Explanation
Time complexity is analysed for the best, average and worst cases. A "test case" is an input used in software testing, not a case of complexity analysis.
Which of the following options is correct about the functions in C language?
AActual parameters are declared in the function definition.
BActual parameters are always variables.
CActual parameters are used to define the function signature and to specify the type and
number of arguments that a function can accept.
DActual parameters are the values that are passed to a function when it is called.
Show answerHide answer
Correct answer: (D) Actual parameters are the values that are passed to a function when it is called.
Explanation
Actual parameters (arguments) are the values or expressions passed in the function call. The parameters declared in the function definition are formal parameters, and actual arguments need not be variables (constants and expressions work too).
Which of the following DHTML methods is used to control the browser window size, such as
resizing it dynamically via JavaScript?
Awindow.resizeTo()
Bwindow.setSize()
Cwindow.changeSize()
Ddocument.resizeWindow()
Show answerHide answer
Correct answer: (A) window.resizeTo()
Explanation
window.resizeTo(width, height) resizes the browser window to the given size (resizeBy changes it by an amount). setSize(), changeSize() and resizeWindow() do not exist.
Which sorting technique is best for sorting a linked list with n elements?
AInsertion sort
BBubble sort
CMerge sort
DSelection sort
Show answerHide answer
Correct answer: (C) Merge sort
Explanation
Merge sort suits linked lists: it needs only sequential access, splits the list by moving pointers, merges without extra arrays and runs in O(n log n). Other sorts are O(n²) or need random access.
Which of the following PHP functions is used to sort an array in ascending order without
affecting the keys?
Aksort()
Barray_sort()
Casort()
Dsort()
Show answerHide answer
Correct answer: (C) asort()
Explanation
asort() sorts an array by value in ascending order while keeping each key associated with its value. sort() re-indexes the keys, and ksort() sorts by key.
Which tool is used to adjust the brightness and contrast of an image in Adobe Photoshop?
AHealing brush tool
BPaint bucket tool
CAdjustments panel
DSelection tool
Show answerHide answer
Correct answer: (C) Adjustments panel
Explanation
Brightness/Contrast and other tonal corrections are applied from the Adjustments panel (Image > Adjustments) in Photoshop. The healing brush repairs blemishes and the paint bucket fills areas with colour.
An array name is not a modifiable lvalue, so a string cannot be assigned with arr = "..." after declaration (and "consultancy" needs 12 chars, more than 6). Strings must be given at initialisation or copied with strcpy.
Which of the following formats is commonly used for exporting images for the web?
APNG
BPSD
CBMP
DTIFF
Show answerHide answer
Correct answer: (A) PNG
Explanation
PNG is a compressed, lossless format with transparency that all browsers support, so it is commonly used for web images. PSD is Photoshop's working file, and BMP/TIFF are large and not web-friendly.
What will be the output of the given C program?
#include <stdio.h>
int main() {
int a = 4;
int b = 3;
int result;
result = a ^ b;
printf("%d", result);
return 0;
}
A0
B3
C4
D7
Show answerHide answer
Correct answer: (D) 7
Explanation
^ is bitwise XOR: 4 = 100 and 3 = 011, so 100 XOR 011 = 111 = 7.
How to use these DSSSB TGT / PGT Computer Science questions
Every question here was asked in a real DSSSB TGT / PGT paper; the paper and shift are shown on the card, and the number opens the question on its own page. Try each one before tapping Show answer, then attempt the full DSSSB TGT / PGT papers as timed tests to check your speed under exam conditions.