NOCTI Computer Science 2 — Questions and Answers
Question 1: What is the time complexity of a binary search algorithm?
- O(n)
- O(log n) (Correct answer)
- O(n log n)
- O(n squared)
Correct answer: O(log n)
Binary search divides the search space in half with each comparison, resulting in O(log n) time complexity where n is the number of elements.
Binary search works on sorted arrays by comparing the target value to the middle element. If they are not equal, the half in which the target cannot lie is eliminated. This halving process means that for an array of n elements, the maximum number of comparisons is log base 2 of n. For example, searching through 1,000,000 elements requires at most about 20 comparisons.
Question 2: Which data structure uses FIFO (First In, First Out) ordering?
- Stack
- Queue (Correct answer)
- Binary tree
- Hash table
Correct answer: Queue
A queue processes elements in FIFO order, the first element added is the first one removed, similar to a line of people waiting.
A queue is a linear data structure that follows First In, First Out ordering. Elements are added at the rear (enqueue) and removed from the front (dequeue). Queues are fundamental in computing: CPU task scheduling, print job management, breadth-first search, and message buffers all rely on queues. In contrast, a stack uses LIFO (Last In, First Out) ordering.
Question 3: What does SQL stand for?
- Structured Query Language (Correct answer)
- Sequential Query Logic
- Standard Question Language
- System Quality Level
Correct answer: Structured Query Language
SQL stands for Structured Query Language, the standard language for managing and querying relational databases.
Structured Query Language (SQL) was developed at IBM in the 1970s and became an ANSI/ISO standard in 1986. It is the universal language for relational database management systems including MySQL, PostgreSQL, SQL Server, Oracle, and SQLite. SQL encompasses DDL for creating tables, DML for inserting/updating/deleting data, DQL for SELECT statements, and DCL for permissions.
Question 4: In object-oriented programming, what is encapsulation?
- The ability of a class to inherit from multiple parents
- Bundling data and methods that operate on that data within a single unit (Correct answer)
- The process of converting one data type to another
- Creating multiple methods with the same name but different parameters
Correct answer: Bundling data and methods that operate on that data within a single unit
Encapsulation is the OOP principle of bundling data (attributes) and the methods that manipulate that data into a single unit (class), while restricting direct access to some components.
Encapsulation is one of the four fundamental OOP principles (along with inheritance, polymorphism, and abstraction). It involves bundling data and methods into a class, and information hiding through access modifiers (private, protected, public). By making internal data private and providing public getter/setter methods, encapsulation prevents external code from directly modifying an object's state in unexpected ways.
Question 5: What is the decimal equivalent of the binary number 11010?
- 22
- 26 (Correct answer)
- 30
- 18
Correct answer: 26
Converting binary 11010: (1x16) + (1x8) + (0x4) + (1x2) + (0x1) = 16 + 8 + 0 + 2 + 0 = 26.
Binary to decimal conversion uses positional notation with base 2. Each position represents a power of 2, starting from 2^0 (=1) on the right. For binary 11010: 1x16 = 16, 1x8 = 8, 0x4 = 0, 1x2 = 2, 0x1 = 0. Sum = 26. Understanding binary is essential in computer science because all digital systems store and process data as binary digits.
Question 6: Which network topology connects each device to a central hub or switch?
- Bus topology
- Ring topology
- Star topology (Correct answer)
- Mesh topology
Correct answer: Star topology
In a star topology, all devices connect to a central hub or switch, which manages data transmission between nodes.
Star topology is the most common network layout in modern LANs. Each device connects to a central networking device via its own dedicated cable or wireless link. Advantages include easy troubleshooting, simple expansion, and centralized management. The main disadvantage is the single point of failure at the central device. Modern enterprise networks typically use extended star topologies with redundant core switches.
What is the time complexity of a binary search algorithm?