Daa 2
Daa 2
Classification of algorithms
1. Recursion or
Iteration 1. Divide and 1. Classification by
2. Procedural or Conquer Research Area
Declarative 2. Greedy Method
2. Classification by
(non- 3. Dynamic
Procedural) Complexity
Programming
3. Serial or Parallel 3. Branch and Bound
or Distributed
4. Linear
Programming & Backtracking
4. Deterministic or
Non- 5. Transform and
4. Randomized
Deterministic Conquer
Algorithms
5. Exact or
Approximate
1
...
2
...
Time analysis
3
...
4
...
5
...
6
...
1. void addMatrices (int a[m][n], int b[m][n], int result[m][m], int row,
int col)
2. {
1. Base case: if we've processed all rows
1. if (row == SIZE) { return; }
2. Base case: if we've processed all columns in the current row
1. if (col == SIZE)
2. {
3. Move to the next row and reset the column index
4. addMatrices(a, b, result, row + 1, 0);
5. return;
6. }
3. // Add the corresponding elements
1. result[row][col] = a[row][col] + b[row][col];
4. // Move to the next column
1. addMatrices(a, b, result, row, col + 1);
3. }
7
...
8
...
9
...
10
...
11
...
12
...
13
...
14
...
15
...
16
...
17
...
18