Sunday, July 4, 2010

Interesting Problem 5 : Trees

Q.5 Consider the following sequence of keys

(5,16,22,45,2,10,18,30,50,12,1)

Consider the insertion of items with this set of keys, in the order given, into :

a. An initially empty (2,4) tree T’

b. An initially empty red black tree T’’


My solution :





Saturday, July 3, 2010

Interesting Problem 4 : Writing VB Scripts

Write a script to simulate the rolling of two dice. The script should use Math.random to roll the first die and again to roll the second die. The sum of the two values should then be calculated. [note: Since each die can show an integer value from 1 to 6, the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12 the least frequent sums. Your program should roll the dice 36,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Display the results in an XHTML table. Also determine whether the totals are reasonable.(e.g., there are six ways to roll a 7, so approximately 1/6 of all the rolls should be 7)]

My Solution: Writing in a file named as scripts.vbs .


Dim dice1
Dim dice2
Dim total(10)
total(0)=0
total(1)=0
total(2)=0
total(3)=0
total(4)=0
total(5)=0
total(6)=0
total(7)=0
total(8)=0
total(9)=0
total(10)=0

Dim max,min
max=6
min=1
Dim sum

for count =0 to 35999
dice1 = Int((max-min+1)*Rnd+min)
dice2 = Int((max-min+1)*Rnd+min)
sum = dice1 + dice2

Select Case sum
Case 2
total(0) = total(0) + 1
Case 3
total(1) = total(1) + 1
Case 4
total(2) = total(2) + 1
Case 5
total(3) = total(3) + 1
Case 6
total(4) = total(4) + 1
Case 7
total(5) = total(5) + 1
Case 8
total(6) = total(6) + 1
Case 9
total(7) = total(7) + 1
Case 10
total(8) = total(8) + 1
Case 11
total(9) = total(9) + 1
Case 12
total(10) = total(10) + 1
End Select

Next


Now we can import these values in html table using document.write property and using html tags .