Test Flashcards
What is the definition of finiteness in algorithms?
An algorithm must always have a finite number of steps before it ends
It must have a defined endpoint or output and not enter an endless loop.
Define definiteness in the context of algorithms.
An algorithm needs to have exact definitions for each step
Clear and straightforward directions ensure that every step is understood and can be taken easily.
What are inputs in an algorithm?
Values supplied to the algorithm before its processing
These inputs come from a predetermined range of acceptable values.
What is meant by output in an algorithm?
One or more results produced after the algorithm completes its steps
The relationship between the input and the result should be clear.
Explain the effectiveness characteristic of an algorithm.
Stages must be straightforward to be carried out in finite time using basic operations
Every operation in the algorithm should be doable and practicable.
What does generality mean in terms of algorithms?
An algorithm should solve a group of issues rather than just one specific case
It should offer a generic fix that manages a variety of inputs.
What does modularity refer to in algorithm design?
The ability to break a problem down into small modules or steps
This is a basic definition of an algorithm.
Define correctness in the context of an algorithm.
When given inputs produce the desired output
It indicates that the algorithm was designed correctly.
What is maintainability in algorithm design?
The algorithm should be designed in a straightforward, structured way
This allows for redefinition without significant changes.
What does functionality mean in algorithms?
It takes into account various logical steps to solve a real-world problem
What is robustness in an algorithm?
An algorithm’s ability to define a problem clearly
What does user-friendly mean in the context of algorithms?
The algorithm should be easy to understand for the programmer
How does simplicity impact algorithms?
A simple algorithm is easier to understand
What is extensibility in algorithm design?
The algorithm should be usable by other designers or programmers
What is a brute force algorithm?
A straightforward approach that exhaustively tries all possible solutions
Suitable for small problem instances but may become impractical for larger ones.
Define a recursive algorithm.
A method that breaks a problem into smaller, similar subproblems and applies itself to solve them
It continues until reaching a base case.
What is an encryption algorithm?
Utilized to transform data into a secure, unreadable form using cryptographic techniques
What is a backtracking algorithm?
A trial-and-error technique used to explore potential solutions by undoing choices
Commonly employed in puzzles and optimization problems.
What is the purpose of a searching algorithm?
Designed to find a specific target within a dataset
What does a sorting algorithm do?
Aims to arrange elements in a specific order
This enhances data organization and retrieval.
What is a hashing algorithm?
Converts data into a fixed-size hash value for rapid data access
Commonly used in databases and password storage.
What is the divide and conquer algorithm?
Breaks a complex problem into smaller subproblems, solves them independently, and combines their solutions
What is a greedy algorithm?
Makes locally optimal choices at each step to find a global optimum
Useful for optimization problems but may not always lead to the best solution.
What is dynamic programming in algorithms?
Stores and reuses intermediate results to avoid redundant computations
What is a randomized algorithm?
Utilizes randomness in its steps to achieve a solution
What is a base case in recursive algorithms?
The condition under which the recursion stops
It represents the simplest instance of the problem.
What is a recursive case?
The part of the algorithm that breaks the problem down into smaller instances
What is a stack in the context of recursion?
Each recursive call is placed on the system call stack
What is the factorial of a number n in terms of recursion?
Defined as n! = n * (n-1)! for n > 0, and 0! = 1 as the base case
What are the advantages of recursion?
- Simplicity
- Direct translation for naturally recursive problems
What are the disadvantages of recursion?
- Performance overhead due to multiple function calls
- Higher memory usage from call stack
When should recursion be used?
When a problem can be divided into similar sub-problems or when the recursive solution is simpler
What is linear search?
A simple search algorithm that checks each element sequentially
It has a time complexity of O(n).
What is the time complexity of linear search in the worst case?
O(n)
What is binary search?
A more efficient search algorithm that repeatedly divides the search interval in half
Requires the array to be sorted.
What is the time complexity of binary search?
O(log n)
What is the best case time complexity for binary search?
O(1)
Define interpolation search.
Similar to binary search but works on uniformly distributed data
What is depth-first search (DFS)?
Explores as far as possible along one branch before backtracking
What is breadth-first search (BFS)?
Explores all neighbors at the present depth before moving on to the next depth level
What is bubble sort?
A simple sorting algorithm that repeatedly swaps adjacent elements
It is inefficient for large datasets.
What is the worst-case time complexity of bubble sort?
O(n^2)
What is selection sort?
Finds the minimum element and swaps it with the first unsorted element
Always performs O(n^2) comparisons.
What is the worst-case time complexity of selection sort?
O(n^2)
What is the time complexity of Selection Sort in the best case?
O(n^2)
Selection sort does not improve with better input scenarios.
What is the primary characteristic of Insertion Sort?
Builds a sorted list one element at a time
Efficient for small or nearly sorted datasets.
What is the worst-case time complexity of Insertion Sort?
O(n^2)
Occurs when the array is sorted in reverse order.
What is the best-case time complexity for Merge Sort?
O(n log n)
The time complexity remains the same in all cases.
What is the main approach used in Quicksort?
Selects a pivot element and partitions the array around it
Recursively sorts the partitions.
What is the average-case time complexity of Quicksort?
O(n log n)
Occurs with random pivots.
What data structure does Heap Sort utilize?
Binary heap data structure
Builds a max-heap and repeatedly extracts the maximum element.
What is the time complexity of Counting Sort?
O(n + k)
Where k is the range of the input.
What is Radix Sort effective for?
Sorting large numbers or strings with fixed length
Sorts numbers by processing individual digits.
What is the worst-case time complexity for Bucket Sort?
O(n^2)
All elements may end up in one bucket in a degenerate case.
What is the defining characteristic of Shell Sort?
Generalization of insertion sort with a gap sequence
Sorts elements far apart and gradually reduces the gap.
What is Big O Notation?
Provides an upper bound on time or space complexity
Represents the worst-case scenario for an algorithm’s efficiency.
What does O(1) signify in Big O Notation?
Constant Time
The algorithm takes the same time to execute regardless of input size.
What is the time complexity of Linear Search?
O(n)
The runtime increases linearly with the input size.
What is the worst-case time complexity of Bubble Sort?
O(n^2)
Inefficient for large datasets.
What is the average-case time complexity for Merge Sort?
O(n log n)
Consistent across different input scenarios.
What is the primary use case for Insertion Sort?
Good for small or nearly sorted lists
Efficient for building a sorted list incrementally.
Fill in the blank: The best case for Insertion Sort is _______.
O(n)
Occurs when the array is already sorted.
What is a key observation regarding Quick Sort?
Can degrade to O(n^2) if poor pivot selection occurs
While it is efficient on average, the worst-case scenario exists.
What is the time complexity of Heap Sort in all cases?
O(n log n)
Consistent across best, average, and worst cases.
What does O(n log n) represent in terms of algorithm efficiency?
Log-Linear Time
Common in efficient sorting algorithms like merge sort and quicksort.
What characterizes Exponential Time complexity?
Runtime doubles with each additional element
Common in algorithms that solve problems by brute force.
What is the definition of a Data Type?
Classification that specifies the type of data a variable can hold
Defines operations that can be performed on the data.
Give examples of primitive data types.
- Integer
- Floating Point
- Character
- Boolean
Basic building blocks of data in programming.
What is an Enumeration in programming?
A data type allowing a variable to be a set of predefined constants
Improves code readability and limits possible values.