Questions
NOTE: The first three are rules and do not have to be solved. Just there for...

NOTE: The first three are rules and do not have to be solved. Just there for the master theorem.

Master Theorem. Let T(n) = aT(n/b) + f(n) for some constants a ≥ 1, b > 1.

(Rule 1). If f(n) = O(n logb a− ) for some constant > 0, then T(n) = Θ(n logb a ).

(Rule 2). If f(n) = Θ(n logb a ), then T(n) = Θ(n logb a log n).

(Rule 3). If f(n) = Ω(n logb a+ ) for some constant > 0, and af(n/b) ≤ cf(n) for some constant c < 1, for all large n, then T(n) = Θ(f(n)).

1. Consider the recurrences: T(n) = 2T(n/2) + n log n. Either solve it using the Master method as given above, or explain why it can’t be solved using the Master method. If it can not be solved using Master method, use Recurrence tree method to solve it. Show your steps. If you use extended version of Master theorem to solve the same problem, does the solution thus obtained agree with the solution obtained by recurrence method?

In: Computer Science

Use C++ language Create a program which will ask the user to input three songs for...

Use C++ language Create a program which will ask the user to input three songs for a playlist (you may use TV shows or movies, if you prefer). Declare three strings to store each of the songs. Use getline to receive the input. Display output which lists each of the songs (or movies or tv shows), on separate lines, with a title on the first line: My Playlist. Insert three lines of comments at the beginning of the program for your name, today's date, and my playlist on the third line.

In: Computer Science

Create an application using PyQt. The user must be prompted for the name of a country...

Create an application using PyQt. The user must be prompted for the name of a country
(e.g. Spain) and a single character (e.g ‘a’). The application must read the name of the
country and count the number of occurrences of the character in the country name. The
count should be case-insensitive. Thus, if ‘c’ is entered as the character then both capital
letter ‘C’ and small letter ‘c’ in the string should be counted. The count must be displayed.
The application interface must include at least a label, an edit and a button. You are
welcome to enhance your application with comments and messages.

In: Computer Science

Problem 1 Write a Java program that implements a two-dimensional array of grades for students in...

Problem 1
        Write a Java program that implements a two-dimensional array of grades
        for students in a class. The grades should be as follows:
        Row 1: 87, 45
        Row 2: 69, 88, 90, 94
        Row 3: 79, 87, 94
        
        Compute and print out the maximum number of columns in the array.
        Hint: use a for loop.
        
   (5 Points.)
*/

/*      Problem 2
*       Suppose there are 4 candidates in 6 districts running for an election.
    Let's assume the candidates' names are: Jane, Amani, Doe, and Macbeth.
        Your task is to print out: 1) the total votes per candidate, and 2) the
        total votes per district.
        
        Here are some hints:
        1) Create a two-dimensional array of type int and name it ballots.
         int [][] ballots = { }. Fill it with votes. Remember, you are going to have
         four columns and six rows.
         
        2) Create the candidates as follows: String [] candidates = { } and
        assign them names.
        
        3) Create an object reference to hold the tally for the votes.
        
        4) Use a for loop to print the totals for candidates. 
        
        5) Use a for loop to print the totals for districts.
        
        Your output should look like:
        Total votes per candidate
        Jane
        x
        
        Amani
        x
        
        Doe
        x
        
        Macbeth
        x
        
        Total votes per district
        1
        x
        
        2
        x
        
        3
        x
        
        4
        x
        
        5
        x
        
        6
        x
*       (10 Points.)

In: Computer Science

Write the following assembly code file into C code. .globl main .text main:    # Tests...

Write the following assembly code file into C code.

.globl main
.text
main:
   # Tests simple looping behaviour
   li t0, 60
   li t1, 0
loop:
   addi t1, t1, 5
   addi t0, t0, -1
   bne t1, t0, loop
   bne t1, zero, success
failure:
   li a0, 0
   li a7, 93 # a7 is what determines which system call we are calling and we what to call write (64)
    ecall # actually issue the call
  
success:
   li a0, 42
   li a7, 93
   ecall
  

In: Computer Science

Cite an instance when you should consider "making" new technology Cite an instance when you should...

  1. Cite an instance when you should consider "making" new technology
  2. Cite an instance when you should consider "buying" new technology
  3. Cite an instance when you should consider "modifying" existing technologies to create a new one.

In your citations, include the following:

  1. What technology do you wish to develop?
  2. What are the resources available or lacking which would make consider this option?  

In: Computer Science

HTML 7.20 A palindrome is a number or a text phrase that reads the same backward...

HTML

7.20

A palindrome is a number or a text phrase that reads the same backward and forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a script that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an alert dialog indicating the problem to the user. Allow the user to enter a new value after dismissing the alert dialog. [Hint: It’s possible to do this exercise with the techniques learned in this chapter. You’ll need to use both division and remainder operations to “pick off” each digit.]

In: Computer Science

Matrix Multiplication with Threads - C/C++ **Please read entire question before answering** **Please don't copy /...

Matrix Multiplication with Threads - C/C++

**Please read entire question before answering**
**Please don't copy / paste code**

In this assignment you will use the Pthreads library to write a program that multiplies two square arrays and compare the difference between the imperative and parallel implementations of this algorithm.

Use the matrix mulltiplication algorithm.

Write a program that contains three functions:

(1) A function that has an integer as a parameter and returns a pointer to square array of integers (i.e. both dimensions should be equal). The function should allocate storage from the heap and randomly fill that dynamically allocated array.

(2) A function that uses the algorithm described above to compute the matrix square of an array. It should be passed a pointer to an array of integers and an integer defining the dimensions of the array. It should return a pointer to the array containing the product.

(3) A function that uses pthreads to compute the matrix square of an array. This function should have the same parameters and return values of the previous function

The main() function in your program needs to use these functions to compute the square of matrices with 100, 500, 1000, 5000, and 10000 integers
Assume that the values used for the size of these square arrays will always be even.

My suggestion is to think about dividing each array into smaller and smaller pieces until you reach some reasonably small size. At that point multiply the matrices using the iterative algorithm.

In: Computer Science

Create a program that asks the user for two positive integers. If the user's input for...

Create a program that asks the user for two positive integers. If the user's input for either integer is not positive (less than or equal to 0), re-prompt the user until a positive integer is input. You may assume that all inputs will be integers.

Print out a list, ascending from 1, of all divisors common to both integers. Then, print out a message stating whether or not the numbers are "relatively prime" numbers. Two positive integers are considered relatively prime if, and only if, the only common divisor they have is 1.

For example, if the user inputs 8 and 12 the output should be:

Common divisors of 8 and 12:

1

2

4

8 and 12 are not relatively prime.

If the user inputs 8 and 9, on the other hand, the output should be:

Common divisors of 8 and 9:

1

8 and 9 are relatively prime.

Starter Code:-

import java.util.Scanner;

public class RelativelyPrime {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in); //Scanner to get user input
  
//TODO
//Complete the program
  
}
}

In: Computer Science

The purpose of this assignment is to build the business calculator using supporting files built inTopics...

The purpose of this assignment is to build the business calculator using supporting files built inTopics 4 and 5.Create a Java application file named RPN.java containing a main method by using the ForthStack.java and associated files from Topic 5.The application should have one text box for numeric data entry, one text box for numeric display, one text box for error display, and buttons labeled "+", "-", "*", "/","dup", "2dup", "clr", "pop" and "push." The actions of the controls should be as follows.oThe text box for numeric display should display the top element of the stack, or blank if the stack is empty.oThe text box for numeric data entry should allow the user to type in a valid numeric value.oThe text box for error display should display an error message from the previous operation (if any), or be blank if the last operation was successful.oThe buttons labeled "+", "-", "*", "/", "dup", "2dup", "clr", and pop should invoke the corresponding methods in ForthStack; "pop" should remove and discard the top item on the stack, and "push" should push the numeric value in the numeric data entry box onto the stack and clear the numeric data entry box.oAll button operations should update the display of the top of the stack.The size of the stack used should be four, no more or less, in order to standardize testing.After thoroughly testing the program, submit the AbstractStack.java, ArrayStack.java,Forth.java, ForthStack.java, TestForthStack.java, and RPN.java

STACK CODE:

ArrayStack.java

import java.util.Arrays;

public class ArrayStack extends AbstractStack {
//Attributes
private double[] array;
private int size;
private int num;
  
//Default constructor
public ArrayStack() {
array = new double[3];
size = 3;
num = 0;
}
  
//Parametrized Constructor
public ArrayStack(int a){
array = new double[a];
size = a;
num = 0;
}
  
//Insert a new element
public void push(double a){
if (num < size) {
array[num] = a;
num++;
System.out.println("Success");
}
else {
throw new ArrayIndexOutOfBoundsException("Failure! Stack is full");
}
}
  
//Take out last inserted value
public double pop(){
if (num > 0){
num--;
return array[num];
}
else {
throw new ArrayIndexOutOfBoundsException("Stack is empty");
}
}
//Check stack empty or not
public boolean isEmpty(){
return (num == 0);
}
//Get top element from stack
public double peek() {
return peek(num-1);
}
//Get specified index element
public double peek(int n){
try
{
if (num > 0){
if (n < 0 || n >= num)
return -1;
else
return array[n];
}
else{
System.out.println("Stack is empty");
return -1;
}
}catch(Exception e ){
e.printStackTrace();
}
return 0;
}
//Number of elements in stack
public int count(){
return num;
}
public void clear() {
size=0;;
num=0;
}
  
}

public class FourthStack extends ArrayStack implements Fourth{
//Parameterized constructor
public FourthStack(int sz) {
super(sz);
}

@Override
//Pop 2 elements from stack and add values
//Push into stack
public void add() {
if(super.count()<2) {
throw new ArrayIndexOutOfBoundsException("Not enough elements to pop");
}
else {
super.push(super.pop()+super.pop());
}
}

@Override
//Pop 2 elements from stack and subtract second from first
//Push into stack
public void sub() {
if(super.count()<2) {
throw new ArrayIndexOutOfBoundsException("Not enough elements to pop");
}
else {
super.push(super.pop()-super.pop());
}
}

@Override
//Pop 2 elements from stack and multiply values
//Push into stack
public void mul() {
if(super.count()<2) {
throw new ArrayIndexOutOfBoundsException("Not enough elements to pop");
}
else {
super.push(super.pop()*super.pop());
}
}

@Override
//Pop 2 elements from stack and divide second from first values
//Push into stack
public void div() {
if(super.count()<2) {
throw new ArrayIndexOutOfBoundsException("Not enough elements to pop");
}
else {
super.push(super.pop()/super.pop());
}
}

@Override
//peek an element and make duplicate
//Push into stack
public void dup() {
if(super.count()<1) {
throw new ArrayIndexOutOfBoundsException("Not enough elements to pop");
}
else {
super.push(super.peek());
}
  
}

//Peek 2 elements from stack and make their duplicate
//Push into stack in same order
@Override
public void twoDup() {
if(super.count()<2) {
throw new ArrayIndexOutOfBoundsException("Not enough elements to pop");
}
else {
double first=super.peek();
double second=super.peek(super.count()-2);
super.push(second);
super.push(first);
}
}

}

import java.util.Scanner;
/**
* Test implemented functions
* @author deept
*
*/
public class TestFourthStack {
public static void main(String [] args){
//Variables for input
int choice;
int pek;
double val,poped;
boolean empty;
//Keyboard read
Scanner sc =new Scanner(System.in);
FourthStack as = new FourthStack(20);
//Loop until exit
while(true){
//User choices
System.out.println("1. Enter a Value in stack");
System.out.println("2. Pop a Value");
System.out.println("3. Check If array is Empty");
System.out.println("4. Peek Function");
System.out.println("5. Clear Stack");
System.out.println("6. Add Function");
System.out.println("7. Sub Function");
System.out.println("8. Mul Function");
System.out.println("9. Div Function");
System.out.println("10. Dup Function");
System.out.println("11. TwoDup Function");
System.out.println("0. Exit\n");
choice = sc.nextInt();
//Execute each choice
switch(choice){
case 1:
System.out.print("Enter a value To push : ");
val = sc.nextDouble();
as.push(val);
break;
case 2:
poped = as.pop();
System.out.println("Popped : "+poped);
break;
case 3:
empty = as.isEmpty();
System.out.println("Empty ? "+empty);
break;
case 4:
poped = as.peek();
if(poped != -1)
System.out.println("Peeked Value : "+poped);
else
System.out.println("Oops it was not a valid index this place is empty");
break;
case 5:
as.clear();
break;
case 6:
as.add();
break;
case 7:
as.sub();
break;
case 8:
as.mul();
break;
case 9:
as.div();
break;
case 10:
as.dup();
break;
case 11:
as.twoDup();
break;
case 0:
System.exit(0);
}
}
}
}

/*
* Pure abstract class without implementation
*/
public abstract class AbstractStack {
public abstract void push(double item);
public abstract double pop();
public abstract boolean isEmpty();
public abstract double peek();
public abstract void clear();
}


/*
* Interface to generate sum additional functions using stack
*/
public interface Fourth {
public void add();
public void sub();
public void mul();
public void div();
public void dup();
public void twoDup();
}

I PROVIDED THE FIVE PREVIOUS STACKS THAT I USED ON MY PREVIOUS WORK... LET ME KNOW IF THERE'S ANYTHING ELSE


Everything should be attached as requested, and i emailed you all the attachments

In: Computer Science

Fill in the blank for this common use of the for loop in processing each character...

Fill in the blank for this common use of the for loop in processing each character of a string.

for _____________________________________________________

{

    char ch = str.charAt(i);

    // process ch

}

Insert the missing statement in the following code fragment prompting the user to enter a positive number.

    double value;

    do

    {

    System.out.print("Please enter a positive number: ");

    value = in.nextDouble();

    }

    _____________________________________

The following for loop is executed how many times?

for (x = 0; x <= 10; x++)     

Consider the following for loop:

for (i = 0; i < str.length(); i++)

{ ... }

and the corresponding while loop:

i = 0;

while __________________________________

{

    . . .

    i++;

}

Fill in the blank for the while loop condition that is equivalent to the given for loop?

Write a for loop that is equivalent to the given while loop.

i = 1;

while (i <= 5)

{

    . . .

    i++;

}

In: Computer Science

1Write an SQL statement utilizing the WHERE, LIKE, and HAVING clauses that select gender, and the...

1Write an SQL statement utilizing the WHERE, LIKE, and HAVING clauses that select gender, and the email addresses that belong to female users and have an email address that contains a number (0 to 9) within it. Create an alias for the resultant email column name and name it ‘Email Addresses Female With Numbers’

  1. IPV4 (Internet Protocol Version 4) addresses utilize a notation known as the dotted-quad notation. Quad because an IPV4 address is actually a series of 4 numbers separated by a dot (hence dotted quad). Each one of the numbers has a range of 0-255. For example 255.0.65.23 is a valid IPV4 address, and so is 2.2.2.2. However, 2682.586.549.365 is NOT a valid IPV4 address (thank me later for not using IPV6 addresses for this – Google IPV6 and you will see what I mean).

    1. Write an SQL insert statement that will insert 4 rows with invalid IPV4 addresses.

    2. Write an SQL statement that will find all the rows with invalid IPV4 addresses.

      1. To do this you will need to utilize regular expressions. This is the research

        component of the lab.

      2. Regular expression documentation:

        https://dev.mysql.com/doc/refman/5.6/en/regexp.html

      3. You can look up the regular expression, you do not have to write one from scratch, but it is always a good thing to look up the syntax of regular expressions to be able to understand them.

      4. You need to validate that there are 4 numbers separated by dots each with a length of 1-3 (e.g., 999.999.999.999 is considered a valid IP address in your regular expression even though it is not in reality). Validating that there are 4 numbers separated by dots each with a length of 1-3 AND are less than 256 is a little complicated, but I encourage you to take on the challenge.

      5. By now you should see how the query from b can be created in a much cleaner fashion.

In: Computer Science

given pair (a,b) after each unit of time pair (a,b) get changed to (b-a,b+a).you are given...

given pair (a,b) after each unit of time pair (a,b) get changed to (b-a,b+a).you are given the initial value of pair and an integer n and you to print the value of pair at the nth unit of time.

input format:

1.First line:t donating the number of test cases

2.Next t lines:three space-seperated integer a,b and n

output format :

for each test case ,print two integers (mod 10^9 +7) per

line denoting the value of the pair at the n th unit time.

constrains:

1<t< 10^6

0< a<b<10^9

1<n<10^5

sample input :

5

1 3 5

2 3 9  

sample output

4 12

32 48

81920 131072

In: Computer Science

The purpose of this problem is to gain familiarity with stacks and queues. You have three...

The purpose of this problem is to gain familiarity with stacks and queues. You have three jugs that can hold c1, c2, and c3 liters of water, respectively. Initially, jug 1 is full and the other two jugs are empty. You can repeat the following procedure any number of times: Choose two of the jugs and pour the contents of one into the other until either the first is empty or the second is full. Your goal is to end up with exactly d liters in one of the jugs. Make a program called WaterTransfer.java to determine the transfers required to reach the goal. The input is a single line containing four integers between 2 and 100 (inclusive) representing c1, c2, c3, and d. The output is a minimal sequence of jug contents, starting with the initial contents and ending with one of the jugs containing d liters. Each line of the output should consist of 3 integers separated by spaces. If no solution exists, then your program should produce no output.

Good test case: 10 5 3 4 ; from movie ”Die hard: with a vengeance”; seehttps://www.youtube.com/watch?v=6cAbgAaEOVE

For example, if the input is 20 5 3 4t hen a valid output is

20 0 0

15 5 0

15 2 3

18 2 0

18 0 2

13 5 2

13 4 3

There may be other solutions, but none with fewer transfers (6) than this one. (this code should probably use queues)

In: Computer Science

T/F: A function may not execute every line of code in the function if it returns...

T/F: A function may not execute every line of code in the function if it returns a value to the user before getting to the remaining lines.

A. True
B. False

In: Computer Science