and Answers 100% Pass
What is the purpose of using loops in programming?
✔✔ Loops allow repeated execution of a block of code until a specified condition is met, making
programs more efficient by automating repetitive tasks.
How do arrays help in managing data in a program?
✔✔ Arrays help manage data by storing multiple values of the same type in a single, ordered
collection. They allow easy access to and manipulation of data using indices.
What are conditionals, and why are they important in decision-making in programs?
✔✔ Conditionals (e.g., `if`, `else`) allow programs to execute certain blocks of code based on
whether a specified condition is true or false. They enable decision-making within programs,
ensuring that different actions are taken depending on the situation.
How does a binary search algorithm work, and when is it used?
1
,✔✔ A binary search algorithm works by repeatedly dividing a sorted dataset in half and
comparing the target value to the middle element. It is used to efficiently search for a value in
large, sorted datasets.
What is inheritance in object-oriented programming, and why is it useful?
✔✔ Inheritance allows a new class to inherit properties and behaviors (methods) from an
existing class. It promotes code reusability and hierarchical class organization, making it easier
to manage and extend code.
How do you handle exceptions in a program?
✔✔ Exceptions are handled using try-catch blocks, which allow the program to respond to errors
gracefully without crashing. Proper exception handling improves program robustness and user
experience.
What is the difference between a while loop and a for loop?
2
,✔✔ A while loop continues to execute as long as a specified condition remains true, while a for
loop runs a specific number of iterations, often based on a counter variable.
How do you optimize a recursive function to avoid excessive memory usage?
✔✔ Optimizing a recursive function can be done by using techniques such as memoization
(storing intermediate results), ensuring a proper base case, and sometimes converting the
recursion into an iterative solution to reduce memory overhead.
What is a stack data structure, and where is it commonly used?
✔✔ A stack is a data structure that follows the Last In, First Out (LIFO) principle. It is
commonly used in function call management, backtracking algorithms, and undo mechanisms in
applications.
What is the significance of Big O notation in evaluating algorithms?
3
, ✔✔ Big O notation is used to describe the time and space complexity of an algorithm, helping to
evaluate its efficiency, especially in terms of how it scales with input size. It allows comparison
of algorithms' performance independently of specific hardware or implementation details.
What is a queue data structure, and how does it differ from a stack?
✔✔ A queue is a data structure that follows the First In, First Out (FIFO) principle, where
elements are added at the back and removed from the front. Unlike a stack, where the most
recently added item is removed first, a queue removes the oldest item first.
How does a linked list differ from an array?
✔✔ A linked list is a dynamic data structure where each element (node) contains a reference to
the next element, allowing for efficient insertion and deletion. An array, in contrast, is a static,
contiguous block of memory, where elements are accessed via indices.
What is polymorphism in object-oriented programming, and how is it useful?
4