Questions
Using C language, and describe the algorithm design Q2 Problem description n (n is odd) people...

Using C language, and describe the algorithm design

  • Q2 Problem description

n (n is odd) people sitting around a round table playing a game. In this situation, everyone has a left neighbour and a right neighbour. At the beginning, each of them is holding a whiteboard with an integer number. Now, they are playing a game consisting of several rounds. In each round, everyone will first look at the numbers of his/her left neighbour and right neighbour, then calculate the average of the two numbers, replace the number on his/her whiteboard with the average finally. The game terminates when any one has to write a non-integer number on his/her whiteboard.

Given the number of people, the number of passed rounds and the integer numbers on their whiteboards at this moment, you are asked the integer numbers on their whiteboards at the very beginning. The number of rounds increases by 1 when changing the number on the whiteboard and new numbers are all integers.

  • Input & output requirements

Input the number of people n and the number of rounds t on the first line. On the next line are numbers on their whiteboards after t rounds.

Output the integer numbers on their whiteboards at the very beginning.

  • Sample input

3 2

3 1 2

  • Sample output

6 -2 2

In: Computer Science

Write a program to ask three options to the user and continue until user selects option...

Write a program to ask three options to the user and continue until user selects option 3.

The first two options prompt a user to enter a string of numbers separated by spaces which is a 2by2 matrix. Do addition and subtraction on the input matrices when user selects 1 and 2.

You must write functions for matrix addition, subtraction and print. You may use the following function str_to_mlist to convert string to a list.

code example is given:

def str_to_mlist(m_str):
"""Converts a string separated by spaces to a list

Parameters
----------
m_str : str, required
Input string separated by spaces
Returns
-------
list
Numbers
"""
    return m_str.split()

A sample run of the code looks like this:

Enter an option
1.Add two matrices
2.Subtract two matrices
3.Quit
1
Enter four numbers separated by spaces and press enter:3 4 -10 3
3 4
-10 3
Enter four numbers separated by spaces and press enter:8 9 0 -2
8 9
0 -2
Your result is:
11 13
-10 1
Enter an option
1.Add two matrices
2.Subtract two matrices
3.Quit
2
Enter four numbers separated by spaces and press enter:1 0 0 1
1 0
0 1
Enter four numbers separated by spaces and press enter:0 -1 -1 0
0 -1
-1 0
Your result is:
1 1
1 1
Enter an option
1.Add two matrices
2.Subtract two matrices
3.Quit
3

In: Computer Science

Determine the running time of each of the algorithms below. For questions 2a. and 2b., you...

Determine the running time of each of the algorithms below. For questions 2a. and 2b., you may determine the running time line-by-line (see Lecture 2, slide No. 8). For questions 2c – 2f, you may determine the running time by focusing on the basic operation of the algorithm.

a,sum = 0; for (i=1; i<=n; i++) sum += n;

b. Algorithm maxVal (numbers, n) currentVal ← numbers [0] for i ← 1 to n − 1 do if numbers [i] > currentVal then currentVal ←A[i] { increment counter i } return currentVal

c. Algorithm prefix1(X, n) //Input array X of n integers //Output array A of prefix averages of X A ← new array of n integers for i ← 0 to n − 1 do s ←X[0] for j ← 1 to i do s ←s + X[j] A[i] ←s / (i + 1) return A

d. Algorithm prefix2(X, n) //Input array X of n integers //Output array A of prefix averages of X A ← new array of n integers s ← 0 for i ← 0 to n − 1 do s ←s + X[i] A[i] ←s / (i + 1) return A

e. Algorithm SumTripleArray(X, n) //Input triple array X[][][] of n by n by n integers //Output sum of elements of X s ← 0 for i ← 0 to n − 1 do for j ← 0 to n − 1 do for k ← 0 to n − 1 do s ←s + X[i][j][k] return s

f. sum = 0; for( i = 0; i < n; i++) for( j = 0; j < n * n; j++) sum++;

In: Computer Science

Revisit Shneiderman’s 8 Golden Rules and answer the following questions. Which rules still apply? Which rules...

Revisit Shneiderman’s 8 Golden Rules and answer the following questions.

  1. Which rules still apply?
  2. Which rules apply but require modification?
  3. Do any rules no longer apply?
  4. Do we need new rules for Mobile Apps?

PreviousNext

In: Computer Science

Traversal tree program

Traversal tree program

In: Computer Science

Venn Diagram It is much easier to use Venn Diagrams to proof the DeMorgan's Law. Please...

Venn Diagram

It is much easier to use Venn Diagrams to proof the DeMorgan's Law. Please briefly explain Venn diagrams and Sets.

In: Computer Science

[1] Briefly, what is the difference between: 1- Buffering & Spooling. 2- Synchronous & Asynchronous I/O....

[1] Briefly, what is the difference between:

1- Buffering & Spooling.

2- Synchronous & Asynchronous I/O.

3- CPU-bound & I/O-bound jobs.

4- Multiprogramming & Timesharing.

5- Logical & Physical addresses.

6- User & Monitor modes in Operating System.

[2] (i) Define Timesharing.

(ii) In a one processor system, there is an interrupt clock which is set to a “time slice Q”, that is, every Q an interrupt occurs to stop the process. There is only one I/O device in the system which is interrupted when the process needs an I/O. There are 3 processes A, B, C.

Process A executes an I/O interrupt every T units of time.

Process B executes an I/O interrupt every 2T units of time.

Process C executes an I/O interrupt every 3T units of time.

(a) Which of the above processes will benefit the most and which is not when Q = T.

Explain your answer

(b) Which of the above processes will benefit the most and which is not when Q = 2T.

Explain your answer

(a) Which of the above processes will benefit the most and which is not when Q = 3T.

Explain your answer

What is the best value should Q takes for good performance ? explain your answer in full.

In: Computer Science

CAN I HAVE A 200 WORD EXPLANATION FOR THE FOLLOWING QUESTION. Analyse the security of Lamport’s...

CAN I HAVE A 200 WORD EXPLANATION FOR THE FOLLOWING QUESTION.

Analyse the security of Lamport’s OLP algorithm with the properties of hash function

In: Computer Science

You have been asked to prepare an Issue Specific Security Policy (ISSP) on email, instant messaging...

You have been asked to prepare an Issue Specific Security Policy (ISSP) on email, instant messaging and other electronic communications tools. When preparing this policy outline two elements of the policy you must consider and specifically address?

In: Computer Science

Great Food Restaurants (GFR), is a national chain of restaurants with locations in all 50 states....

Great Food Restaurants (GFR), is a national chain of restaurants with locations in all 50 states. The GFR relational database consists of nine tables as shown below. Note the following information about GFR and its database:

  • Each restaurant has a unique restaurant number.
  • Restaurant size is measured in square feet. Restaurant capacity is the number of patrons the restaurant can seat at one time.
  • Suppliers supply food to GFR restaurants. Supplier name is unique in the SUPPLIER table.
  • GFR has an aggressive marketing campaign in which it tracks each customer as they patronize GFR restaurants. Customer number is unique across the country.
  • In the VISIT table, the Bill is the amount of money the customer spent in a particular GFR restaurant on a particular day. Assume that a customer can go to a particular restaurant only once in a given day.
  • Employee number is unique across the GFR chain. In terms of employment, GFR is interested in keeping track only of the GFR restaurant that an employee currently works in.
  • State names and region names are unique.
  • Inspector numbers are only unique within a state.
  • Assume that all states score restaurant inspections on the same 1-100 scale.

RestNum

Address

City

State

Size

Capacity

AnnualSales

RESTAURANT

SuppName

City

State

Phone

YearFounded

SUPPLIER

RestNum

SuppName

Food Type

Date

Cost

FOODDELIVERY

CustNum

Name

CellPhone

City

State

CUSTOMER

RestNum

CustNum

Date

Bill

VISIT

EmpNum

EmpName

YearHired

JobTitle

Salary

RestNum

EMPLOYEE

State

Region

InspectionOfficePhone

InspectionCommissionerName

STATE

State

InspectorNum

InspectorName

InspectorEmail

INSPECTOR

RestNum

State

InspectorNum

Date

Score

INSPECTION

There are 6,000 records in the RESTAURANT table.

There are 200 records in the SUPPLIER table.

There are 1.5 million records in the FOODDELIVERY table.

There are 450,000 records in the CUSTOMER table.

There are 15 million records in the VISIT table.

There are 500,000 records in the            EMPLOYEE table.

There are 50 records in the STATE table.

There are 300 records in the INSPECTOR table.

There are 98,000 records in the INSPECTION table.

Questions

1. What would you do to improve the performance of queries to find a customer by name or would you do nothing? Why?

2. What would you do to improve the performance of queries to find a supplier by phone number or would you do nothing? Why?

3. What would you do to improve the performance of queries requiring a list of the complete records of every GFR restaurant in Tennessee together with a list of their employees, including employee number, name, and salary or would you do nothing? Why?

4. What would you do to improve the performance of a query that seeks the salary of the highest paid employee of any GFR restaurant in Tennessee or would you do nothing? Why?

In: Computer Science

Write a python or java code which can calculate the Shapely-Shubik and Banzhaf indices to determine...

Write a python or java code which can calculate the Shapely-Shubik and Banzhaf indices to determine which state in America has the most power in the primary election.

In: Computer Science

Python: Write a function named power() that calculates rootpow recursively. It receives two arguments root (float)...

Python: Write a function named power() that calculates rootpow recursively. It receives two arguments root (float) and pow (int) > = 1, and it returns the result root raised to power pow. The recursion of the power function is defined as: Base case: rootpow = root, if pow = 1 Recursive case: rootpow = root* rootpow-1 , otherwise. b) Develop a greatestC( ) function that determines the greatest common divisor of two integer numbers. Test greatestC() in a simple main program on the following numbers: 12 and 24; 50 and 10; 33649 and 17043. The recursive definition of the gcd function is as follows: Base case: greatestC(x, y) = x if y = 0 Recursive case: greatestC(x, y) = greatestC(x, x % y) otherwise, where % is the modulus operator.

In: Computer Science

the best document to use to obtain information in order to make a decision on a...

the best document to use to obtain information in order to make a decision on a system. As a systems analyst, explain to management the two types of documents available and what they are used for

In: Computer Science

Simultaneous TCP connection initiations are rare, but simultaneous connection termination is relatively common. How do two...

  • Simultaneous TCP connection initiations are rare, but simultaneous connection termination is relatively common. How do two TCP nodes negotiate the simultaneous sending of FIN packets to one another? Draw the ladder diagram, and label the states on each side. Which node goes into TIMEWAIT state?

In: Computer Science

Using one of the referenced website articles or an article of your choice, to discuss how...

Using one of the referenced website articles or an article of your choice, to discuss how to reduce the cost of paging to disk because frequent paging is prohibitive.

In: Computer Science