Ads

Pages

Monday, October 31, 2011

STA630 Online Quiz No. 1 Fall 2011 Announcement

Online Quiz # 01

All Students of Fall Semester 2011 are informed that Online Quiz # 01 for

“Research Methods (STA630)” will be uploaded according to the following schedule:

Opening Date and Time : October 31, 2011 At 12:01 AM

Closing Date and Time : November 01, 2011 At 11:59 PM

CS506 Assignment No. 1 Fall 2011 Solution

Question:

Write a program that computes the average and standard deviation of the text floating point numbers in a file. Use the following formulas for the average and the standard deviation of N values. The formulas compute the sum, the sum of squares, the average, the average square, the variance, and finally, the standard deviation.

sum = x1 + x2 + x3 + ... + xN-1 + xN

sumSQ = x12 + x22 + x32 + ... + xN-12 + xN2

avg = sum/N

avgSQ = sumSQ/N

var = avgSQ - avg2

sd = var(1/2)

The input file will contain any number text floating point numbers, similar to the following:

10.5

12.9

9.67

12.05

8.23

10.08

10.23

7.7

10.4

11.34

Numbers could be several, or none per line, and negative numbers are perfectly OK.

Solution:

Input Text:

10.0

20.0

30.0

40.0

50.0

............

SAVE THIS FILE IN .JAVA

import java.io.*;

import java.util.*;

import javax.swing.*;

public class assignment1{

public static void main( String args[] ){

try{

FileReader fr = null;

BufferedReader br = null;

fr = new FileReader ("input.txt");

br = new BufferedReader (fr);

String line = br.readLine();

double sum =0 ;

while (line != null) {

double num = Double.parseDouble(line);

sum += num;

line = br.readLine();

}

JOptionPane.showMessageDialog(null, "Sum = " + sum);

br.close();

fr.close();

}

catch(NumberFormatException nfEx) {

System.out.println(nfEx);

}

catch(FileNotFoundException fnfEx){

System.out.println(fnfEx);

}

catch(IOException ioEx){

System.out.println(ioEx);

}

}

}

Fin622 Assignment No. 1 Fall 2011 solution

ABC corporation stock is selling for Rs. 150 per share according to Karachi stock exchange market summary. A rumor about the company has been heard that the firm will make an exciting new product announcement next week. By studying the industry, it is being concluded that this new product will support a growth rate of 20% in dividend for two years. After that it is expected that the growth rate in dividend will decline to 6% and remains same onwards. The firm currently pays an annual dividend of Rs. 4.

The rate of return on stocks like ABC Corporation is 10%.

Required:

I. Find out the values for D1, D2 and D3 (8 Marks)

II. What will be the price of stock (P2) at the end of year 2? (4 Marks)

III. What will be the present value (P0) of stock? (6 Marks)

IV. Should we buy stocks of ABC Corporation at Rs. 150? (2 Marks)

Solution

Find out the values for D1, D2 and D3

D1= 4 (1+0.2) =4.8

D2= 4.8 (1+0.2) =5.76

D3=5.76 (1+0.05) =6.11

What will be the price of stock (P2) at the end of year 2?

P2= 5.76 (1+0.2)/ .1-0.05

P2=138.24

What will be the present value (P0) of stock?

PO= 4.8/(1+.1)1 + 5.76/(1+.1)2 + 6.11/(1+.1)3 + 128.31/(1.1)3

= 110

Should we buy stocks of ABC Corporation at Rs. 150

As the present value of the stock is less then the current selling price so the stock should not be purchased.

Saturday, October 29, 2011

CS401 Assignment No. 1 Fall 2011 solution


Question No. 1:

a)

Suppose your computer has a processor with 24-bit address lines. What is maximum amount of memory that can be attached in your system? (Show the step(s) for calculation of maximum addressable memory) (2.5 marks)

Solution: -

Accessible memory addresses = 2number of address bits

224 = 16777216 bytes

16777216 / 1024 = 16384 KB

16384 / 1024 = 16 MB

b)

How many address bits are required for accessing 1GB RAM? (Show the step(s) for calculation of required address bits) (2.5 marks)

Solution: -

As you know 1GB means 1024MB so we can write it as

1GB = 1024 x 1MB

As you know that 1MB is 220

So we can write the expression as

1024 x 220

This can be further simplified as

210 x 220

=230

Hence, 30 address lines are required to access 1GB RAM.

Question No. 2:

What are the contents of memory locations 0151, 0152, 0153, ………….,0158 if 0151 is starting address for Label1. (1 mark for each location)

Label1: dw 8494

db 42

dw 54

dw 7500

db 01

Solution: -

Memory location Contents

0151 94

0152 84

0153 42

0154 54

0155 00

0156 00

0157 75

0158 01

Question No. 3:

a)

Calculate physical address using the following segment offset pairs. (1 mark each)

1. 00EA:02A4

2. 0100:AA23

3. D3B8:F222

4. 00A0:1234

5. 8FEf:0FFF

Solution: -

Memory Location

Contents

0151

94

0152

84

0153

42

0154

54

0155

00

0156

00

0157

75

0158

01

Question No. 3:

a)

Calculate physical address using the following segment offset pairs. (1 mark each)

1. 00EA:02A4

2. 0100:AA23

3. D3B8:F222

4. 00A0:1234

5. 8FEf:0FFF

Solution: -

1)

00EA0

002A4 +

_______

01144 = physical address

2)

01000

0AA23 +

_______

0BA23 = physical address

3)

D3B80

0F222 +

______

E2DA2 = physical address

4)

00A00

01234 +

________

01C34 = physical address

5)

8FEF0

00FFF +

_________

90EEF = physical address

b)

What is effective address generated by the following instructions? Every instruction is independent of others. vusolutions Initially bx = 0x0101, bp=0x0222, si=0x1234, var1=0x1771 (1 mark each)

1. mov ax, [bx+si]

2. mov ax, [bx+100] (100 is in decimal)

3. mov ax, [bp+si]

4. mov ax, [var1+bp]

5. mov ax, [si+var1]

Solution: -

1)

Effectice address = [bx+si]

= [0101 + 1234]

= [1335]

2)

Effectice address = [bx + 100]

After converting 100 into hexadecimal

Effectice address = [bx + 64]

= [0101 + 64]

= [0165]

3)

Effective address = [bp+si]

= [0222 + 1234]

= [1456]

4)

Effective address = [var1+bp]

= [1771 + 0222]

= [1993]

5)

Effective address = [si + var1]

= [1234 +

CS402 Assignment No. 1 Fall 2011 solution


Theory of Automata

CS402

ASSIGNMENT NO.1

Total Marks= 20 (4+4+4+4+4)

Assignment Submission Deadline

Your assignment must be uploaded before or on 31-10-2011 [upload your assignment well before due date to avoid any assignment uploading related issues]

Rules for Marking

It should be clear that your assignment will not get any credit if:

o The assignment is submitted after due date

o The assignment is copied

Objectives

Objectives of this assignment are to make students able to understand the following concepts,

o Basic concepts clarification

o Recursive Definition of a language

o Regular Expression

o Finite Automata

Question No.1 Basic Concepts [Sets, Letters, Valid Alphabet, Languages, Strings and Words]

a. Which of the following are strings generated from alphabet Σ = {a, b}

i. abba

ii. baa$a

iii. abc.

iv. ba?

v. b.bba

b. Which of the following are valid words for language of all strings ending with bab defined for alphabet Σ = {a, c , bab}

i. acccba

ii. cccbaa

iii. cccbab

iv. babbb

v. baaab

Question No.2 Defining Languages [Using Recursive Definition, Re’s, Fa’s]

Give recursive definitions of following languages defined over alphabet Σ = {a, b}

i. Having all strings starting with b and having length greater than 2

ii. NOT having ab at any place.

Question No.3 Regular Expressions

Give Regular Expression for each of the following language defined over alphabet Σ = {a, b}

i. Even Length strings ending with b

ii. Strings with b’s count multiple of three

Question No.4 Models To Recognize Languages (Fa’s)

Give Finite Automata (FA) for each of the following language defined over alphabet Σ = {a, b}

i. Language having all strings NOT containing aa at any place

ii. Language of all strings NOT STARTING with bb

Question No.5 Models To Recognize Languages (Nfa’s)

Give Non Deterministic Finite Automata (NFA) for each of the following language defined over alphabet Σ = {a, b}

i. Language of all strings STARTING WITH bba

ii. Language having all strings NOT having even no of a’s and b’s

You can view the demo video in file,http://vulms.vu.edu.pk/Courses/CS402/Downloads/Assignment1.00.zipto see how to make FA in MS Word.

Note:

Please keep in view the following points while attempting any question:

• Where OR is used in the description of a language it means that expressions on both sides of ‘OR’ are parts of the language.

• Where NOT is used in the description of the language it means that language includes all strings except described in the ‘NOT’ condition, for example

language NOT starting with a, means all strings not having a in the start (you have to evaluate yourself what kinds of strings are these).

Assignment Uploading Instructions:

o Upload single word file having solutions for all parts as well as chart images.

o You can crop and compress images in the word file by double clicking on an image and selecting compress all images option to decrease file size before

uploading it.

Appendix:

Definition of Set:

A set can be defined as follows:

“Non repeating collection of elements”

Example Sets:

i. {car, bus }

ii. {table, chair , stand}

iii. {basket ,eggs}

iv. { ^, #, *, / }

However {car, car, bus} is NOT a set according to its definition.

Solution:


Question No.1 Basic Concepts [Sets, Letters, Valid Alphabet, Languages, Strings and Words]
a. Which of the following are strings generated from alphabet Σ = {a, b}
i. abba
ii. baa$a
iii. abc.
iv. ba?
v. b.bba

b. Which of the following are valid words for language of all strings ending with bab defined for alphabet Σ = {a, c , bab}
i. acccba
ii. cccbaa
iii. cccbab
iv. babbb
v. baaab


Question No.2 Defining Languages [Using Recursive Definition, Re’s, Fa’s]
Give recursive definitions of following languages defined over alphabet Σ = {a, b}

i. Having all strings starting with b and having length greater than 2

Answer. { baa, bab, bba, bbb, bba, baab, ….. .. }

ii. NOT having ab at any place.


Answer. {^, a, b, ba, bab, bba, bbb, baa, bbba,…..}

Question No.3 Regular Expressions
Give Regular Expression for each of the following language defined over alphabet Σ = {a, b}

i. Even Length strings ending with b

Answer. { ^ ,ab, bb, aabb,abab, bbbb, aaaabb, aaabab, ……}

ii. Strings with b’s count multiple of three

Answer. {^, bbb, bbbbbb, bbbbbbbbb, bbbbbbbbbbbb, bbbbbbbbbbbbbbb,
bbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbb,………}


Question No.4 Models To Recognize Languages (Fa’s)
Give Finite Automata (FA) for each of the following language defined over alphabet Σ = {a, b}

i. Language having all strings NOT containing aa at any place

Answer. { ^, a, b, ab, ba, abb, bab,bba, baba, abbb, ….}

ii. Language of all strings NOT STARTING with bb

Answer. { ^, a, b, aab, aaab, abab, aabab, …….}

Question No.5 Models To Recognize Languages (Nfa’s)
Give Non Deterministic Finite Automata (NFA) for each of the following language defined over alphabet Σ = {a, b}

i. Language of all strings STARTING WITH bba

Answer. { ^, bba, bbaa, bbaba, bbaab, bbab, bbabb, …}

ii. Language having all strings NOT having even no of a’s and b’s

Answer. {^, a, b, aaab, bbba, ababab, aaaaab, bbbbba, ……}