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 marksThe worst-case time complexity of deleting a node from a red-black tree is:
- A.O(1)
- B.O(log n)
- C.O(n)
- 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 marksIn a depth-first search of a directed graph, a back edge indicates the presence of a:
- A.Spanning tree
- B.Cycle in the graph
- C.Connected component
- 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 marksA priority queue is most efficiently implemented using:
- A.Sorted array
- B.Binary heap
- C.Linked list
- 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 marksThe time complexity of matrix chain multiplication using dynamic programming for n matrices is:
- A.O(n²)
- B.O(n³)
- C.O(2^n)
- 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 marksWhich of the following is a valid state in the NFA to DFA conversion (subset construction)?
- A.A single NFA state
- B.A set of NFA states
- C.A regular expression
- 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 marksWhich of the following is TRUE about the relationship between DFA and NFA?
- A.NFAs are strictly more powerful than DFAs
- B.DFAs and NFAs recognize exactly the same class of languages
- C.DFAs can recognize some languages that NFAs cannot
- 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 marksIn OSPF (Open Shortest Path First) routing protocol, each router maintains:
- A.Only routes to directly connected networks
- B.A complete topology map of the network area
- C.A distance vector to each destination
- 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 marksIn 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:
- A.The grammar is LL(1)
- B.A state has both a shift and a reduce action on the same terminal (shift-reduce conflict)
- C.The grammar has no epsilon productions
- 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 marksThe Chomsky hierarchy classifies formal languages into four types. Type 2 corresponds to:
- A.Regular languages
- B.Context-free languages
- C.Context-sensitive languages
- 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 marksWhich of the following statements about AES (Advanced Encryption Standard) is correct?
- A.AES is an asymmetric key algorithm
- B.AES uses a block size of 128 bits with key sizes of 128, 192, or 256 bits
- C.AES is the same as DES with a longer key
- 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 marksIn software testing, mutation testing is used to:
- A.Test the software under extreme conditions
- B.Evaluate the quality of the test suite by introducing small changes (mutants) to the code
- C.Test the user interface
- 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 marksThe number of edges in a tree with n vertices is always:
- A.n
- B.n − 1
- C.n + 1
- 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 marksAn operator grammar (simple precedence grammar) is one where:
- A.No two non-terminals appear adjacent on the right side of any production
- B.All productions are left-recursive
- C.The grammar is ambiguous
- 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 marksIn deadlock detection, the wait-for graph is constructed from the resource allocation graph by:
- A.Adding resource nodes for each process
- B.Removing resource nodes and collapsing edges through them
- C.Adding edges between all process pairs
- 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 marksWhich of the following is NOT a property of a B+ tree?
- A.All leaf nodes are at the same level
- B.Leaf nodes are linked for sequential access
- C.Internal nodes store actual data records
- 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 marksIn Prim's algorithm for MST, the tree grows by adding:
- A.The globally lightest edge
- B.The lightest edge connecting the tree to a non-tree vertex
- C.A random edge
- 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 marksRegister allocation in a compiler is equivalent to which graph theory problem?
- A.Maximum independent set
- B.Graph coloring
- C.Minimum spanning tree
- 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 marksDijkstra's algorithm does NOT work correctly for graphs with:
- A.Directed edges
- B.Weighted edges
- C.Negative edge weights
- 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 marksThe worst-case time complexity of inserting into an unbalanced BST with n nodes is:
- A.O(log n)
- B.O(n)
- C.O(1)
- 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 marksRadix sort with d digits and base b has time complexity:
- A.O(d × (n + b))
- B.O(n log n)
- C.O(n²)
- 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 marksIn an Activity Selection Problem, the greedy strategy of always selecting the activity with the earliest finish time is:
- A.Not always optimal
- B.Always optimal
- C.Only optimal when activities have equal durations
- 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 marksThe Bellman-Ford algorithm can detect negative weight cycles because:
- A.It uses only positive weights
- B.After V−1 iterations, if any edge can still be relaxed, a negative cycle exists
- C.It never terminates with negative cycles
- 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 marksThe time complexity of computing the Longest Common Subsequence (LCS) of two sequences of lengths m and n using dynamic programming is:
- A.O(m + n)
- B.O(m × n)
- C.O(2^(m+n))
- 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 marksIn IPv4, the Time-To-Live (TTL) field is decremented by:
- A.Each router the packet passes through
- B.Only the source host
- C.Only when crossing network boundaries
- 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 marksIn the context of operating systems, thrashing occurs when:
- A.CPU utilization is very high
- B.The system spends most of its time swapping pages in and out rather than executing
- C.Too many processes are in the ready queue
- 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 marksThe type of grammar required for the language L = {a^n b^n c^n | n ≥ 1} is:
- A.Regular grammar (Type 3)
- B.Context-free grammar (Type 2)
- C.Context-sensitive grammar (Type 1)
- 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 marksUDP is preferred over TCP when:
- A.Reliable, ordered delivery is essential
- B.Low latency is more important than reliability (e.g., real-time streaming, gaming)
- C.The data must be encrypted
- 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 marksThe Dijkstra-Scholten algorithm is used for:
- A.Shortest path computation
- B.Distributed termination detection
- C.Mutual exclusion
- 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 marksIn software engineering, which model allows going back to the previous phase to handle changes?
- A.Pure Waterfall model
- B.Iterative/Incremental model
- C.Big Bang model
- 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 marksWhich hash function property ensures that given a hash value h, it is computationally infeasible to find any message m such that H(m) = h?
- A.Collision resistance
- B.Preimage resistance
- C.Second preimage resistance
- 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₂).