Sunteți pe pagina 1din 2

Ming Zhao (mz2377)

MATLAB COMS W1005


Homework #3
10/25/13
Written Part
Problem 1:
All possible ways for visiting 25 cities is 25! = 1.551121*10^25 different paths
Computer must analyze all paths before finding the shortest one.
So, it takes 1.551121*10^25 / 10,000,000 = 1.551121*10^18 seconds to determine t
he optimal route.
This alorithm will not finish in a time that is useful for the programmer. So, i
t is not feasible.
A more reasonable solution is this: first, find the closest city relative to her
starting position (let's call it city A) and store this city as the first eleme
nt of a 1-by-25 cell. Then, of the remaining 24 cities, find the one closest to
city A (let's call it city B) and store this as the second element of your cell.
Then, of the remaining 23 cities, find the one closest to city B (let's call it
city C) and store this as your third element in the cell. Repeat this operation
, each time excluding the cities you have already recorded from your distance co
mparisons, until you have only one city left. This last city can simply be recor
ded as the last entry in the cell.Your final row cell gives you the optimal rout
e.

Problem 2:
a) Decimal value of 1011010011: -(2^0+2^1+2^4+2^6+2^7) = -211
b) Decimal value of 0100011010: +(2^1+2^3+2^4+2^8) = 282
c) Decimal value of 1111111111: -(2^0+2^1+2^2+2^3+2^4+2^5+2^6+2^7+2^8) = -(2^9-1
)= -511
d) Decimal value of 1000000000: -(0) = 0

Problem 3:
a) 2048 = 2^11. So, in 32-bit two's complement binary, 2048 becomes: 00000000000
000000000100000000000
b) 456 = 2^8+2^7+2^6+2^3, which is 00000000000000000000000111001000.Flip bits an
d add one for the negative. So, in 32-bit two's complement binary,-456 becomes:
11111111111111111111111000111000.
c) 3,450,001 = 2^21+2^20+2^18+2^15+2^13+2^10+2^7+2^4+2^0, which is 0000000000110
1001010010010010001. Flip bits and add one for the negative. So, in 32-bit two's
complemend binary, -3,450,001 becomes: 11111111110010110101101101101111.

Problem 4:

a) Flipping the bits and adding 1 gives 0000 0010 1101 0010 0000 0001 0111 0100.
In decimal, this is 47,317,362. So,the decimal value of 1111 1101 0010 1101 111
1 1110 1000 1100 is: -47,317,364.
b) Flipping the bits and adding 1 gives 0000 0000 0000 0000 0000 0000 0000 0001.
In decimal, this is 1. So, the decimal value of 1111 1111 1111 1111 1111 1111 1
111 1111 is: -1.
c) First digit is 0, so the decimal number must be a positive. 2^31 - 1 = 2,147,
483,647. So, the decimal value of 0111 1111 1111 1111 1111 1111 1111 1111 is: 2,
147,483,647.

S-ar putea să vă placă și