















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















































Question 1: Which of the following best describes an algorithm? A. A step-by-step procedure for solving a problem B. A programming language used for web development C. A database management system D. A type of hardware component Answer: A Explanation: An algorithm is a sequence of instructions designed to perform a specific task. Question 2: What does 'syntax' refer to in programming? A. The meaning of code B. The style of programming C. The structure and rules of a programming language D. The runtime performance Answer: C Explanation: Syntax refers to the set of rules that defines the combinations of symbols that are considered to be correctly structured programs. Question 3: Which data type is used to represent a single character? A. String B. Integer C. Char D. Boolean Answer: C Explanation: The 'char' data type is used to store a single character. Question 4: In programming, what is a variable? A. A constant value B. A storage location identified by a name C. A type of error D. A built-in function Answer: B Explanation: A variable is a storage location paired with an associated symbolic name that contains some known or unknown quantity of information. Question 5: What is typecasting? A. Converting one data type into another B. Declaring a variable
C. Repeating a loop D. Writing a comment Answer: A Explanation: Typecasting is the process of converting a variable from one data type to another. Question 6: Which control structure is best used when you need to execute code repeatedly while a condition is true? A. If-else statement B. For loop C. Switch statement D. Function call Answer: B Explanation: A loop, such as a for loop, is used to execute code repeatedly while a condition holds true. Question 7: What does the 'break' statement do inside a loop? A. It terminates the entire program B. It pauses the loop temporarily C. It exits the loop immediately D. It skips the current iteration Answer: C Explanation: The 'break' statement terminates the loop immediately and transfers control to the statement following the loop. Question 8: Which keyword is used in many programming languages to define a function? A. def B. var C. if D. for Answer: A Explanation: Many programming languages, especially Python, use the keyword 'def' to define a function. Question 9: What is a parameter in the context of a function? A. A variable that holds a constant value B. A value that is returned by the function C. A value passed into a function to customize its behavior D. A loop control variable Answer: C Explanation: A parameter is a variable used in a function to refer to one of the pieces of data provided as input.
Answer: A Explanation: Debugging is the process of identifying, isolating, and fixing issues or bugs in a program. Question 15: Which programming paradigm focuses on using functions and immutable data? A. Imperative B. Object-oriented C. Functional D. Procedural Answer: C Explanation: Functional programming emphasizes the use of functions and avoids changing-state and mutable data. Question 16: What is the main purpose of using comments in code? A. To increase runtime speed B. To explain code for better understanding C. To encrypt data D. To define variables Answer: B Explanation: Comments are used to explain code and improve its readability and maintainability. Question 17: What is the result of an infinite loop? A. The program terminates normally B. The program enters a state of perpetual execution C. The program automatically fixes itself D. The program skips execution Answer: B Explanation: An infinite loop never terminates and causes the program to run indefinitely. Question 18: Which concept describes the structure and meaning of code? A. Syntax and semantics B. Variables and constants C. Algorithms and data structures D. Functions and methods Answer: A Explanation: Syntax refers to the structure while semantics refers to the meaning of the code. Question 19: What does the term 'scope' refer to in programming? A. The number of functions in a program B. The area of the program where a variable is accessible
C. The type of data stored in a variable D. The error handling mechanism Answer: B Explanation: Scope defines the region of a program where a variable can be accessed. Question 20: What is the difference between compilation and interpretation? A. Compilation translates code to machine language before execution, while interpretation translates code during execution B. Compilation is used for scripting languages, interpretation for compiled languages C. Compilation results in runtime errors only, interpretation in syntax errors only D. Compilation is slower than interpretation Answer: A Explanation: Compilers translate the entire code into machine language before execution, whereas interpreters translate code line-by-line at runtime. Question 21: Which of the following best describes data structures? A. Algorithms that process data B. Organized ways to store and manage data C. Visual representations of code D. Syntax rules of a programming language Answer: B Explanation: Data structures are ways to store and organize data efficiently. Question 22: What is the purpose of type conversion in programming? A. To change the function of a variable B. To convert one data type into another C. To encrypt data D. To declare new variables Answer: B Explanation: Type conversion is used to change data from one type to another to ensure compatibility. Question 23: Which statement correctly initializes a variable in many programming languages? A. int number = 5; B. number := int 5; C. int 5 = number; D. number = "5"; Answer: A Explanation: The syntax "int number = 5;" is commonly used to declare and initialize an integer variable.
Answer: B Explanation: Syntax errors are detected by the compiler during the code compilation process. Question 29: Which concept allows a program to execute different code based on conditions? A. Looping B. Conditional statements C. Functions D. Variables Answer: B Explanation: Conditional statements allow a program to perform different actions based on whether a condition is true or false. Question 30: What is the main advantage of using functions in a program? A. They reduce code readability B. They promote code reuse and modularity C. They increase memory usage D. They eliminate the need for variables Answer: B Explanation: Functions allow code to be reused and organized into manageable, modular pieces. Question 31: What is the significance of debugging tools? A. They compile the code faster B. They help identify and fix errors in the code C. They automate variable declarations D. They create user interfaces Answer: B Explanation: Debugging tools are used to locate and resolve errors in the code during development. Question 32: What is the role of data structures in algorithms? A. They store data needed for algorithm execution B. They define the algorithm's syntax C. They are used solely for error handling D. They compile code Answer: A Explanation: Data structures are used to organize and store data, which algorithms process to produce a result. Question 33: Which term refers to the rules that define how code must be written in a programming language? A. Semantics
B. Syntax C. Logic D. Structure Answer: B Explanation: Syntax refers to the set of rules that dictate the structure of code in a programming language. Question 34: Which statement is true about variable scope? A. Global variables can be accessed only within functions B. Local variables are accessible throughout the program C. Global variables can be accessed anywhere in the program D. Local variables are declared outside of any function Answer: C Explanation: Global variables are accessible throughout the entire program. Question 35: What is the purpose of error handling in programming? A. To enhance program aesthetics B. To ensure the program handles unexpected conditions gracefully C. To eliminate the need for debugging D. To increase execution speed Answer: B Explanation: Error handling is used to manage errors or exceptions in a program, ensuring it fails gracefully if an issue occurs. Question 36: What is encapsulation in object-oriented programming? A. Hiding internal details and exposing only necessary components B. Inheriting properties from a parent class C. Allowing multiple functions with the same name D. Converting code into machine language Answer: A Explanation: Encapsulation involves bundling data and methods together and restricting access to some of the object's components. Question 37: Which access modifier restricts access to class members within the same class only? A. Public B. Protected C. Private D. Internal Answer: C Explanation: Private access modifiers restrict access to class members only within the class.
Answer: A Explanation: A constructor is a special method that initializes new objects of a class. Question 43: What is method overriding? A. Defining a new method with a different name B. Redefining a parent class method in a subclass C. Declaring a method as static D. Removing a method from a class Answer: B Explanation: Method overriding allows a subclass to provide a specific implementation of a method that is already defined in its parent class. Question 44: Which keyword is used to refer to the current instance of a class? A. super B. this C. self D. current Answer: B Explanation: The keyword 'this' is used in many languages to refer to the current instance, though some languages like Python use 'self'. Question 45: What is an interface in object-oriented programming? A. A class that cannot have any methods B. A contract that defines a set of methods without implementing them C. A way to hide class data D. A tool for debugging code Answer: B Explanation: An interface defines a contract of methods that a class must implement without providing the actual method implementations. Question 46: What distinguishes a static method from an instance method? A. Static methods cannot be called B. Static methods belong to the class, not to any specific object C. Instance methods are always private D. Instance methods do not use parameters Answer: B Explanation: Static methods are associated with the class itself rather than with any particular instance. Question 47: Which of the following is an example of encapsulation? A. Using public variables for all class members B. Keeping class variables private and providing public getter and setter methods
C. Inheriting from multiple classes D. Overloading methods with different parameters Answer: B Explanation: Encapsulation involves keeping the internal state private and providing public methods to access and modify it. Question 48: What is a destructor in object-oriented programming? A. A method called to create an object B. A method that cleans up resources when an object is no longer needed C. A method that copies an object D. A method that initializes class variables Answer: B Explanation: A destructor is used to free resources or perform cleanup when an object is destroyed. Question 49: Which principle of OOP is primarily concerned with exposing only necessary details? A. Abstraction B. Inheritance C. Polymorphism D. Encapsulation Answer: A Explanation: Abstraction focuses on exposing only the essential features and hiding the underlying complexity. Question 50: Which of the following allows multiple methods to have the same name within the same class? A. Method overriding B. Method overloading C. Encapsulation D. Inheritance Answer: B Explanation: Method overloading allows different methods in the same class to have the same name as long as their parameter lists differ. Question 51: What is the purpose of a getter method in a class? A. To modify the value of a variable B. To retrieve the value of a private variable C. To initialize class properties D. To delete an object
C. A class cannot contain methods, whereas an object can D. A class is used for error handling, and an object is not Answer: B Explanation: A class defines a blueprint, while an object is an instantiated version of that blueprint. Question 57: Which concept involves a method in a subclass having the same signature as a method in the parent class? A. Method overloading B. Method overriding C. Encapsulation D. Abstraction Answer: B Explanation: Method overriding is when a subclass redefines a method from its parent class with the same signature. Question 58: What does the term 'class inheritance' refer to? A. A class copying code from another class B. A class being used to create an interface C. A class deriving properties and behaviors from another class D. A class that is declared as final Answer: C Explanation: Class inheritance allows one class (subclass) to inherit properties and methods from another class (superclass). Question 59: Which keyword is commonly used to prevent a class from being subclassed? A. final B. static C. private D. abstract Answer: A Explanation: The keyword 'final' is used in many programming languages to indicate that a class cannot be subclassed. Question 60: In object-oriented programming, what is an abstract class? A. A class that cannot be instantiated and may contain abstract methods B. A class that is only used for utility functions C. A class with only static methods D. A class that contains no methods
Answer: A Explanation: An abstract class cannot be instantiated and is designed to be subclassed, often containing abstract methods that must be implemented by subclasses. Question 61: Which term describes a function defined within a class? A. Variable B. Method C. Attribute D. Constructor Answer: B Explanation: A function defined inside a class is known as a method. Question 62: What is the main benefit of using interfaces in OOP? A. They allow multiple inheritance of behavior B. They restrict code to one implementation C. They make code execution faster D. They eliminate the need for constructors Answer: A Explanation: Interfaces allow classes to implement multiple sets of behaviors, overcoming limitations of single inheritance. Question 63: Which of the following is NOT a benefit of object-oriented programming? A. Modularity B. Reusability C. Increased complexity without structure D. Maintainability Answer: C Explanation: OOP is intended to improve structure and maintainability, not to introduce unnecessary complexity. Question 64: What is the role of a setter method? A. To retrieve the value of a variable B. To modify or set the value of a private variable C. To initialize an object D. To override parent class methods Answer: B Explanation: A setter method is used to assign a value to a private variable in a controlled way. Question 65: Which of the following is a feature of inheritance in object-oriented programming? A. Code duplication B. Code reuse
Answer: B Explanation: The 'this' keyword is used to reference the current object instance. Question 70: Which of the following best describes object-oriented programming? A. A programming paradigm based on functions and procedures B. A style of programming that focuses on objects and data encapsulation C. A method of writing code that avoids classes entirely D. A technique for designing databases Answer: B Explanation: Object-oriented programming centers around objects that encapsulate data and behavior. Question 71: What is an array? A. A collection of elements stored in contiguous memory locations B. A function that sorts data C. A type of loop D. A method for error handling Answer: A Explanation: An array is a data structure that holds a fixed number of elements in contiguous memory locations. Question 72: Which of the following is a characteristic of a linked list? A. Elements are stored in contiguous memory B. Each element contains a reference to the next element C. It provides constant time random access D. It is immutable Answer: B Explanation: A linked list consists of nodes, where each node contains a reference (or pointer) to the next node. Question 73: What is the main advantage of using a stack data structure? A. It allows random access to elements B. It follows the Last-In, First-Out (LIFO) principle C. It supports efficient searching D. It is used for storing key-value pairs Answer: B Explanation: A stack is a LIFO data structure where the most recently added element is the first to be removed. Question 74: Which algorithm is most efficient for searching in a sorted array? A. Linear search B. Binary search
C. Bubble search D. Depth-first search Answer: B Explanation: Binary search efficiently finds an element in a sorted array by repeatedly dividing the search interval in half. Question 75: What is the average-case time complexity of binary search? A. O(n) B. O(n²) C. O(log n) D. O(1) Answer: C Explanation: Binary search has an average-case time complexity of O(log n). Question 76: Which sorting algorithm repeatedly compares adjacent elements and swaps them if they are in the wrong order? A. Merge sort B. Quicksort C. Bubble sort D. Insertion sort Answer: C Explanation: Bubble sort compares adjacent elements and swaps them, repeatedly passing through the list until it is sorted. Question 77: What is the main idea behind the merge sort algorithm? A. Dividing the array into halves, sorting them, and merging the sorted halves B. Selecting a pivot element and partitioning the array around it C. Repeatedly swapping adjacent elements D. Scanning the array sequentially to find the smallest element Answer: A Explanation: Merge sort divides the array into halves, recursively sorts them, and then merges the sorted halves. Question 78: Which sorting algorithm is known for its average-case efficiency of O(n log n) and uses a divide-and-conquer approach? A. Selection sort B. Merge sort C. Bubble sort D. Insertion sort
B. It simplifies code by breaking down problems into smaller subproblems C. It uses less memory than iteration D. It avoids the need for conditional statements Answer: B Explanation: Recursion simplifies complex problems by breaking them down into smaller, manageable subproblems. Question 84: Which algorithm is best for finding the shortest path in a graph with non- negative weights? A. Depth-first search B. Bellman-Ford algorithm C. Dijkstra's algorithm D. Quick sort Answer: C Explanation: Dijkstra's algorithm efficiently finds the shortest path in graphs with non-negative weights. Question 85: What is a key property of a binary search tree (BST)? A. Each node has exactly three children B. The left subtree of a node contains only nodes with values less than the node’s value C. The right subtree of a node contains only even numbers D. All nodes are stored in an array Answer: B Explanation: In a BST, for any given node, all values in the left subtree are less than the node’s value and all values in the right subtree are greater. Question 86: What is the primary purpose of a graph data structure? A. To represent hierarchical relationships B. To represent networks of nodes and edges C. To store sequential data D. To implement recursive algorithms Answer: B Explanation: Graphs represent networks of nodes connected by edges, useful in modeling relationships. Question 87: What is the difference between a directed and an undirected graph? A. Directed graphs have weighted edges, undirected graphs do not B. In directed graphs, edges have a direction; in undirected graphs, they do not C. Directed graphs are acyclic; undirected graphs are cyclic D. Directed graphs can only have one node
Answer: B Explanation: Directed graphs have edges with a specified direction, while undirected graphs do not. Question 88: Which algorithm uses a stack data structure for traversal in graphs? A. Breadth-first search (BFS) B. Depth-first search (DFS) C. Dijkstra's algorithm D. Merge sort Answer: B Explanation: Depth-first search uses a stack (either explicitly or through recursion) to traverse graphs. Question 89: What is the time complexity of a linear search algorithm in the worst-case scenario? A. O(1) B. O(n) C. O(log n) D. O(n log n) Answer: B Explanation: In the worst-case scenario, linear search examines each element once, resulting in O(n) time complexity. Question 90: Which of the following sorting algorithms is generally considered unstable? A. Insertion sort B. Merge sort C. Quick sort D. Bubble sort Answer: C Explanation: Quick sort is generally considered unstable because it does not preserve the relative order of equal elements. Question 91: Which data structure is ideal for implementing recursive backtracking algorithms? A. Queue B. Stack C. Array D. Hash Table Answer: B Explanation: Stacks are well-suited for recursive backtracking as they allow the algorithm to backtrack through previous states.