Matrix Multiplication by Brute Force
Matrix Multiplication by Brute Force
Matrix Multiplication by Brute Force
David Akers
for i 0 to n - 1 do for j 0 to n - 1 do C[i,j] = 0.0 for k 0 to n - 1 do C[i,j] C[i,j] + A[i,k] x B[k,j] return C
Brute force
Brute force is a straightforward approach to solving a problem, usually directly based on the problem statement and definitions of the concepts involved.
Levitin p. 97
1/31/2012
Bubble sort
BubbleSort(A[0..n-1])
// Input: An array A[0..n-1] of orderable elements // Output: Array A[0..n-1], sorted in ascending order.
Selection sort
SelectionSort (A[0..n-1]) // Sorts a given array // Input: An array A[0..n-1] of orderable elements. // Output: An array A[0..n-1] sorted in ascending order. A[0..n 1] for i 0 to n 2 do min i for j i + 1 to n - 1 do if A[j] < A[min] min j swap A[i] and A[min]
Selection sort
for i 0 to n 2 do min i for j i + 1 to n - 1 do if A[j] < A[min] min j swap A[i] and A[min]
1/31/2012
Sequential search
SequentialSearch(A[0..n-1], K)
// Input: An array A[0..n-1] of elements, and a search key K. // Output: Index of the first element of A that matches K (or -1 if there are no // matching elements).
i 0 while i < n and A[i] K do i i+1 if i < n return i else return -1 Whats the running time?
// adding K as a sentinel
Multi-variable big-oh
One variable:
Multiple variables: