Download HW1.pdf

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Genetic algorithm wikipedia , lookup

Algorithm characterizations wikipedia , lookup

Selection algorithm wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Fisher–Yates shuffle wikipedia , lookup

Algorithm wikipedia , lookup

Sieve of Eratosthenes wikipedia , lookup

Transcript
HW1, Fundamentals of Programming (Pascal) 1
Due Date: Monday, Farvardin 14th
1. Are the four items listed below algorithms? If not, what qualities required of algorithms do they
lack?
• Add the first row of the following matrix to another row whose first column contains a
nonzero entry. (Reminder: Columns run vertically, rows run horizontally.)
In order to show that there are as many prime numbers as there are natural numbers,
match each prime number with a natural number in the following manner. Create pairs
of prime and natural numbers by matching the first prime number with 1(which is the
first natural number) and the second prime number with 2, the third with 3, and so
forth. If, in the end, it turns out that each prime number can be paired with each natural
number, then it is shown that there are as many prime numbers as natural numbers
• Suppose you’re given two vectors each with 20 elements and asked to perform the
following operation. Take the first element of the first vector and multiply it by the first
element of the second vector. Do the same to the second elements, and so forth. Add
all the individual products together to derive the dot product.
• Esfandiar and Rostam are trying to decide who will ride Rakhsh. Esfandiar suggests that
they flip a coin and pulls one out of his pocket. Rostam does not trust Esfandiar and
suspects that the coin may be weighted (meaning that it might favor a particular
outcome when tossed) and suggests the following procedure to fairly determine who
will ride Rakhsh.
• Flip the coin twice.
• If the outcome is heads on the first flip and tails on the second, then I will ride
Rakhsh.
• If the outcome is tails on the first flip, and heads on the second, then you will
ride Rakhsh.
• If both outcomes are tails or both outcomes are heads, then we flip twice
again.
Is Rostam’s technique an algorithm?
2. Draw a flowchart to prepare tea for your guests!
3. Represent a pseudo-code for the algorithm to get the maximum of n input numbers.
4. Draw a flowchart for the problem 3.
•
HW1, Fundamentals of Programming (Pascal) 2
Due Date: Monday, Farvardin 14th
5. Represent an algorithm, in any way you prefer, to calculate GCD1 of two numbers
6. Represent an algorithm, in any way you prefer, that writes its input numbers as multiplication of
its prime factors.
1
Greatest Common Divisor