Explain the shortest seek time first, first come first serve, scan, and c scan algorithms of storage management algorithms with the single of the sequence (93, 176, 42, 148, 14, 180).
Draw good diagrams and CALCULATE the total distance traveled and the total waiting time.
initial position is at 50
In: Computer Science
In: Computer Science
1. Give, using “big oh” notation, the worst case running times of the following procedures as a function of n ≥ 0.
(a). procedure unknown
for i =1 to n – 1 do
for j =i + 1 to n do
for k =1 to j do
{statements requiring O(1) time}
endfor
endfor
endfor
(b). procedure quiteodd
for i =1 to n do
if odd(i) then
for j =i to n do
x ← x + 1
endfor
for j =1 to i do
y ← y + 1
endfor
endif
endfor
(c). function recursion (n)
if n <= 1 then
return (1)
else
return (recursion (n – 1) + recursion (n – 1))
endif
2.
The function max (i, n) given below returns the largest element in positions i through i + n – 1 of an integer array A. Assume for convenience that n is a power of 2.
function max(i, n)
if n = 1 then
return (A[i])
else
m1 ← max (i, n/2)
m2 ← max (i + n/2, n/2)
if m1 < m2 then
return (m2)
else
return (m1)
endif
endif
(a). Let T(n) denote the worst-case time taken by max with the second argument n. Note that n is the number of elements of which the largest is to be determined. Write an equation expressing T(n) in terms of T(j) for j < n and constants that represent the times taken by statements of the program.
(b). Obtain a big theta bound on T(n).
In: Computer Science
What is the legal business structure of the company (sole proprietorship, partnership, corporation, LLC/LLP, etc.)? Why was this legal business structure chosen?
In: Computer Science
| (16) Convert the following numbers into 8-bit hexadecimal values. | ||||
| Number | Binary | Complemented | Two's Complement | Hex |
| -102 | ||||
| -87 | ||||
| -31 | ||||
| (17) Add up the first two binary numbers from the previous problem in Two’s complement form. | ||||
| (17a) What is the sum in hex? | ||||
| (17b) What is the sign bit? | ||||
| (17c) Did overflow occur? | ||||
| (17d) Code this up in 68K and include a screenshot of the output here as well as your source & listing files. What happens? | ||||
Please show work!
If you can't do 17 d I understand, no worries!!!
In: Computer Science
I need to write a C++ program that will generate random numbers between the ranges of your own choice and within the random numbers, indicate the maximum, minimum and the average of the random numbers.
In: Computer Science
Given a csv file named “result_niwtawq.csv”, extract the data from it. Store the first column data to a list named time, second column data to a list named Turb_annual_avg, third column data to a list named Turb_min, fourth column data to a list named Turb_max, fifth column data to a list named Turb_mean. Calculate and write the average, maximumand minimumof Turb_min to a file named “lab3_output.txt”.
https://dropbox.cse.sc.edu/pluginfile.php/256369/mod_assign/introattachment/0/result_niwtawq.csv?forcedownload=1
In: Computer Science
The First National Bank of Parkville recently opened up a new “So You Want to Be a Millionaire” savings account. The new account works as follows:
Write a java program that prompts the user for a starting balance and then prints the number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.
Sample session:
Enter starting balance: 10000
It takes 4 years to reach $100,000.
It takes 7 years to reach $1,000,000.
In: Computer Science
3. Write a Java program to demonstrate the concept of priority thread. It should show that each thread have a priority. Priorities are represented by a number between 1 and 20. In most cases, thread schedular schedules the threads according to their priority (known as preemptive scheduling). But it is not guaranteed because it depends on JVM specification that which scheduling it chooses.
3 constants defined in Thread class:
1. public static int MIN_PRIORITY
2. public static int NORM_PRIORITY
3. public static int MAX_PRIORITY
Default priority of a thread is 5 (NORM_PRIORITY). The value of
MIN_PRIORITY is 1 and
the value of MAX_PRIORITY is 20.
Here is an example of priority of a Thread:
1. class TestMultiPriority1 extends Thread{
2. public void run(){
3. System.out.println("running thread
name is:"+Thread.currentThread().getName());
4. System.out.println("running thread
priority is:"+Thread.currentThread().getPriority());
5. }
6. public static void main(String args[]){
7. TestMultiPriority1 m1=new
TestMultiPriority1();
8. TestMultiPriority1 m2=new
TestMultiPriority1();
9. m1.setPriority(Thread.MIN_PRIORITY);
10. m2.setPriority(Thread.MAX_PRIORITY);
11. m1.start();
12. m2.start();
13.
14. }
15. }
In: Computer Science
Python 3.7.4
## Tombstones
'''
A Grave is a dictionary with two keys:
* 'Name': A string value with the grave's occupant's name
* 'Message': A string value with the grave's message
'''
Grave = {'name': str, 'Message': str}
'''
G1. Define the function `count_grave_all` that consumes a list of
graves
and produces an integer representing the number of characters
needed to
write all of the message of the grave. Include spaces and new
lines.
'''
'''
G2. Define the function `count_grave_characters` that consumes a
list of graves
and produces an integer representing the number of characters
needed to
write all of the message of the grave. Do not count spaces and new
lines.
'''
'''
G3. Define a function named `estimate_grave_cost` that consumes a
list of graves
and produces an integer representing the total estimate lettering
cost by
multiplying the number of letters on the grave (ignoring spaces and
newlines) by
the cost of writing a letter ($2).
'''
"""
G4. Define a function named `count_shouters` that consumes a list
of graves
and produces an integer representing the number of graves that had
their
messages in all capital letters. Hint: use the `.upper()`
method.
"""
In: Computer Science
Function Return Value
In this program, you will be using C++ programming constructs, such as functions and loops.
main.cpp
Write a program that allows the user to enter the information for multiple packages to determine the shipping charges for each package. The program will exit when the user enters 0 or negative for the package weight.
Your program will ask the user to enter the weight of a package they want to ship. If the weight they enter is a positive number, your program will then prompt the user to enter the distance the package will be shipped. Your program will then output the shipping charges with a precision of 2 digits past the decimal point, and will prompt the user for the next package.
calculateCharge
Create a function called calculateCharge that contains 2 parameters: a double to represent the weight of the package, and an integer to represent the distance the package will be shipped. This function returns the shipping charge. See types.hpp for the function prototype for this function.
This function calculates the charge based on the package weight as well as the distance. The rates per weight are defined in types.hpp. And that rate is multiplied by how many 500 mile segments the package will be traveling. For instance, if the distance is 1-500 then the rate is multiplied by one. If the distance is 501-1000 then the rate is multiplied by two. 1001-1500, multiplied by three, and so forth.
Input Validation
Hints
Sample Output
Welcome to Fast Freight Shipping Company Enter the package weight in lbs (or 0 to exit): 0
Welcome to Fast Freight Shipping Company Enter the package weight in lbs (or 0 to exit): 33 Enter shipping distance in miles: 3 Shipping cost: $6.40 Enter the package weight in lbs (or 0 to exit): -1
Welcome to Fast Freight Shipping Company Enter the package weight in lbs (or 0 to exit): 3.4 Enter shipping distance in miles: 501 Shipping cost: $8.40 Enter the package weight in lbs (or 0 to exit): 3.4 Enter shipping distance in miles: 500 Shipping cost: $4.20 Enter the package weight in lbs (or 0 to exit): 1.1 Enter shipping distance in miles: 1100 Shipping cost: $9.30 Enter the package weight in lbs (or 0 to exit): 1.1 Enter shipping distance in miles: 1 Shipping cost: $3.10 Enter the package weight in lbs (or 0 to exit): 0
Here is is the information on the types.hpp file to be used:
//-----------
// Constants
//-----------
// shipping distance per segment
const int SEGMENT_MILES = 500;
// rates per 500 miles shipped
const double RATE1 = 3.10; // pkgs weighing <= 2 lb
const double RATE2 = 4.20; // pkgs > 2 lb but <= 6 lb
const double RATE3 = 5.30; // pkgs > 6 lb but <= 10 lb
const double RATE4 = 6.40; // pkgs > 10 lb
//---------------------
// Function prototypes
//---------------------
// This function receives a package weight in lbs and
// a shipping distance in miles. It uses these to compute
// and return the shipping charge.
double calculateCharge(double weight, int distance);
In: Computer Science
ALGORITHMS AND ANALYSIS
Show with a counterexample that the greedy approach does not always yield an optimal solution for the Change problem when the coins are U.S. coins and we do not have at least one of each type of coin.
In: Computer Science
In: Computer Science
Programming in C Game of Craps
PR01
The game of craps is often said to be the “fairest” casino game of
pure chance (meaning that
there is no player strategy involved) in that the house has the
smallest advantage over the
player. What is that advantage? To answer this question we need to
first define, precisely, what
we mean by “advantage”. The house advantage is simply the fraction
of bets placed that will go
to the house, on average.
To estimate the house advantage for craps perform a Monte Carlo
simulation of the game for
many millions of games, keeping track of the total amount bet and
the total amount collected
by the house.
The rules of craps are very simple (note that we are not
considering “side bets”). A player
places a wager and they will either lose the game (and their wager)
or they will win the game
(and get both their wager and an equal payout from the house). Each
game consists of a
number of throws of two fair six-sided dice (with sides equal to
{1,2,3,4,5,6}. On each roll the
sum of the two dice is calculated. On the first roll, if a player
rolls a 7 or an 11 they win
immediately. If the first roll is 2, 3, or 12 they lose
immediately. Any other result establishes the
player’s “point” for that game. They then continue rolling the dice
until they either roll their
point again (and win) or roll a 7 (and lose).
Write a predicate function that plays a single game of craps and
returns TRUE if the player wins
and FALSE if the player loses. On each game place a random bet
ranging from $1 to $1000
(whole dollar increments is fine). Collect data not only on the
total amount wagered and the
total (net) amount taken by the house, but also aggregate data on
how long games last and
their outcome. The end result should be output similar to the
following (fake data). Note that
the percentages in parens on each line are the percentage of games
that lasted that length, not
the fraction of total games played. The last column is the
percentage of all games that lasted
that number of rolls.
GAMES PLAYED:........ 1000000
LONGEST GAME:........ 31 rolls
HOUSE ADVANTAGE:..... 1.734%
ROLLS WON LOST % OF GAMES
1 222222 (66.667%) 111111 (33.333%) 33.333
2 22222 ( 2.222%) 11111 ( 1.111%) 17.234
3 2222 ( 0.222%) 11111 ( 1.111%) 8.645
4 222 ( 0.022%) 1111 ( 0.111%) 0.935
...
20 22 ( 0.002%) 1 ( 0.000%) 0.006
>20 2222 ( 0.222%) 111 ( 0.011%) 0.521
PR02
Take a slightly different look at the game of craps by tabulating
the odds of winning (the
fraction of the time that the player wins) for each possible mark
value. This table should look
something like:
GAMES PLAYED:........ 1000000
FIRST ROLL WIN:...... 22.222%
FIRST ROLL LOSS:..... 11.111%
POINT WON LOST
4 222222 (22.222%) 111111 (11.111%)
5 22222 (22.222%) 111111 (11.111%)
6 2222 (22.222%) 111111 (11.111%)
8 26 (13.222%) 173 (86.778%)
9 222222 (22.222%) 111111 (11.111%)
10 222222 (22.222%) 111111 (11.111%)
Again, note that the numbers above are just effectively random
placeholder values.
The percentages for the first-roll figures should be as a fraction
of all games played. The
percentages for the values in the table should be as a fraction of
all games that used that row’s
point value. The idea is for the player to know that IF their point
is 8, then they have a 13%
change of winning that game – so the percentages on each row should
sum to 100%.
In: Computer Science
In this lab, we will write some utility methods within a class called ListUtils. These three methods will all be static methods, and their purpose will be to perform conversions between objects implementing one type of interface and objects implementing another type. For example, we will write a method for converting from an Iterable object to a Collection, and so on. We will discuss more about how this will work below.
Tip: you will definitely want to import java.util for this lab, since List and all of its relatives use it.
Iterable to Collection task:
public static <E> Collection<E>
iterToCollection(Iterable<? extends E> iterable)
(3pts) Every Collection is an Iterable but not every Iterable is a Collection. However, if we have an Iterable, it implies a sequence of elements, so we can use that to built a Collection. That is what we will do in this method. To implement the method, we will need to create some kind of Collection object, and add elements from the Iterable's sequence to it one by one.
Hint: we don't want to store the result in a Collection itself, because it is just an interface, but there may be a more familiar choice of structure which implements Collection.
Collection to List task:
public static <E> List<E> collToList(Collection<?
extends E> coll)
(3pts) As above, every List is a Collection but not every Collection is a List. However, if we have a Collection, it implies a fixed number of elements which can be retrieved in sequence, so we can use that to built a List by numbering the element indices in the order they are retrieved. That is what we will do in this method. To implement the method, we will need to create some kind of List object, and add elements from the Collection.
List to Map task:
public static <E> Map<Integer, E> listToMap(List<?
extends E> list)
(3pts) A Map, sometimes known as an associative array or dictionary, is in some ways similar to a List, except that instead of accessing elements by the indices 0, 1, 2, etc., the elements are accessed by a key, which may or may not be in order, and which may or may not be a number. Every element in a Map is stored as a key-value pair (the value of the element plus the key which is used to access it). Thus, when we call the get() method, instead of passing in an int index, we pass in the key corresponding to the element we're looking for. An example of a class which implements the Map interface in Java is the HashMap class.
A List is not a Map and a Map is not a List. However a Map stores collections of data indexed by some kind of mapping. A Map is essentially a dictionary which allows us to look up elements in a collection of data using some reference key to find each element. The reference key for a Map can be any data type, but if we make that data type an Integer, then we can use the key to represent a List index. Thus, in this method, we will take a List and use it to build a Map by using the list index of each element as the element's key within the Map. Thus, if our List contains the elements 2, 4, and 6, then this method will produce a Map with the mappings 0 ⇒ 2, 1 ⇒ 4, and 2 ⇒ 6. As above, this would involve creating an appropriate type of Map and adding the elements from the List.
In: Computer Science