Divide and Conquer (Strassen’s Matrix Multiplication)
Given two square matrices A and B of size n x n each, find their multiplication matrix.
Naive Method
Following is a simple way to multiply two matrices.
void multiply(int A[][N], int B[][N], int C[][N]) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { C[i][j] = 0; for (int k = 0; k < N; k++) { C[i][j] += A[i][k]*B[k][j]; } } } } |
Time Complexity of above method is O(N3).
Divide and Conquer
Following is simple Divide and Conquer method to multiply two
square matrices.
1) Divide matrices A and B in 4 sub-matrices of size N/2 x N/2 as
shown in the below diagram.
2) Calculate following values recursively. ae + bg, af + bh, ce +
dg and cf + dh.
Implement Strassen’s algorithm in Java / Python as indicated above.. in multiplying two square matrices of size n x n
Submit your solution online (BB), with the generated output
In: Computer Science
A mobile phone service provider has three different subscription packages for its customers:
Package A: For $39.99 per month 450 minutes are
provided. Additional minutes are
$0.45 per minute.
Package B: For $59.99 per month 900 minutes are
provided. Additional minutes are
$0.40 per minute.
Package C: For $69.99 per month unlimited minutes provided.
Write a program that calculates a customer’s monthly bill. It
should ask which package
the customer has purchased and how many minutes were used. It
should then display
the total amount due.
Input Validation: Be sure the user only selects package A, B, or C.
Assume 30 day month(Billing Cycle). Maximum Minutes is 43200.
Quality of craftsmanship is part of the grading.
===============================================================================
In: Computer Science
=========================================================================
A software company sells a package that retails for $99.
Quantity discounts are given
according to the following table.
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Write a program that asks for the number of units sold and computes
the total cost of
the purchase.
Input Validation: Make sure the number of units is greater than
0.
=========================================================================
the pseudo code is:
There comes situations in real life when we need to make some
decisions and based on these decisions, we decide what should we do
next. Similar situations arises in programming also where we need
to make some decisions and based on these decision we will execute
the next block of code. Decision making statements in programming
languages decides the direction of flow of program execution.
Decision making structures require that the programmer specify one
or more conditions to be evaluated or tested by the program
selection construct, along with a statement or statements to be
executed if the condition is determined to be true, and optionally,
other statements to be executed if the condition is determined to
be false.
When a customer purchases some quantity of our software package, we
need to make a decision about how much discount to apply to the
purchase. Our program will need to evaluate at least 4 to 5
conditions to determine which discount to apply.
We will use a decision making structure that can evaluate at test for five(5) possible conditions along with a statement to apply the discount if the condition is determined to be true.
Since we have multiple conditions to evaluate, we shall select to implement the if-else-if ladder construct which has the following syntax:
if (condition)
statement;
else if (condition)
statement;
.
.
else
statement;
=========================================================================
declare const for price
double const PRICE(99.00);
declare variables
int qty, double totalCost, discount
prompt user for qty
validate data & determine discount
if( qty <= 0 ) cout<<"Invalid Value\n"
else if( qty < 20 ) discount = 0.20
.
.
else discount = 0.50
compute totalCost
display results
----------------------------------------------------------------------------
In: Computer Science
In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle cannot be more than 0.1 of the width of the canvas. If the player draws a large circle, the message "This is too big!" will be shown on the canvas. Still player can fix it and get back to game by moving the mouse towards the center of the circle (the point that first mouse was pressed on) and resume the game.
In: Computer Science
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML tags to design your webpage: <h1>...</h1>,<h3>...</h3>, <h6>...</h6>, <p>...</p>, <b>...</b>, <i>...</i>, <a>...</a>, <img...>, <table>... </table>, <div>...</div>, <form>...</form>, <input type="text">, and <input type= "submit">
Use an external css to change the default style of your webpage. You must use at least one element selector, one id selector, and one class selector Using text input and submit button, allow the user to change the background color of your web page to red, blue, or yellow. When the user clicks the submit button to change the background color, you must first validate the user input to make sure the entered color is valid (red, blue, and yellow are valid colors). Then, you should change the background color of your web page. If the user didn’t enter a valid color, you should prompt the user to enter a valid color.
In: Computer Science
Question: How do I write a program in C# that calculates a student's final grade for a test with 20 multiple questions using arrays and helper methods?
Instructions: (0-incorrect answer, 1-correct answer) If the student answered the question right, add .5 points to the running total. If the student didn’t answer correctly subtract .5 points from the running total. The running total is initialized with 5 points (so the student receives 5 points extra credit). To define the final grade use the grading scale below
Score Grade
90+ A
80-89 B
70-79 C
60-69 D
<60 F
Write a helper method displayScoreGrade()that displays the score and calculated grade.
private static void displayGrade(double score, char grade)
{ //printing the score; //printing the grade; ... } Call the method from the main method.
In: Computer Science
Write a simple MIPS Assembly program to average 3 integers. Make sure to read in three numbers from the user instead of hard coding them. To divide the sum by 3 you may use div $t0, $t0, 3 where register $t0 conatins the sum of the 3 integers.
.data
prompt1: .asciiz " Please enter an integer: "
prompt2: .asciiz " Please enter an integer: "
prompt3: .asciiz " Please enter an integer: "
result: .asciiz "The average of three number is: "
.text
main:
li $v0, 4 # syscall to print string
la $a0, prompt1
syscall
li $v0, 5 # syscall to read an integer
syscall
move $t0, $v0 # move number to read into $t0
li $v0, 4
la $a0, prompt2
syscall
li $v0,5
syscall
move $t1, $v0
li $v0, 4
la $a0, prompt3
syscall
li $v0,5
syscall
move $t2, $v0
# add all integers to $t3
add $t3, $t0, $t1
add $t3, $t2, $t3
li $v0, 1
syscall
# Read the sum
li $v0, 3
syscall
move $t3, $v0
# Divide Sum / count
div $t4, $t3, 3
#li $v0, 1
#move $a0, $t4
#print out the average
move $a0, t4
li $v0, 1
la $a0, result
syscall
exit:
li $v0, 10
syscall
Whats the problem?
In: Computer Science
In Your Own Words, very briefly (1 paragraph)
In: Computer Science
wite a program in C to print a right and left pointing arrow pattern using '#' symbol. Do so within 10 lines i.e upper half of the occupies 5 lines and lower half occupies other 5 lones.
User will enter 'R' or'r' for printing right pointing arrow. 'l' or 'L' for left pointing arrow.'k'' for invalid option.
You must use if-else and while loop for do this.
In: Computer Science
Problem: On an ARM processor using big endian format, given the following memory map and [R1] = 0xA10E0C2D, [R2] = 0x00000060, [R3] = 0x00000002, [R4] = 0x0000000C, predict [R1] and [R2] and draw the updated memory map after an ARM data transfer instruction is executed in EACH case. (hint: (1) in this map, each memory location is a word long and occupies 4 bytes; also you only need to draw the section of the memory including the changed word and its address; (2) these instructions are NOT executed one after the other one; instead, each instruction starts with the initial conditions given in the statement.)
0x6C [0x78092A7B]
0x68 [0x56AB8CEF]
0x64 [0x3490AB02]
0x60 [0x902E8C9A]
(1) LDRH R1, [R2, R4]
(2) STRB R1, [R2]
In: Computer Science
Complete the task below C++
This header file declares the Comp315Array Class **************************/ //Include the libraries #include <iostream> //Allow the use of cin and cout //Declare namespace std for using cin and cout using namespace std; //Class declaration class Comp315Array{ //Public members public: /**************** Default Constructor Task: assign 0 to the array size *********/ Comp315Array(); /**************** Constructor Task: Define an int array of size n *********/ Comp315Array(int n); /***************** getSize method Task: return the array size ******************/ int getSize(); /***************** setValue method Task: set array value in position p ******************/ void setValue(int p, int val); /***** sum method Task: compute the sum of the n elements in the array params: @returns sum of elements *******/ int sum(); /***** sum method Task: compute the sum of the elements in the array from position i to position j @returns sum of elements from position i to position j *******/ int sum(int i, int j); /***** greatest method Task: returns the greatest element in the array @returns value of the greatest element in the array *******/ int greatest(); /***** lowest method Task: returns the lowest element in the array @returns value of the lowest element in the array *******/ int lowest(); /***** average method Task: the average of elements in the array @returns the average of elements in the array *******/ double averageValue(); /****** occurencesCount method Task: count the number of occurrences in the array of a target value params targetVal: target value @returns number of occurrences of the target value in the array *********/ int occurencesCount(int targetVal); /****** firstOccurence method Task: returns the position of the first occurrence of a target value params targetVal: target value @returns position of the first occurrence of target value in the array if the target value is not in the array, the method must return a -1 *********/ int firstOccurence(int targetVal); /****** printArray method Task: print elements in the array @returns *********/ void printElements(); /************** Destructor ******/ ~Comp315Array(); //Private members private: //array size int arraySize; //actual array int *actualArray; }; **************************/
This file implements the Comp315Array Class //Include the header file #include "Comp315Array.h" //Allow the use of cin and cout /**************** Default Constructor Task: assign 0 to the array size *********/ Comp315Array::Comp315Array() { arraySize = 0; } /**************** Destructor *********/ Comp315Array::~Comp315Array() { actualArray=0; } /**************** Constructor Task: Define an int array of size n *********/ Comp315Array::Comp315Array(int n) { actualArray= new int[n]; arraySize = n; } /***************** getSize method Task: return the array size ******************/ int Comp315Array::getSize(){ return arraySize; } /***************** setValue method Task: set array value in position p ******************/ void Comp315Array::setValue(int p, int actualValue){ actualArray[p]=actualValue; } /***** sum method Task: compute the sum of the n elements in the array params: @returns sum of elements *******/ int Comp315Array::sum(){ int res=0; return res; } /***** sum method Task: compute the sum of the elements in the array from position i to position j @returns sum of elements from position i to position j *******/ int Comp315Array::sum(int i, int j){ int res=0; return res; } /***** greatest method Task: returns the greatest element in the array @returns value of the greatest element in the array *******/ int Comp315Array::greatest(){ int res=actualArray[0]; return res; } /***** lowest method Task: returns the lowest element in the array @returns value of the lowest element in the array *******/ int Comp315Array::lowest(){ int res=actualArray[0]; return res; } /***** average method Task: the average of elements in the array @returns the average of elements in the array *******/ double Comp315Array::averageValue(){ int res=0; return res; } /****** occurencesCount method Task: count the number of occurrences in the array of a target value params targetVal: target value @returns number of occurrences of the target value in the array *********/ int Comp315Array::occurencesCount(int targetVal){ int res=0; return res; } /****** firstOccurence method Task: returns the position of the first occurrence of a target value params targetVal: target value @returns position of the first occurrence of target value in the array if the target value is not in the array, the method must return a -1 *********/ int Comp315Array::firstOccurence(int targetVal){ int res=-1; return res; } /****** printArray method Task: print elements in the array @returns *********/ void Comp315Array::printElements(){ for(int i=0;i<arraySize; i++){ cout<<actualArray[i]<<endl; } } **************************/
This file implements the Comp315Array Class //Include the header file #include "Comp315Array.h" //Allow the use of cin and cout int menu() { int op; op=0; while (op==0 || op>10) { cout<<"***********************************"<<endl; cout<<"Select one of the following options"<<endl; cout<<"***********************************"<<endl; cout<<" 1. Introduce array elements"<<endl; cout<<" 2. Compute elements sum"<<endl; cout<<" 3. Compute elements sum in a selected range"<<endl; cout<<" 4. Compute elements average value"<<endl; cout<<" 5. Find the greatest element"<<endl; cout<<" 6. Find the lowest element"<<endl; cout<<" 7. Count occurrences of an element"<<endl; cout<<" 8. Find the first occurrence of an element"<<endl; cout<<" 9. Print elements"<<endl; cout<<" 10. Exit"<<endl; cout<<"***********************************"<<endl; cin>>op; } cout<<"Selected option"<<op<<endl<<endl; return op; } int main(){ int size, op, val; Comp315Array cArray; cout<<"Array size? "; cin>>size; cArray = Comp315Array(size); do{ op=menu(); switch (op) { case 1: for (int i=0; i<size; i++) { cout<<"Element "<<i<<": "; cin>>val; cArray.setValue(i,val); } break; case 2: cout<<"The total sum is "<< cArray.sum()<<endl; break; case 3: int initVal, endVal; cout<<"Initial position: "; cin>>initVal; cout<<"Final position: "; cin>>endVal; cout<<"The total sum is "<< cArray.sum(initVal, endVal)<<endl; break; case 4: cout<<"The aveage value is "<< cArray.averageValue()<<endl; break; case 5: cout<<"The greatest value is "<< cArray.greatest()<<endl; break; case 6: cout<<"The lowest value is "<<cArray.lowest()<<endl; break; case 7: cout<<"Target value: "; cin>>val; cout<<"Number of occurrences: " << cArray.occurencesCount(val) <<endl; break; case 8: cout<<"Target value: "; cin>>val; cout<<"The first occurrence is in position " << cArray.firstOccurence(val) <<endl; break; case 9: cArray.printElements(); break; } }while(op!=10); cout<<"Goodbye!"<<endl; return 0; }
In: Computer Science
A digital computer has a memory unit with 32 bits per word. The instruction set consists of 122 different operations. All instructions have an operation code part (opcode) and an address part (allowing for only one address). Each instruction is stored in one word of memory.
a) How many bits are needed for the opcode?
b) How many bits are left for the address part of the instruction?
c) What is the maximum allowable size for memory?
d) What is the largest unsigned binary number that can be accommodated in one word of memory?
In: Computer Science
Im in a java class and having trouble with assigning the seat to a specific number from the array.. Below are the instructions I was given and then the code that I have already.
ITSE 2321 – OBJECT-ORIENTED PROGRAMMING JAVA Program 8 – Arrays and ArrayList
A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to write an application to assign seats on flight of the airline’s only plane (capacity: 10 seats). Your application should display the following alternatives: "Please type 1 for First Class" and "Please type 2 for Economy." If the user types 1, your application should assign a seat in the first-class section (seats 1 – 5). If the user types 2, your application should assign a seat in the economy section (seats 6 – 10). Your application should then display a boarding pass indicating the person’s seat number and whether it’s in the first-class or economy section of the plane. Use a one-dimensional array of primitive type boolean to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each is assigned, set the corresponding element of the array to true to indicate that the seat is on longer available. Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it’s acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours." End the program when all the ten seats on the plane have been assigned.
No input, processing or output should happen in the main method. All work should be delegated to other non-static methods. Include the recommended minimum documentation for each method. See the program one template for more details.
Run your program, with your own data, and copy and paste the output to a file. Create a folder named, fullname_program8. Copy your source code and the output file to the folder. Zip the folder and upload it to Blackboard.
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package airlineapp;
import java.util.Scanner;
/**
*
* @author user1
*/
public class AirlineApp {
int num;
int i;
int counter = 0;
int [] seatNum = new int[11];
public static void main(String[] args) {
AirlineApp application = new AirlineApp();
application.userInput();
application.seatChart();
//create the array
// TODO code application logic here
}
public void userInput(){
Scanner input = new Scanner(System.in);
System.out.print("Please type 1 for first class and press 2 for
economy: ");
//gets the input from the user and saves it as num to perform the
rest
//of the aplication
num = input.nextInt();
}
public void seatChart(){
for(int counter = 0; counter < seatNum.length; counter++){
if(num != 2 && counter < 6 )
counter = counter + 1;
}
}
}
In: Computer Science
Compare the file storage of two types of cell phones, such as an iPhone and an Android phone. Research the amount of system software that occupies main memory after the phone is completely powered on. If the amount of storage used by the system files are substantially different, explain why that may be the case, such as platform issues, features, and so on. Cite your sources.
Cell phone configuration doesn't matter. Can pick any two types of cell phone.
In: Computer Science