1. Read the Netflix Challenge Preview the document – datacenter edition paper to understand the relationship between the Netflix challenge and the cluster resource allocation problem.
2. Quasar Preview the document classifies resource allocation for scale-up, scale-out, heterogeneity, and interference. Why are classification criteria important, and how are they applied?
3. What are stragglers and how does Quasar deal with them?
In: Computer Science
Using Jeliot, execute the following tree algorithm:
import Prog1Tools.IOTools;
class Node {
Node
left;
Node
right;
int
value;
public Node(int value) {
this.value = value;
}
}
public class GeneralTreeTest {
public static void
main(String[] args) {
// build a simple tree add 5 nodes to the tree
Node root =
new Node(5);
System.out.println("Tree Example");
System.out.println("Building tree with root value " +
root.value);
insert(root,
1);
insert(root,
8);
insert(root,
6);
insert(root,
3);
insert(root,
9);
System.out.println("Traversing tree ");
printOrder(root);
}
public static void insert(Node node, int
value) {
if (value
< node.value) {
if (node.left != null) {
insert(node.left, value);
} else {
System.out.println(" Inserted " + value + " to left of "
+ node.value);
node.left = new Node(value);
}
} else if (value
> node.value) {
if (node.right != null) {
insert(node.right, value);
} else {
System.out.println(" Inserted " + value + " to right of "
+ node.value);
node.right = new Node(value);
}
}
}
public static void printOrder(Node node)
{
if (node != null)
{
printOrder(node.left);
System.out.println(" Traversed " + node.value);
printOrder(node.right);
}
}
}
This algorithm first inserts five nodes into a tree structure and then traverses the tree. Using the Jeliot environment, load, compile and execute this java algorithm to understand its operation. Determine the kind of tree structure that is being created and determine what kind of traversal the algorithm is conducting.
Finally, conduct an Asymptotic analysis for the provided algorithm and report your analysis including Big O, Big Omega, or Big Theta as appropriate. Post your findings to the discussion forum and review and respond to the postings of your peers.
If you have arrived at a different answer or analysis than your peers, discuss your findings with your peers and attempt to determine whose analysis is most accurate.
In: Computer Science
x=61,y=73 compute x+y and x-y in8-bit 2's complement system, then convert the answer to decimal
In: Computer Science
How are primitive and reference types different an examples of how copying works differently for these two types.
In: Computer Science
Write a program that calculates how many digits an integer value acquired via scanf() contains. A correctly functioning program should produce the following output, where the user entered the value 374:
Enter a number: 374
The number 374 has 3 digits
You may assume that the input integer has no more than four digits.
Use if statements to test the number. For example,
if the integer value entered by the user is between 0 and 9, it has
one digit. If the integer value is between 10 and 99, it has two
digits.
Rewrite the program without using if or switch statements. Instead use a do-while loop.
When implemented correctly, the user should be able to input any integer value (that will fit in a storage variable of type int) and its number of digits will be correctly determined without you needing to implement special logic for each possible quantity digits.
Hint:
The number of digits is very simply related to the number of
times the input integer value may be divided by
10.
In: Computer Science
Question: Not sure how to proceed with question below:
In this task, task 2(a) will be extended so that an array of
five Person objects are created. Write the comma
separated values format of each object in separate lines in a file
named persons.txt. Make use of the
toString() method of Person to obtain comma separated values.
Create a hyperlink pointing to the file persons.txt and include it
on the task page. When the user clicks
on the link, the browser can then download it.
This is question 2a below: not need to be answered
Task 2: Chapter 14: page name=task2.php 40 marks
This task consists of two different subtasks.
(a) [15 marks]
Code a class named Person, which has three data properties to store
the name, a telephone number and
an e‐mail address of a person.
The class must have a constructor to initialise all three data
properties, three set methods and three get
methods to change and access the data properties of the
class.
The class must also have a toString() method with an argument named
$csv initialised to a default
boolean value true. By default, this function must return the value
of data properties in comma separated
values (refer to Chapter 23, Section named ‘How to read and write
CSV data’). On the other hand, if the
method is called with boolean value false, it returns a string
representation of the data properties in a
different format (for example, see showAll() method in Section ‘How
to loop through an object’s
properties’ in Chapter 14).
Create an object of the class Person, invoke all six set and get
methods, and invoke toString() with
both boolean values. Display the results returned by toString()for
both method calls.
In: Computer Science
Write functions that do the following in Python:
i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters.
ii) A function that takes 2 arguments and returns the difference,
iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
In: Computer Science
Examples:
The Lab is divided into a set of example and exercise activities related with this topic and students are required to perform all activities and show (and discuss) the output of activities to the instructor.
Example 1: Implement the Stack Push Operation with Overflow condition
Declare an array of size 5 and implement the Push Operation with overflow condition; you can type the following code as a hint:
#include<iostream>
using namespace std ;
#define MAX 5
struct Stack {
int S[MAX];
int top;
};
Stack st;
st.top = -1;
int item;
if(st.top == (MAX-1))
cout<<"Stack Overflow\n" ;
else
{
cout<< "Enter the item to be pushed in stack : " ;
cin>> item ;
st.top++;
st.S[st.top] = item;
}
Complete this implementation as a full program to PUSH as many elements as the user wants (or till the Stack is full).
Example 2: Implement the Stack Pop Operation with Underflow condition
Declare an array of size 5 and implement the Pop operation; you can type the following code as a hint:
int item;
if (st.top == -1) /* stack empty condition */
cout<< "Stack Underflow\n" ;
else
{
item = st.S[st.top];
st.top-- ;
cout<< "Element popped from stack is :" << item ;
}
Complete this implementation as a full program to POP as many elements as the user wants (or till the Stack is empty).
Example 3: Display the contents of Stack
Display the contents of Stack; you can type the following code as a hint:
int i;
if(st.top == -1)
cout<<"Stack is empty\n" ;
else
{
cout<< "Stack elements :\n" ;
for(i = st.top; i >=0; i--)
cout<< st.S[i] ; }
Exercise
Combine all the three examples above to implement one complete program of Stack
In: Computer Science
QUESTION 5
Consider the following Die class:
class Die {
public:
void setValue(int x);// assign x to num
int getValue(); // return num
void roll(); // set num with a random number ranging 1-6
Die(); // constructor
private:
int num;
};
Which of the following C++ code segment will correctly find that how many times a Die object will be rolled until the value '6' is obtained.
|
Die myDie; |
||
|
Die myDie; |
||
|
Die myDie; |
||
|
Die myDie; |
3 points
QUESTION 6
Consider the following statements.
struct supplierType {
string name;
int supplierID;
};
struct paintType {
supplierType supplier;
string color;
string paintID;
};
paintType paint;
Which stataement is correct?
|
paint.name="Sherwin-Williams"; |
||
|
paintType.supplyType.name="Sherwin-Williams"; |
||
|
paint.supplier="Sherwin-Williams"; |
||
|
paint.supplier.name="Sherwin-Williams"; |
In: Computer Science
In C programming
Declare two 2d arrays n0[MAX_ROW][MAX_COL], n1
[MAX_ROW][MAX_COL].
Then, loop through the 2d array and save the results in n0 and
n1:
for (i=0; i<MAX_ROW; i++)
for (j=0; j<MAX_COL;j++){
//calculate number of
zeros around entry a[i][j]
n0[i][j] =
//calculate number of
ones around entry a[i][j]
n1[i][j] =
}
Set the MAX_ROW and MAX_COL to a small number and display all three 2d arrays on the screen to verify that the calculations are correct. You may still use command-line inputs as in the example program to set the actual size of the array (must be less than or equal to MAX_ROW, MAX_COL.
In: Computer Science
(a) Write code segments to perform the following:
(i) declare and create a boolean array flagArray of size 5
(ii) declare and initialize an array amount which contains 39.8, 50 and 45
(iii) declare a Keyboard array of size 3 with name keyboard and initialize it with Keyboard objects using one statement
(b) A incomplete definition of a class Cash is given below: public class Cash { private double value[] = {10.5, 20, 5.5, 7.8}; }
(i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of the method as the answers to this part.
(ii) Write another class TestCash in a separate file with a method main() to test the class Cash. In main(), create a Cash object cash and print its values by calling toString(). Run the program. Copy the content of the file and the output showing the message as the answers to this part.
(iii) Add a method decreasePercent(int index, double percent) to the Cash class which decreases the element with subscript index of the value array by the percentage percent without returning anything. Also add a method getValue(int index) to return value[index]. Copy the content of the methods as the answers to this part.
(iv) Add another method countBelow(double threshold) to the Cash class which returns the number of values which are less than threshold. Copy the content of the method as the answers to this part.
(v) Add another method minimumIndex() to the Cash class which returns the index of the minimum value in the array. Copy the content of the method as the answers to this part. You can assume there is only one minimum value.
(vi) Add another method trimmedMean() to the Cash class which returns the average value which excludes the (unique) largest value and (unique) smallest value in the calculation. You should use minimumIndex() to get the index of the minimum value. Note that this method should work without any modifications when the number of values, which is at least three, is changed. Copy the content of the method as the answers to this part.
(vii) Perform the tasks listed below in main() of TestCash: * print the second value from the left, decrease it by 10% using the method decreasePercent(), and print the new value; * calling countBelow()to count the number of values less than 15 and then print it; * print the index of the minimum value and the trimmed mean. Run the program. Copy the content of the class and the output as the answers to this part.
In: Computer Science
You are to create a class called Person. You should create the definition of the class Person in a file person.h and the functions for Person in person.cpp. You will also create a main program to be housed in personmain.cpp.
A Person will have attributes of
A Person will have the following methods
personmain.cpp should perform the following actions
In: Computer Science
In: Computer Science
For this exercise, you are going to write your code in the FormFill class instead of the main method. The code is the same as if you were writing in the main method, but now you will be helping to write the class. It has a few instance variables that stores personal information that you often need to fill in various forms, such as online shopping forms.
Read the method comments for more information.
As you implement these methods, notice that you have to store the result of concatenating multiple Strings or Strings and other primitive types. Concatenation produces a new String object and does not change any of the Strings being concatenated.
Pay close attention to where spaces should go in theString, too.
FormFillTester has already been filled out with some test code.
Feel free to change the parameters to print your own information.
If you don’t live in an apartment, just pass an empty String for
the apartment number in setAddress.
Don’t put your real credit card information in your program!
When you run the program as written, it should output
Dog, Karel 123 Cherry Lane Apt 4B Card Number: 123456789 Expires: 10/2025
public class FormFill
{
private String fName;
private String lName;
private int streetNumber;
private String streetName;
private String aptNumber;
// Constructor that sets the first and last name
// streetNumber defaults to 0
// the others default to an empty String
public FormFill(String firstName, String lastName)
{
}
// Sets streetNumber, streetName, and aptNumber to the given
// values
public void setAddress(int number, String street, String apt)
{
}
// Returns a string with the name formatted like
// a doctor would write the name on a file
//
// Return string should be formatted
// with the last name, then a comma and space, then the first
name.
// For example: LastName, FirstName
public String fullName()
{
}
// Returns the formatted address
// Formatted like this
//
// StreetNumber StreetName
// Apt AptNumber
//
// You will need to use the escape character \n
// To create a new line in the String
public String streetAddress()
{
}
// Returns a string with the credit card information
// Formatted like this:
//
// Card Number: Card#
// Expires: expMonth/expYear
//
// Take information as parameters so we don't store sensitive
information!
// You will need to use the escape character \n
public String creditCardInfo(int creditCardNumber, int expMonth,
int expYear)
{
}
}
public class FormFillTester
{
public static void main(String[] args)
{
FormFill filler = new FormFill("Karel", "Dog");
filler.setAddress(123, "Cherry Lane", "4B");
System.out.println(filler.fullName());
System.out.println(filler.streetAddress());
System.out.println(filler.creditCardInfo(123456789, 10,
2025));
}
}
In: Computer Science
Radix sort was proposed for sorting numbers, but if we
consider a number as a string of digits, the
algorithm can be considered as a string sorting algorithm. In this
project you are asked to
implement a radix sort algorithm forsorting strings in ascending
order. The input to your algorithm
should be a (multi)set S = [S1, S2, . . . , Sn] of strings each of
which is of length m over the English
alphabet [A…Z, a…z]. The output should be the set sorted in
ascending lexicographical order.
Notes:
• For simplicity you my limit the number of stings n (or |S| ) to
100 and the number of characters
(digits) m in each string Si to 50.
• You should use the cursor implementation of the linked list data
structure to store characters in
your buckets.
• You are allowed to use only character comparisons. Thus, you are
not allowed to use the String
library functions.
• You should sort all characters starting at position k, where k is
the position of the most
significant digit dk in the string ( e.g., in the string “BirZeit”
t is the character in the least
significant digit while B is the character in the most significant
digit).
Example: the set {data, structures, and, algorithms, in, C} should
be sorted as follows:
a l g o r i t h m
a n d
C
d a t a
i n
s t r u c t u R e s
Notice that in the first pass, the strings and and algorithm would
be placed in one bucket since the
first character in both is a. In the second pass, however, the
strings will be reordered since l comes
before n in lexicographical order. Same applies for the remaining
passes
In: Computer Science