Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ECE 1125
Agam Mittal
ECE 1125
Problem 3
void pmult(int startA, int finishA, int startB, int finishB, int* startD, int* finishD);
float coefficient;
*startD = avail;
while((startA <= finishA) && (startB<=finish)){
for (startA<=finishA, startA++){
for (startB <= finshB, startB++){
[startD].exp= terms[StartA].exp + terms[startB].expon
[startD].coeff=terms[StartA].coeff * terms[startB].coeff
startD++;
}
}
}
}
Complexity: O(m*n)
Problem 4
void stackEmpty()
{
if (top==-1){
return;
}
}
Problem 5
empty(stack s);
create(queue q);
while (end != 5) {
insert(q)
}
if (size[q]!=0) {
delete[q];
push[s]
}
if (size[s]!=0) {
pop[s]
insert[q];
}
}
Agam Mittal
ECE 1125
Problem 6
Problem 7
(a) One triple represents each sparse matrix; also, there are w bits per word, and
each word corresponds to a single triple. Every term that is not zero is stored
as 3 triples, and to store the # of rows, cols, and # of nonzero terms, there are
3 more triples. So, one needs 3x+3 triples for x non-zero numbers. The total
bit storage is w(3x+3)
typedefstruc{
int row;
int col;
int val;
}term;
term matrixA[][MAX] matrixB[][MAX];
void Madd() {
for(i=0;i<rows; i++){
for(j=0;j<cols;j++){
if ((matrixA[i][j].row == 1) && (matrixB[i][j].col==1)){
Agam Mittal
ECE 1125