MCQ’S
(PROGRAMMING CONSTRUCTS AND ALGORITHMS)
1. In Java, which keyword is used to declare a variable that cannot be modified once
assigned?
A) const
B) final
C) immutable
D) static
Answer: B) final
2. What will be the result of the following Java expression?
int x = 5; int y = 3; int result = x + y * 2;
A) 11
B) 16
C) 13
D) 10
Answer: C) 13
3.Which of the following best describes pseudocode?
A) A formal language similar to Java used for algorithm design
B) A high-level description of a computer program using natural language
C) A programming language widely used for web development
D) A type of bytecode generated by Java compiler
Answer: B) A high-level description of a computer program using natural language
4.Which of the following sorting algorithms typically has the worst time complexity?
A) Bubble Sort
B) Selection Sort
C) Insertion Sort
D) Merge Sort
Answer: A) Bubble Sort
5. In Java, which sorting algorithm is commonly used by the Arrays.sort() method?
A) Bubble Sort
B) Selection Sort
C) Insertion Sort
D) Quicksort
Answer: D) Quicksort
6.What is the time complexity of Binary Search when applied to a sorted array of size n?
A) O(1)
B) O(log n)
C) O(n)
D) O(n^2)
Answer: B) O(log n)
7. Linear search is best suited for:
A) Unsorted arrays
B) Sorted arrays
C) Arrays with duplicate elements
D) Arrays with a small number of elements
Answer: A) Unsorted arrays
8.In Java, which operator is used to compare two values for equality?
A) ==
B) =
C) !=
D) ===
Answer: A) ==
9. What is the result of the following Java expression?
int a = 7; int b = 3; double result = (double) a / b;
A) 2.3333333333333335
B) 2.0
C) 2.333333
D) 2.333333333333333
Answer: A) 2.3333333333333335
10.Which of the following is not a characteristic of pseudocode?
A) Uses programming language syntax
B) Expresses algorithm logic in a clear and understandable way
C) Independent of any specific programming language
D) Helps in planning and designing algorithms
Answer: A) Uses programming language syntax
11.In Bubble Sort, what is the time complexity in the best-case scenario?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(log n)
Answer: A) O(n)
12. Which sorting algorithm has the best average-case time complexity?
A) Bubble Sort
B) Insertion Sort
C) Merge Sort
D) Quick Sort
Answer: C) Merge Sort
13.Binary search can only be applied to:
A) Sorted arrays
B) Unsorted arrays
C) Arrays with unique elements
D) Arrays with negative numbers
Answer: A) Sorted arrays
14. Linear search is an example of:
A) Divide and Conquer algorithm
B) Greedy algorithm
C) Dynamic Programming algorithm
D) Sequential Search algorithm
Answer: D) Sequential Search algorithm
15.In Java, which keyword is used to define a function or method?
A) function
B) method
C) def
D) void
Answer: D) void
16. What is the purpose of modular design in programming?
A) To make the code more complex
B) To break down a program into smaller, manageable pieces
C) To increase the efficiency of the program
D) To eliminate the need for functions
Answer: B) To break down a program into smaller, manageable pieces
17.In Java, what is the return type of a function that doesn't return any value?
A) void
B) int
C) String
D) boolean
Answer: A) void
18. What is the purpose of a function parameter in Java?
A) To define the return type of the function
B) To provide input values to the function
C) To specify the function name
D) To declare local variables
Answer: B) To provide input values to the function
19. Which of the following is not a benefit of modular programming?
A) Reusability of code
B) Ease of maintenance
C) Faster execution time
D) Improved readability
Answer: C) Faster execution time
20. What is a module in modular programming?
A) A data type used to store values
B) A block of code that performs a specific task
C) A reserved keyword in Java
D) A function that returns a value
Answer: B) A block of code that performs a specific task
21. When writing pseudocode for a modular function, what should be included in the
description?
A) Detailed implementation steps
B) Variable declarations
C) Function name and parameters
D) Syntax-specific details
Answer: C) Function name and parameters
22. What is the purpose of using pseudocode for modular functions?
A) To generate executable code directly
B) To provide a high-level overview of the function's logic
C) To replace the need for actual coding
D) To specify the syntax of the function
Answer: B) To provide a high-level overview of the function's logic
23.What is the purpose of designing a flowchart for a sorting algorithm?
A) To execute the algorithm directly
B) To replace the need for writing pseudocode
C) To visualize the steps of the algorithm
D) To generate Java code automatically
Answer: C) To visualize the steps of the algorithm
24.In a flowchart, what shape is typically used to represent a process or action?
A) Rectangle
B) Diamond
C) Circle
D) Parallelogram
Answer: A) Rectangle
25.Which sorting algorithm is more efficient for small arrays or nearly sorted arrays?
A) Bubble Sort
B) Insertion Sort
C) Quick Sort
D) Merge Sort
Answer: B) Insertion Sort
26.In Bubble Sort, what is the time complexity in the worst-case scenario?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(log n)
Answer: C) O(n^2)
27.Which of the following best describes pseudocode?
A) A formal language similar to Java used for algorithm design
B) A high-level description of a computer program using natural language
C) A programming language widely used for web development
D) A type of bytecode generated by Java compiler
Answer: B) A high-level description of a computer program using natural language
28.Which of the following time complexities grows the fastest as the input size increases?
A) O(1)
B) O(log n)
C) O(n)
D) O(n^2)
Answer: D) O(n^2)
29.In Big O notation, what does O(n) represent?
A) Constant time complexity
B) Linear time complexity
C) Exponential time complexity
D) Logarithmic time complexity
Answer: B) Linear time complexity
30.What is the base case of the factorial calculation recursive algorithm?
A) n = 1
B) n = 0
C) n = 2
D) n = -1
Answer: B) n = 0