Share
Explore BrainMass

Algorithms

Exam Question on grammar from Languages&their implementation

(ii) Using the grammar below:- S -> pAb Production No. 1 A -> cB | a Productions No. 2 and 3 B -> cb Production No. 4 Construct a table with four columns that indicate the step number, state of the input, derivation, and rule applied, and hence show how the string:- pccbb can be parsed top-dow

Classes and Enumerators

Write a program similar to the following: wavelength.cpp computes the wavelength of light for a fiven Color. Input: theColor, a Color value Precondition: theColor is one of RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET Output: the wavelegth of light corresponding to theColor, but that uses the Color class hierarchy.

Building Classes

Write a program to do rational number arithmatic, representing each rational number as a class that has instance variables for the numerator and the denomonator. The program should read and display all rational numbers in the format a/b, or simply a if the denominator is 1.

Building Classes

The point-slope equation of a line having slope m and pasing through pint P with coordinates (x1, y1) is y-y1=m(x-x1). a. Write a class for a CartesianPoint, described by its x- and y- coordinates, with all appropriate operations on such objects. b. Write a LineSegment class, described by two CartesianPoint endpoints. In addi

Stopwatch Program

Write a stopwatch program that will display time in letters approximately 2 inches high and 1 inch wide. Display minutes, seconds, and tenths of seconds. Have the elapsed time reset to 0.00.00 when the r key is pressed, and then begin time when the t key is pressed. Stop timing, and freeze the display, when the t key is pressed

Functions

Write a function calculateTaxes () that calculates and returns the amount of city incom tax and the amount of federal income tax to be withheld from an employee's pay for one pay period. Assume that city income tax withheld is computed by taking 1.15 percent of gross pay on the first $40,000 earned per year and that federal inc

Functions

The graph of a person's emotional cycly y=f(x) is a sinc curve having an amplitude of 1 and a period of 28 days. On a given day, the person's emotional index is f(age), where age is his or her age in days. Similarly, the physical and intellectual cycles are sine curves having an amplitude of 1 and periods of 23 and 33 days,

Using Classes

Write a program to display the lyrics of "Happy Birthday to You."

Program for wind speed, temperature, humidity

In a certain region, pesticide can be sprayed from an iairplane only if the temperature is at least 70 degrees, the relative humidity is between 15 and 35%, and the wind speed is at most 10 miles per hour,

To change numerals into normalized form of floating point.

Change the following numerals into normalized form of floating point representation: (a) 1.25487×106 (b) .0125487×106 (c) 12.5487×106 (d) .000125487×106 (e) 125.487×106 (f) 125487×106 (g) 12548.7×106 See attached file for full problem description.

Hops

A datagram subnet allows routers to drop packets whenever they need to. The probability of a router discarding a packet is p. Consider the case of a source host connected to a source router, which is connected to the destination router, and then to the destination host. If either of the routers discards a packet, the source host

Frame Arrival Rates: Example Problems

Frames arrive randomly at a 100 Mbps channel for transmission. If the channel is busy when a frame arrives, it waits its turn in a queue. Frame length is exponentially distributed with a mean of 10,000 bits/frame. For each of the following frame arrival rates, give the delay experienced by the average frame, including both queui

Sliding Window Protocol

A data link layer runs a sliding window protocol. A transmits using a sending window size of 6 and B receives using a receiving window size of 1. We assume that A always has traffic to send and that B sends Acks only. The channel delay is large enough that A transmits 6 frames before receiving any acknowledgements from B. A begi

Stop and Wait Problem

A channel has a bit rate of 64 kbps and a propagation delay of 20 msec. For what range of frame sizes does stop-and-wait give a channel efficiency of at least 50%.

Big O Problem

Consider the recurrence T(1)=a T(n)=cT(n/d)+bn^k, for n a power of d Iteratively expand T(n) in terms of T(n/d^i) for i=1,2,.... Show that a) if c > d^k, then T(n) is O(n^logd c) b) if c = d^k, then T(n) is O(n^k log n) c) if c < d^k, then T(n) is O(n^k)

Big O - algorithm comparison

Suppose program A takes (2^n)/1000 units of time and program B takes 1000(n^2) units. For what values of n does program A take less time than program B. I am really looking for a detailed explanation on this problem - to check my answer. Thanks.

Give an example of a weighted directed graph with at most 5 vertices such that Dijkstra's algorithm will NOT give the correct results for the shortest path lengths from source s to every other vertex. algorithm

Give an example of a weighted directed graph with at most 5 vertices such that Dijkstra's algorithm will NOT give the correct results for the shortest path lengths from source s to every other vertex. Your graph may have negative edge weights but NO negative weight cycles. Indicate what answer Dijkstra's algorithm would give a

Storage on a disk with 2 surfaces

Background: I have a hard magnetic disk w/2 surfaces. The storage area on each surface has an inner radius of 1cm and and outer radius of 5cm. Each track holds the same number of bits even though the size differs from each other. The max storage density of the media is 10,000 bits/cm. The spacing between corresponding points

Bit pair recoding

I have to use use bit pair recoding to multiply 010011 (multiplicated) by 011011 (multiplier).

How long does it take to load

How long does it take to load a 64-KB program from a disk whose average seek time is 10 msec, whose rotation time is 10 msec and whose tracks hold 32 KB: A) For a 2-KB page size? B) For a 4-KB page size?

Multiplication and division of binary numbers

8. The answer for the following two problems must be in binary. a) Multiply binary 1 0 0 0 1 1 1 1 1 0 . 1 0 1 0 1 1 1 1 0 1 by decimal 16. b) Divide binary 1 0 0 0 1 1 1 1 0 1 0 1 0 . 0 1 1 1 1 0 1 by decimal 32

Perform Addition and Subtaction on Binary numbers

9. Convert the following decimal numbers into 8?bit binary numbers as required for 2's complement math, and perform the indicated operations. Note: Remember that positive numbers are represented in signed-magnitude format in 2's complement math a) +39 +19 = b) +39 -19 = c) -39 +19 =.

Writing queue and stack algorithms

Using only the algorithms in the queue and stack ADT's, write an algorithm called reverseQueue that copies the contents of a queue to another queue, and reverses the order of the data. After data is copied, the data that is at the front of Q1, should be at the rear of Q2.

The use of "this"

In writing the code for a method, a programmer might use the keyword "this". When the method is invoked from somewhere in the program, what does this refer to?