Answer:
No, if the algorithm is properly written to solve problems with minimal resources like RAM and processor speed.
Explanation:
Rather than buy a faster or more expensive computer simply upgrade the RAM else you may have to buy new computer each the size of problem instances increases.
Answer:
nooooooo
Explanation:
Answer:
Given Data:
Clock rate of P1 = 4 GHz
Clock rate of P2 = 3 GHz
Average CPI of P1 = 0.9
Number of Instructions = 5.0E9 = 5 × 10^9
Clock rate of P2 = 3 GHz
Average CPI of P2 = 0.75
Number of Instructions = 1.0E9 = 10^9
To find: If the computer with largest clock rate has the largest performance?
Explanation:
Solution:
As given in the question, clock rate of P1 = 4 GHz which is greater than clock rate of P2 = 3 GHz
According to the performance equation:
CPU Time = instruction count * average cycles per instruction/ clock rate
CPU Time = I * CPI / clock rate
Where instruction count refers to the number of instructions.
Performance of P1:
CPU Time (P1) = 5 * 10^9 * 0.9 / (4 * 10^9)
= 5000000000 * 0.9 / 4000000000
= 4500000000 / 4000000000
= 1.125s
Performance of P2:
CPU Time (P2) = 10^9 * 0.75/ (3 * 10^9)
= 750000000 / 3000000000
= 0.25s
So the Performance of P2 is larger than that of P1,
performance (P2) > performance (P1)
0.25 is better than 1.125
But clock rate of P1 was larger than P2
clock rate of P1 > clock rate of P2
4 GHz > 3 GHz
So this is a misconception about P1 and P2.
It is not true that computer with the largest clock rate as having the largest performance.
Answer:
Explanation:
#include <iostream>
#include <string>
#include<vector>
using namespace std;
vector<int> permute(vector<int>, vector<int>);
string encrypt(vector<int>s1 , vector<int> t1, string p);
string decrypt(vector<int>s1, vector<int> t1, string p);
int main() {
string plaintext = "cryptology";
string plaintext2 = "RC4";
vector<int> S(256);
vector<int> T(256);
int key[] = { 1,2,3,6 };
int key2[] = { 5,7,8,9 };
int tmp = 0;
for (int i = 0; i < 256;i++) {
S[i] = i;
T[i] = key[( i % (sizeof(key)/sizeof(*key)) )];
}
S = permute(S, T);
for (int i = 0; i < 256 ;i++) {
cout << S[i] << " ";
if ((i + 1) % 16 == 0)
cout << endl;
}
cout << endl;
string p = encrypt(S, T, plaintext);
cout << "Message: " << plaintext << endl;
cout << "Encrypted Message: " << " " << p << endl;
cout << "Decrypted Message: " << decrypt(S, T, p) << endl << endl;
tmp = 0;
for (int i = 0; i < 256;i++) {
S[i] = i;
T[i] = key2[(i % (sizeof(key) / sizeof(*key)))];
}
S = permute(S, T);
for (int i = 0; i < 256;i++) {
cout << S[i] << " ";
if ((i + 1) % 16 == 0)
cout << endl;
}
cout << endl;
p = encrypt(S, T, plaintext2);
cout << "Message: " << plaintext2 << endl;
cout << "Encrypted Msg: " << p << endl;
cout << "Decrypted Msg: "<<decrypt(S, T, p) << endl << endl;
return 0;
}
string decrypt(vector<int>s1, vector<int> t1, string p) {
int i = 0;
int j = 0;
int tmp = 0;
int k = 0;
int b;
int c;
int * plain = new int[p.length()];
string plainT;
for (int r = 0; r < p.length(); r++) {
i = (i + 1) % 256;
j = (j + s1[i]) % 256;
b = s1[i];
s1[i] = s1[j];
s1[j] = b;
tmp = (s1[i] + s1[j]) % 256;
k = s1[tmp];
c = ((int)p[r] ^ k);
plain[r] = c;
plainT += (char)plain[r];
}
return plainT;
}
string encrypt(vector<int>s1, vector<int> t1, string p) {
int i = 0;
int j = 0;
int tmp = 0;
int k = 0;
int b;
int c;
int * cipher = new int [p.length()];
string cipherT;
cout << "Keys Generated for plaintext: ";
for (int r = 0; r < p.length(); r++) {
i = (i + 1) % 256;
j = (j + s1[i]) % 256;
b = s1[i];
s1[i] = s1[j];
s1[j] = b;
tmp = (s1[i] + s1[j]) % 256;
k = s1[tmp];
cout << k << " ";
c = ((int)p[r] ^ k);
cipher[r] = c;
cipherT += (char)cipher[r];
}
cout << endl;
return cipherT;
}
vector<int> permute(vector<int> s1, vector<int> t1) {
int j = 0;
int tmp;
for (int i = 0; i< 256; i++) {
j = (j + s1[i] + t1[i]) % 256;
tmp = s1[i];
s1[i] = s1[j];
s1[j] = tmp;
}
return s1;
}
Lists are used in Python to hold multiple values in one variable
(a) Nested list
A nested list is simply a list of list; i.e. a list that contains another list.
It is also called a 2 dimensional list.
An example is:
nested_list = [[ 1, 2, 3, 4] , [ 5, 6, 7]]
(b) The “*” operator
The "*" operator is used to calculate the product of numerical values.
An example is:
num1 = num2 * num3
List slices
This is used to get some parts of a list; it is done using the ":" sign
Take for instance, you want to get the elements from the 3rd to the 5th index of a list
An example is:
firstList = [1, 2 ,3, 4, 5, 6, 7]
secondList = firstList[2:5]
The “+=” operator
This is used to add and assign values to variables
An example is:
num1 = 5
num2 = 3
num2 += num1
A list filter
This is used to return some elements of a list based on certain condition called filter.
An example that prints the even elements of a list is:
firstList = [1, 2 ,3, 4, 5, 6, 7]
print(list(filter(lambda x: x % 2 == 0, firstList)))
A valid but wrong list operation
The following operation is to return a single list, but instead it returns as many lists as possible
def oneList(x, myList=[]):
myList.append(x)
print(myList)
oneList(3)
oneList(4)
Read more about Python listsat:
B: the responsible person or organization and the website URL
C: the responsible person or organization, date accessed, and URL
D: the responsible person or organization and the date accessed
Answer:
C: the responsible person or organization, date accessed, and URL
Explanation: