Question

In: Computer Science

Write pseudocode for Boolean product of two matrices. Identify how sections of the code computing cycles...

Write pseudocode for Boolean product of two matrices.

Identify how sections of the code computing cycles grows with increasing matrix sizes.

10 points pseudocode

10 points description of code computing cycle growth

Solutions

Expert Solution

Part1

PSEUDOCODE FOR BOOLEAN PRODUCT OF TWO MATRICES:

I have added comments in the code for better understanding.

for(i = 0; i < n; i++)    //here we are using nested loops to multiply the two matrices
{
    for(j = 0; j < n; j++)
    {
        boolean status = false;    //initial bool status
        for(m = 0; m < n; m++)
        {
            status ||= a[i][m] && b[m][j];   //here we are using ||= to get the boolean value whether the multiplication turns true or not. if true then we have completed the multiplication.
            if(status)
                break; // if the value turns out to be true then break out of the loop
        }
        c[i][j] = status;   //final status value after the multiplication stored in the matrix
    }
}

Part 2

How the code computing cycles grows with increasing matrix sizes:

Description:

Boolean matrices are matrices where each entry is either 0 or 1, and matrix multiplication is performed by using AND for * and OR for +, hence for a boolean matrix, AND is used in place of multiplication and OR in place of addition. Now let us assume that we are given two matrices of the size n * n.

Let us say for any constant x inside the matrix, the number of operations before we can break out of the loop depends on x and will not increase with n, the size of the matrix. n may only decide the number of "trials" unitl "true" is obtained. At each iteration/trial there are (1/x)2 chances that the loop will terminate by obtaining a true value, because we need two 1s and the chance of each entry being a 1 turns out to be 1/x. The number of trials before breaking or terminating will follow a Geometric distribution (GD) where p being the probability is (1/x)2, so the innermost loop runs in constant time for a given k, making the overall algorithm O(n2).

When x is very large, you'll almost never exit early and your algorithm will be of the complexity O(n^3).

This describes the limiting behaviour of the algorithm.


Related Solutions

Using pseudocode or C++ code, write a function to compute and return the product of two...
Using pseudocode or C++ code, write a function to compute and return the product of two sums. The first is the sum of the elements of the first half of an array A. The second is the sum of the elements of the second half of A. The function receives A and N ≥ 2, the size of A, as parameters. (in c++)
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
We see that this computes the product of two matrices. Add a new kernel code, called...
We see that this computes the product of two matrices. Add a new kernel code, called sum, to compute the sum of the two matrices. #include <stdio.h> #include <math.h> #include <sys/time.h> #define TILE_WIDTH 2 #define WIDTH 6 // Kernel function execute by the device (GPU) __global__ void product (float *d_a, float *d_b, float *d_c, const int n) {    int col = blockIdx.x * blockDim.x + threadIdx.x ;    int row = blockIdx.y * blockDim.y + threadIdx.y ;    float...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack that implements a stack using the fact that you have access to a queue data structure with operations enqueue(), dequeue(), isEmpty(). Remember that every stack should have the operations push() and pop(). Hint: use two queues, one of which is the main one and one is temporary. Please note that you won’t be able to implement both push() and pop() in constant time. One...
write the pseudocode and code to solve the following: you are given a list. determine the...
write the pseudocode and code to solve the following: you are given a list. determine the sum of all the elements in the list without using the built in puthon function sum(). Take your code and create your own function and name it my_sum_algo() which will return the sum of numbers PS please write comments in the code for my understanding, and please write jn jn PYTHON 3 languge. Thank you, have a great day !
Write a pseudocode for the following code: /*every item has a name and a cost */...
Write a pseudocode for the following code: /*every item has a name and a cost */ public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;...
Examine the product life cycles for your chosen two products relative to how it affects the...
Examine the product life cycles for your chosen two products relative to how it affects the company’s marketing strategies How would your suggestion be different for the two companies' brand managers about making decisions on price, advertising, and distribution channels?
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT