UGC NET CS Practice Set 8

UGC NET JRF Computer Science · 2026 · with answers and explanations

questions
30
Total marks
60
Duration
180 minutes
Negative marking
No

Subjects: Computer Science

Question 1

Computer Science · 2 marks

The worst-case time complexity of deleting a node from a red-black tree is:

  1. A.O(1)
  2. B.O(log n)
  3. C.O(n)
  4. D.O(n log n)

Correct answer: B

Explanation: Red-black trees are self-balancing BSTs with O(log n) height. Deletion involves finding the node O(log n), removing it, and performing at most O(log n) rotations and recolorings to restore the red-black properties. Total: O(log n).

Question 2

Computer Science · 2 marks

In a depth-first search of a directed graph, a back edge indicates the presence of a:

  1. A.Spanning tree
  2. B.Cycle in the graph
  3. C.Connected component
  4. D.Bipartite partition

Correct answer: B

Explanation: In DFS of a directed graph, a back edge (from a descendant to an ancestor in the DFS tree) indicates the presence of a cycle. A directed graph is acyclic (DAG) if and only if its DFS produces no back edges.

Question 3

Computer Science · 2 marks

A priority queue is most efficiently implemented using:

  1. A.Sorted array
  2. B.Binary heap
  3. C.Linked list
  4. D.Hash table

Correct answer: B

Explanation: A binary heap provides O(log n) insertion and O(log n) deletion of the min/max element, with O(1) peek. A sorted array gives O(1) deletion but O(n) insertion. An unsorted linked list gives O(1) insertion but O(n) deletion. A hash table doesn't maintain order.

Question 4

Computer Science · 2 marks

The time complexity of matrix chain multiplication using dynamic programming for n matrices is:

  1. A.O(n²)
  2. B.O(n³)
  3. C.O(2^n)
  4. D.O(n log n)

Correct answer: B

Explanation: The DP solution for matrix chain multiplication fills an n×n table where each cell (i,j) considers all possible split points k between i and j. The three nested loops (chain length l, starting position i, split point k) give O(n³) time.

Question 5

Computer Science · 2 marks

Which of the following is a valid state in the NFA to DFA conversion (subset construction)?

  1. A.A single NFA state
  2. B.A set of NFA states
  3. C.A regular expression
  4. D.A production rule

Correct answer: B

Explanation: In the subset construction (NFA to DFA conversion), each DFA state corresponds to a set (subset) of NFA states. The DFA state is accepting if it contains at least one accepting NFA state. The resulting DFA may have up to 2^n states for an n-state NFA.

Question 6

Computer Science · 2 marks

Which of the following is TRUE about the relationship between DFA and NFA?

  1. A.NFAs are strictly more powerful than DFAs
  2. B.DFAs and NFAs recognize exactly the same class of languages
  3. C.DFAs can recognize some languages that NFAs cannot
  4. D.NFAs are only theoretical and cannot be simulated

Correct answer: B

Explanation: DFAs and NFAs are equivalent in power — they both recognize exactly the class of regular languages. Every NFA can be converted to an equivalent DFA using the subset construction (though the DFA may have exponentially more states). The key advantage of NFAs is succinctness.

Question 7

Computer Science · 2 marks

In OSPF (Open Shortest Path First) routing protocol, each router maintains:

  1. A.Only routes to directly connected networks
  2. B.A complete topology map of the network area
  3. C.A distance vector to each destination
  4. D.Routes learned from BGP only

Correct answer: B

Explanation: OSPF is a link-state routing protocol. Each router floods its link-state information to all other routers in the area, so every router builds a complete topology map (link-state database) and independently computes shortest paths using Dijkstra's algorithm.

Question 8

Computer Science · 2 marks

In the SLR parsing method, reduce actions are determined by the FOLLOW set of the left-hand side non-terminal. This can lead to conflicts when:

  1. A.The grammar is LL(1)
  2. B.A state has both a shift and a reduce action on the same terminal (shift-reduce conflict)
  3. C.The grammar has no epsilon productions
  4. D.The grammar is unambiguous

Correct answer: B

Explanation: SLR parsing uses FOLLOW sets to determine when to reduce. A shift-reduce conflict occurs when a state has both a shift action and a reduce action on the same terminal. This happens because FOLLOW sets can be too imprecise, which is why LR(1) parsing (with lookahead in items) is more powerful.

Question 9

Computer Science · 2 marks

The Chomsky hierarchy classifies formal languages into four types. Type 2 corresponds to:

  1. A.Regular languages
  2. B.Context-free languages
  3. C.Context-sensitive languages
  4. D.Recursively enumerable languages

Correct answer: B

Explanation: In the Chomsky hierarchy: Type 0 = recursively enumerable (TM), Type 1 = context-sensitive (linear bounded automata), Type 2 = context-free (PDA), Type 3 = regular (DFA/NFA). Each type is a proper subset of the one above: Type 3 ⊂ Type 2 ⊂ Type 1 ⊂ Type 0.

Question 10

Computer Science · 2 marks

Which of the following statements about AES (Advanced Encryption Standard) is correct?

  1. A.AES is an asymmetric key algorithm
  2. B.AES uses a block size of 128 bits with key sizes of 128, 192, or 256 bits
  3. C.AES is the same as DES with a longer key
  4. D.AES uses a Feistel network structure

Correct answer: B

Explanation: AES (Rijndael) is a symmetric block cipher with a fixed block size of 128 bits and key sizes of 128, 192, or 256 bits (10, 12, or 14 rounds respectively). Unlike DES, AES does NOT use a Feistel network — it uses a substitution-permutation network (SPN).

Question 11

Computer Science · 2 marks

In software testing, mutation testing is used to:

  1. A.Test the software under extreme conditions
  2. B.Evaluate the quality of the test suite by introducing small changes (mutants) to the code
  3. C.Test the user interface
  4. D.Perform integration testing

Correct answer: B

Explanation: Mutation testing assesses the quality of a test suite by introducing small syntactic changes (mutations) to the program (e.g., changing + to −, swapping conditions) and checking if the test suite detects them (kills the mutant). A high mutation score indicates an effective test suite.

Question 12

Computer Science · 2 marks

The number of edges in a tree with n vertices is always:

  1. A.n
  2. B.n − 1
  3. C.n + 1
  4. D.2n

Correct answer: B

Explanation: A tree is a connected acyclic graph. A tree with n vertices always has exactly n − 1 edges. This is a fundamental property: removing any edge disconnects the tree, and adding any edge creates a cycle.

Question 13

Computer Science · 2 marks

An operator grammar (simple precedence grammar) is one where:

  1. A.No two non-terminals appear adjacent on the right side of any production
  2. B.All productions are left-recursive
  3. C.The grammar is ambiguous
  4. D.Every production has exactly one terminal

Correct answer: A

Explanation: An operator grammar is a context-free grammar where no production has two adjacent non-terminals on the right-hand side (no ε-productions allowed either). This enables operator-precedence parsing, which uses precedence relations (<, =, >) between terminal pairs to parse expressions.

Question 14

Computer Science · 2 marks

In deadlock detection, the wait-for graph is constructed from the resource allocation graph by:

  1. A.Adding resource nodes for each process
  2. B.Removing resource nodes and collapsing edges through them
  3. C.Adding edges between all process pairs
  4. D.Removing all process nodes

Correct answer: B

Explanation: The wait-for graph is derived from the resource allocation graph by removing resource nodes and collapsing the edges. If process P waits for a resource held by process Q (P → Resource → Q), an edge P → Q is added in the wait-for graph. A cycle in this graph indicates deadlock.

Question 15

Computer Science · 2 marks

Which of the following is NOT a property of a B+ tree?

  1. A.All leaf nodes are at the same level
  2. B.Leaf nodes are linked for sequential access
  3. C.Internal nodes store actual data records
  4. D.Keys in internal nodes act as separators

Correct answer: C

Explanation: In a B+ tree, internal nodes store only keys and child pointers (acting as separators/index entries). Actual data records or pointers to data records are stored ONLY in leaf nodes. This is a key difference from B-trees, where data can appear in all nodes.

Question 16

Computer Science · 2 marks

In Prim's algorithm for MST, the tree grows by adding:

  1. A.The globally lightest edge
  2. B.The lightest edge connecting the tree to a non-tree vertex
  3. C.A random edge
  4. D.All edges of the lightest vertex

Correct answer: B

Explanation: Prim's algorithm grows the MST from a starting vertex by repeatedly adding the minimum-weight edge that connects a vertex in the tree to a vertex not yet in the tree. This is a cut property application. Kruskal's, in contrast, adds the globally lightest edge that doesn't form a cycle.

Question 17

Computer Science · 2 marks

Register allocation in a compiler is equivalent to which graph theory problem?

  1. A.Maximum independent set
  2. B.Graph coloring
  3. C.Minimum spanning tree
  4. D.Shortest path

Correct answer: B

Explanation: Register allocation is modeled as graph coloring on the interference graph. Variables that are simultaneously live are connected by edges. Assigning k registers to variables without conflicts is equivalent to k-coloring the interference graph. Graph coloring is NP-complete in general.

Question 18

Computer Science · 2 marks

Dijkstra's algorithm does NOT work correctly for graphs with:

  1. A.Directed edges
  2. B.Weighted edges
  3. C.Negative edge weights
  4. D.Cycles

Correct answer: C

Explanation: Dijkstra's algorithm assumes non-negative edge weights. With negative edges, a vertex marked as finalized may later have a shorter path discovered through a negative edge, violating the greedy invariant. Bellman-Ford handles negative weights (but not negative cycles).

Question 19

Computer Science · 2 marks

The worst-case time complexity of inserting into an unbalanced BST with n nodes is:

  1. A.O(log n)
  2. B.O(n)
  3. C.O(1)
  4. D.O(n log n)

Correct answer: B

Explanation: An unbalanced BST can degenerate into a linked list (e.g., inserting sorted data), giving height = n−1. Insertion requires traversing from root to leaf, which is O(height) = O(n) in the worst case. Self-balancing trees (AVL, red-black) guarantee O(log n).

Question 20

Computer Science · 2 marks

Radix sort with d digits and base b has time complexity:

  1. A.O(d × (n + b))
  2. B.O(n log n)
  3. C.O(n²)
  4. D.O(d × n × b)

Correct answer: A

Explanation: Radix sort processes d digits, performing a stable counting sort for each digit. Each counting sort is O(n + b) where b is the base (number of possible digit values). Total: O(d × (n + b)). For fixed d and b, this is O(n) — linear time.

Question 21

Computer Science · 2 marks

In an Activity Selection Problem, the greedy strategy of always selecting the activity with the earliest finish time is:

  1. A.Not always optimal
  2. B.Always optimal
  3. C.Only optimal when activities have equal durations
  4. D.Optimal only for weighted activities

Correct answer: B

Explanation: The greedy choice of always selecting the next activity with the earliest finish time (among those compatible with already selected activities) always yields an optimal solution for the unweighted activity selection problem. This is proved using exchange argument/greedy stays ahead.

Question 22

Computer Science · 2 marks

The Bellman-Ford algorithm can detect negative weight cycles because:

  1. A.It uses only positive weights
  2. B.After V−1 iterations, if any edge can still be relaxed, a negative cycle exists
  3. C.It never terminates with negative cycles
  4. D.It uses a priority queue

Correct answer: B

Explanation: Bellman-Ford runs V−1 iterations of edge relaxation (sufficient for shortest paths in a graph without negative cycles, since shortest paths have at most V−1 edges). A V-th iteration that still reduces some distance proves a negative-weight cycle exists.

Question 23

Computer Science · 2 marks

The time complexity of computing the Longest Common Subsequence (LCS) of two sequences of lengths m and n using dynamic programming is:

  1. A.O(m + n)
  2. B.O(m × n)
  3. C.O(2^(m+n))
  4. D.O(m × n × (m+n))

Correct answer: B

Explanation: The DP solution for LCS builds an (m+1)×(n+1) table where each cell is computed in O(1) time using the recurrence: if characters match, L[i][j] = L[i-1][j-1]+1; otherwise L[i][j] = max(L[i-1][j], L[i][j-1]). Total: O(m×n) time and space.

Question 24

Computer Science · 2 marks

In IPv4, the Time-To-Live (TTL) field is decremented by:

  1. A.Each router the packet passes through
  2. B.Only the source host
  3. C.Only when crossing network boundaries
  4. D.The destination host

Correct answer: A

Explanation: Each router that forwards an IPv4 packet decrements the TTL by at least 1. If TTL reaches 0, the router discards the packet and sends an ICMP Time Exceeded message to the source. This prevents packets from looping indefinitely due to routing errors.

Question 25

Computer Science · 2 marks

In the context of operating systems, thrashing occurs when:

  1. A.CPU utilization is very high
  2. B.The system spends most of its time swapping pages in and out rather than executing
  3. C.Too many processes are in the ready queue
  4. D.The disk has insufficient space

Correct answer: B

Explanation: Thrashing occurs when the system's working set of all active processes exceeds available physical memory. The system spends most of its time handling page faults (swapping pages between RAM and disk), causing CPU utilization to plummet. The working set model helps prevent it.

Question 26

Computer Science · 2 marks

The type of grammar required for the language L = {a^n b^n c^n | n ≥ 1} is:

  1. A.Regular grammar (Type 3)
  2. B.Context-free grammar (Type 2)
  3. C.Context-sensitive grammar (Type 1)
  4. D.Unrestricted grammar (Type 0)

Correct answer: C

Explanation: L = {aⁿbⁿcⁿ | n ≥ 1} is NOT context-free (can be shown using the CFL pumping lemma). It IS context-sensitive: a linear bounded automaton can recognize it, and a context-sensitive grammar can generate it. It does not require a full Turing machine.

Question 27

Computer Science · 2 marks

UDP is preferred over TCP when:

  1. A.Reliable, ordered delivery is essential
  2. B.Low latency is more important than reliability (e.g., real-time streaming, gaming)
  3. C.The data must be encrypted
  4. D.Connection setup is required

Correct answer: B

Explanation: UDP is connectionless, has no built-in reliability/ordering/flow control, and has minimal overhead (8-byte header vs TCP's 20). It is preferred for real-time applications (VoIP, video streaming, gaming, DNS queries) where low latency matters more than guaranteed delivery.

Question 28

Computer Science · 2 marks

The Dijkstra-Scholten algorithm is used for:

  1. A.Shortest path computation
  2. B.Distributed termination detection
  3. C.Mutual exclusion
  4. D.Leader election

Correct answer: B

Explanation: The Dijkstra-Scholten algorithm detects termination in distributed computations built on a diffusing computation model. It maintains a spanning tree of the active processes and detects global termination when the tree collapses to the root and the root becomes idle.

Question 29

Computer Science · 2 marks

In software engineering, which model allows going back to the previous phase to handle changes?

  1. A.Pure Waterfall model
  2. B.Iterative/Incremental model
  3. C.Big Bang model
  4. D.Code-and-fix model

Correct answer: B

Explanation: The iterative/incremental model allows revisiting earlier phases to accommodate changes. Each iteration goes through requirements → design → implementation → testing, with each cycle producing an increment of the software. The pure waterfall model does not support going back.

Question 30

Computer Science · 2 marks

Which hash function property ensures that given a hash value h, it is computationally infeasible to find any message m such that H(m) = h?

  1. A.Collision resistance
  2. B.Preimage resistance
  3. C.Second preimage resistance
  4. D.Determinism

Correct answer: B

Explanation: Preimage resistance (one-wayness): given h, it's infeasible to find m with H(m) = h. Second preimage resistance: given m₁, it's infeasible to find m₂ ≠ m₁ with H(m₁) = H(m₂). Collision resistance: it's infeasible to find ANY two messages m₁ ≠ m₂ with H(m₁) = H(m₂).

View all papers — UGC NET JRF Computer Science

Practice this paper with a timer

Attempt it online, get scored instantly, and see which subjects are costing you marks.

Start practising free