Module 3 Flashcards
Brute Force Boi
A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved
Brute Force
Examples of Brute Force
- Computing an (a > 0, n a nonnegative integer)
- Computing n!
- Multiplying two matrices
- Searching for a key of a given value in a list
Brute Force Strengths
- wide applicability
- simplicity
- yields reasonable algorithms for some important problems (e.g., matrix multiplication, sorting, searching, string matching)
Brute Force Weaknesses
- rarely yields efficient algorithms
- some brute-force algorithms are unacceptably slow
- not as constructive as some other design techniques
__________ sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning.
Selection Sort Algorithm
T or F
The Selection Sort Algorithm maintains two subarrays in a given array.
True
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
T or F
In every iteration of selection sort, the minimum element (considering descending order) from the unsorted subarray is picked and moved to the sorted subarray.
False (Descending)
In Brute Force String Matching what is a string of m characters to search for?
Pattern
In Brute Force String Matching what is a a (longer) string of n characters to search in?
Text
Compares a given pattern with all substrings
of a given text.
Brute Force String Matching
T or F
Those comparisons between substring and pattern proceed character by
character unless a mismatch is found.
True
Whenever a mismatch is found, the remaining character comparisons for that substring are dropped and the next substring can be selected
immediately.
True
Brute Force Algorithm Steps:
Step 1 Align pattern at beginning of text
Step 2 Moving from left to right, compare each character of pattern to the corresponding character in text until all characters are found to match (successful search); or a mismatch is detected
Step 3 While pattern is not found and the text is not yet exhausted, realign pattern one position to the right and repeat Step 2
A brute force solution to a problem involving search for an element with a special property, usually among combinatorial objects such as permutations, combinations, or subsets of a set.
Exhaustive Search
Exhaustive Search Method
- generate a list of all potential solutions to the problem in a systematic manner evaluate potential solutions one by one, disqualifying infeasible ones and, for an optimization problem, keeping track of the best one found so far
- when search ends, announce the solution(s) found