SlideShare a Scribd company logo
1 of 46
Download to read offline
786
Answers of Discrete_Mathematics
Page No (186)
Q1. Explain what it means for one set to be a subset of another set. How do you prove that one set
is a subset of another set?
A1: The set A is a subset of B if and only if every element of A is also an element of B.
We use the notation A ⊆ B to indicate that A is a subset of the set B.
We see that A ⊆ B if and only if the quantification
∀x(x ∈ A → x ∈ B) is true.
Note that to show that A is not a subset of B we need only find one element x ∈ A with x /∈ B. Such
an x is a counterexample to the claim that x ∈ A implies x ∈ B.
We have these useful rules for determining whether one set is a subset of another:
Showing that A is a Subset of B. To show that A ⊆ B, show that if x belongs to A then x also belongs
to B.
Showing that A is Not a Subset of B. To show that A _⊆ B, find a single x ∈ A such that x _∈B.
Q2. What is the empty set? Show that the empty set is a subset of every set.
A2: The empty set is the set with no elements. It satisfies the definition of being a subset of every set
vacuously.
Q . a Defi e |S|, the a di alit of the set S.
b) Give a formula for |A ∪ B|, where A and B are sets.
A3: a) Showing Two Sets are Equal. To show that two sets A and B are equal, show that
A ⊆ B and B ⊆A.
b) Sets may have other sets as members. For instance, we have the sets
A = {∅, {a}, {b}, {a, b}} and B = {x | x is a subset of the set {a, b}}.
Note that these two sets are equal, that is, A = B. Also note that {a} ∈ A, but a /∈ A.
Q4. a Defi e the po e set of a set S.
b) When is the empty set in the power set of a set S?
c) How many elements does the power set of a set S with n elements have?
A4: a) Given a set S, the power set of S is the set of all subsets of the set S. The power set of S is
denoted by P(S).
b) Always
c) 2n
Q5. a Defi e the u io , i te se tio , diffe e e, a d s et i diffe e e of t o sets.
b) What are the union, intersection, difference, and symmetric difference of the set of positive
integers and the set of odd integers?
A5:a) Union: Let A and B be sets. The union of the sets A and B, denoted by A ∪ B, is the set that
contains those elements that are either in A or in B, or in both.
An element x belongs to the union of the sets A and B if and only if x belongs to A or x belongs to B.
This tells us that (A ∪ B = {x | x ∈ A x ∈ B}).
E.g. The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is,
{1, 3, 5} ∪ {1, 2, 3} = {1, 2, 3, 5}.
Intersection: Let A and B be sets. The intersection of the sets A and B, denoted by A ∩ B, is the set
containing those elements in both A and B.
An element x belongs to the intersection of the sets A and B if and only if x belongs to A and x
belongs to B. This tells us that (A ∩ B = {x | x ∈ A x ∈ B}).
E.g. The intersection of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 3}; that is,
{1, 3, 5} ∩ {1, 2, 3} = {1, 3}.
b) Union: integers that are odd or positive, intersection: odd positive integers, difference: even
positive integers, symmetric difference: even positive integers together with odd negative integers
786
Q6. a) Explain what it means for two sets to be equal.
b) Describe as many of the ways as you can to show that
two sets are equal.
c) Show in at least two different ways that the sets
A − B ∩ C a d A − B ∪ A − C a e e ual.
A6: a) A= B = (A<:;;; B / B <:;;;A)= Vx(x EA+-+ x EB)
b) If you want extra about this Question see book. Page no (129-132)
TABLE Set Identities.
Identity Name
A ∩ U = A
A ∪ ∅ = A
Identity laws
A ∪ U = U
A∩∅ = ∅
Domination laws
A ∪ A = A
A ∩ A = A
Idempotent laws
(A) = A Complementation
law
A ∪ B = B ∪ A
A ∩ B = B ∩ A
Commutative laws
A ∪ (B ∪ C) = (A ∪ B) ∪ C
A ∩ (B ∩ C) = (A ∩ B) ∩ C
Associative laws
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
Distributive laws
A ∩ B = A ∪ B
A ∪ B = A ∩ B
De Mo ga ’s la s
A ∪ (A ∩ B) = A
A ∩ (A ∪ B) = A
Absorption laws
A ∪ A = U A ∩ A = ∅ Complement laws
c) An B n C =An (Bu C) = (An B) u (An C) = (A- B) u (A - C); use Venn diagrams
Q7. Explain the relationship between logical equivalences and set identities.
A7: Underlying each set identity is a logical equivalence.
These follow directly from the corresponding properties for the logical operations or and and.
a) AU B = { x I x E A V x E B} = { x I x E B V x E A} = B U A
b) An B = { x Ix EA/ x EB}= { x Ix EB / x EA}= B n A
Q8. a Defi e the do ai , odo ai , a d a ge of a fu tio .
b) Let f (n) be the function from the set of integers to the set of integers such that f (n) = n2 + 1.
What are the domain, codomain, and range of this function?
A8: a) Z, Z, z+ = N - {O}
b) If f is a function from A to B, we say that A is the domain of f and B is the codomain of f.
If f (a) = b, we say that b is the image of a and a is a preimage of b. The range, or image, of f is the set
of all images of elements of A. Also, if f is a function from A to B, we say that f maps A to B.
Q9. a) Define what it means for a function from the set of positive integers to the set of positive
integers to be one-to-one.
b) Define what it means for a function from the set of positive integers to the set of positive
integers to be onto.
786
c) Give an example of a function from the set of positive integers to the set of positive
integers that is both
one-to-one and onto.
d) Give an example of a function from the set of positive integers to the set of positive
integers that is one-to-one
but not onto.
e) Give an example of a function from the set of positive integers to the set of positive
integers that is not
one-to-one but is onto.
f ) Give an example of a function from the set of positive integers to the set of positive
integers that is neither
one-to-one nor onto.
A9: a) A function f is said to be one-to-one, or an injunction, if and only if f (a) = f (b) implies that a =
b for all a and b in the domain of f.A function is said to be injective if it is one-to-one.
b) A function f from A to B is called onto, or a surjection, if and only if for every element b ∈ B
there is an element a ∈ A with f (a) = b.A function f is called surjective if it is onto.
Remark: A function f is onto if ∀y∃x(f (x) = y), where the domain for x is the domain of thefunction
and the domain for y is the codomain of the function.
E.g1: Let f be the function from {a, b, c, d} to {1, 2, 3} defined by f (a) = 3, f (b) = 2, f (c) = 1,
and f (d) = 3. Is f an onto function?
Solution: Because all three elements of the codomain are images of elements in the domain, we see
that f is onto. This is illustrated in Figure 4. Note that if the codomain were
{1, 2, 3,4}, then f would not be onto.
E.g2: Is the function f (x) = x2 from the set of integers to the set of integers onto?
Solution: The function f is not onto because there is no integer x with x2 = −1, for instance.
c) f(n) = n
d) f(n) = 2n
e) f(n) = f n/21
f) f(n) = 42548
Q10. a) Define the inverse of a function.
b) When does a function have an inverse?
c) Does the function f (n) = 10 − n from the set of integers to the set of integers have an
inverse? If so, what is it?
A10: a) Let f be a one-to-one correspondence from the set A to the set B. The inverse function of f is
the function that assigns to an element b belonging to B the unique element a in A such that f (a) =b.
The inverse function of f is denoted by f−1.
Hence, f −1 (b) = a when f (a) = b. (f-1 (b) =a= f (a) = b)
b) when it is one-to-one and onto
c) yes-itself
Q11. a) Define the floor and ceiling functions from the set of real numbers to the set of integers.
b) For which real numbers x is it true that _x_ = _x_?
A11: a) The floor function assigns to the real number x the largest integer that is less than or equal
to x. The value of the floor function at x is denoted by _x_. The ceiling function assigns to the
real number x the smallest integer that is greater than or equal to x. The value of the ceiling
function at x is denoted by _x_.
Remark: The floor function is often also called the greatest integer function. It is often denoted
by [x].
E.g: These are some values of the floor and ceiling functions:
[1/2]= 0, [1/2]= 1, [-1/2]= -1, [-1/2]= 0, [3.1]= 3, [3.1]= 4, [7] = 7, [7] = 7
We display the graphs of the floor and ceiling functions in Figure 10. In Figure 10(a) we display the
graph of the floor function _x_. Note that this function has the same value throughout the interval
786
[n, n + 1), namely n, and then it jumps up to n + 1 when x = n + 1. In Figure 10(b) we display the
graph of the ceiling function _x_. Note that this function has the same value throughout the interval
(n, n + 1], namely n + 1, and then jumps to n + 2 when x is a little larger than n + 1.
The floor and ceiling functions are useful in a wide variety of applications, including those involving
data storage and data transmission.
E.g: Data stored on a computer disk or transmitted over a data network are usually represented as a
string of bytes. Each byte is made up of 8 bits. How many bytes are required to encode 100 bits of
data?
Solution: To determine the number of bytes needed, we determine the smallest integer that is at
least as large as the quotient when 100 is divided by 8, the number of bits in a byte. Consequently,
[100/8] = [12.5] = 13 bytes are required.
b) Integers
Q12. Conjecture a formula for the terms of the sequence that begins 8, 14, 32, 86, 248 and find the
next three terms of your sequence.
A12: Hint: subtract 5 from each term and look at the resulting sequence.
Q13. Suppose that an = an−1 − 5 for n = 1, 2, ... Find a formula for an.
A13: The formula depends on the initial condition, namely the value of a0 . After that, each term is 5
less than the preceding term, so an = ao - 5n.
Q14. What is the sum of the terms of the geometric progression a + ar +・ ・ ・+arn when r _= 1?
A14:
Q15. Show that the set of odd integers is countable.
A15: Set up a one-to-one correspondence between the set of positive integers and the set of all odd
integers, such
as 1 ++ 1, 2 ++ 1, 3 ++ 3, 4 ++ 3, 5 ++ 5, 6 ++ 5, and so on.
Answer of (232) number page
Q1. a) Define the term algorithm.
b) What are the different ways to describe algorithms?
c) What is the difference between an algorithm for solving a problem and a computer program
that solves this problem?
A1: a) An algorithm is a finite sequence of precise instructions for performing a computation or for
solving a problem.
b) In English, In a computer language, In pseudocode
c) An algorithm is more of an abstract idea-a method in theory that will solve a problem. A
computer program is the implementation of that idea into a specific syntactically correct set of
instructions that a real computer can use to solve the problem. It is rather like the difference
between a dollar (a certain amount of money, capable in theory of purchasing a certain quantity of
goods and services) and a dollar bill.
Q2. a) Describe, using English, an algorithm for finding the largest integer in a list of n integers.
b) Express this algorithm in pseudocode.
c) How many comparisons does the algorithm use?
A2: a) This algorithm first assigns the initial term of the sequence, a1, to the variable max. The fo
loop is used to successively examine terms of the sequence. If a term is greater than the current
value of max, it is assigned to be the new value of max.
b) procedure max(a1, a2, . . . , an: integers)
max := a1
for i := 2 to n
if max < ai then max := ai
return max{max is the largest element}
786
c) Solution: The number of comparisons will be used as the measure of the time complexity of
the algorithm, because comparisons are the basic operations used.
To find the maximum element of a set with n elements, listed in an arbitrary order, the temporary
maximum is first set equal to the initial term in the list. Then, after a comparison i n has been done
to determine that the end of the list has not yet been reached, the temporary maximum and second
term are compared, updating the temporary maximum to the value of the second term if it is larger.
This procedure is continued, using two additional comparisons for each term of the list—one i n, to
determine that the end of the list has not been reached and another max < ai , to determine
whether to update the temporary maximum. Because two comparisons are used for each of the
second through the nth elements and one more comparison is used to exit the loop when i = n + 1,
exactly 2(n − 1) + 1 = 2n − 1 comparisons are used whenever this algorithm is applied. Hence, the
algorithm for finding the maximum of a set of n elements has time complexity _(n), measured in
terms of the number of comparisons used. Note that for this algorithm the number of comparisons
is independent of particular input of n numbers.
Next, we will analyze the time complexity of searching algorithms
3. a) State the definition of the fact that f (n) is O(g(n)), where f (n) and g(n) are functions from the
set of positive integers to the set of real numbers.
b) Use the definition of the fact that f (n) is O (g (n)) directly to prove or disprove that
n2 + 18n + 107 is O (n3).
c) Use the definition of the fact n is O (g (n)) directly to prove or disprove that n3 is
O (n2 + 18n + 107).
A3: a) Let f and g be functions from the set of integers or the set of real numbers to the set of real
numbers.We say that f (x) is O(g(x)) if there are constants C and k such that
|f (x)| C|g(x)|
whenever x > k. [This is ead as f (x) is big-oh of g(x). ]
b) n2
+l8n+107:::; n3
+ n3
+ n3
= 3n3
for all n > 107.
c) n3
is not less than a constant times n2
+ 18n + 107, since their ratio exceeds n3
/ (3n2) = n/3 for
all
n > 107.
Q4. List these functions so that each function is big-O of the next function in the list:
(log n)3
, n3/1000000, √n,100n
+ 101, 3n
, n!, 2n
n2
.
A4: (log n)3
, √n, l00n
+ 101, n3
/1000000, 2n
n2
, 3n
, n!
Q5. a) How can you produce a big-O estimate for a function that is the sum of different terms
where each term is the product of several functions?
b) Give a big-O estimate for the function f (n) = (n! + 1)(2n + 1) + (nn−2 + 8nn−3)
(n3 + 2n). For the function g in your estimate f (x) is O(g(x)) use a simple function of smallest
possible order.
A5: a) For the sum, take the largest term; for the product multiply the factors together.
b) g(n) = nn-2
2n
= (2n)n
/n2
Q6. a) Define what the worst-case time complexity, average case time complexity, and best-case
time complexity (in terms of comparisons) mean for an algorithm that finds the smallest integer in
a list of n integers.
b) What are the worst-case, average-case, and best-case time complexities, in terms of
comparisons, of the algorithm that finds the smallest integer in a list of n integers by comparing
each of the integers with the smallest integer found so far?
A6: a) the largest, average, and smallest number of comparisons used by the algorithm before it
stops, among all lists of n integers
b) all are n - 1
Q7. a) Describe the linear search and binary search algorithm for finding an integer in a list of
integers in increasing order.
b) Compare the worst-case time complexities of these two algorithms.
786
c) Is one of these algorithms always faster than the other (measured in terms of comparisons)?
A7: a) The linear search: The first algorithm that we will present is called the linear search, or
sequential search, algorithm. The linear search algorithm begins by comparing x and a1.
When x = a1, the solution is the location of a1, namely, 1. When x _= a1, compare x with a2. If
x = a2, the solution is the location of a2, namely, 2. When x _= a2, compare x with a3. Continue this
process, comparing x successively with each term of the list until a match is found, where the
solution is the location of that term, unless no match occurs. If the entire list has been searched
without locating x, the solution is 0. The pseudocode for the linear search algorithm is displayed as
Algorithm 2.
The linear search algorithm.
procedure linear search(x: integer, a1, a2, . . . , an: distinct integers)
i := 1
while (i n and x _= ai )
i := i + 1
if i n then location := i
else location := 0
return location{location is the subscript of the term that equals x, or is 0 if x is not found}
The binary search: We will now consider another searching algorithm. This algorithm can be used
when the list has terms occurring in order of increasing size (for instance: if the terms are numbers,
they are listed from smallest to largest; if they are words, they are listed in lexicographic, or
alphabetic, order). This second searching algorithm is called the binary search algorithm. It proceeds
by comparing the element to be located to the middle term of the list. The list is then split into two
smaller sublists of the same size, or where one of these smaller lists has one fewer term than the
other. The search continues by restricting the search to the appropriate sublist based on the
comparison of the element to be located and the middle term. In Section 3.3, it will be shown that
the binary search algorithm is much more efficient than the linear search algorithm. Example 3
demonstrates how a binary search works.
E.g: To search for 19 in the list
1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22,
first split this list, which has 16 terms, into two smaller lists with eight terms each, namely,
1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22.
Then, compare 19 and the largest term in the first list. Because 10 < 19, the search for 19 can be
restricted to the list containing the 9th through the 16th terms of the original list. Next, split this list,
which has eight terms, into the two smaller lists of four terms each, namely,
12 13 15 16 18 19 20 22.
Because 16 < 19 (comparing 19 with the largest term of the first list) the search is restricted to the
second of these lists, which contains the 13th through the 16th terms of the original list. The list 18
19 20 22 is split into two lists, namely, 18 19 20 22.
Because 19 is not greater than the largest term of the first of these two lists, which is also 19, the
search is restricted to the first list: 18 19, which contains the 13th and 14th terms of the original list.
Next, this list of two terms is split into two lists of one term each: 18 and 19. Because 18 < 19, the
search is restricted to the second list: the list containing the 14th term of the list, which is 19. Now
that the search has been narrowed down to one term, a comparison is made, and 19 is located as
the 14th term in the original list.
We now specify the steps of the binary search algorithm. To search for the integer x in the list a1,
a2, . . . , an, where a1 < a2 < ・ ・ ・ < an, begin by comparing x with the middle term am of the list,
where m = _(n + 1)/2_. (Recall that _x_ is the greatest integer not exceeding x.) If
x > am, the search for x is restricted to the second half of the list, which is am+1, am+2, . . . , an.
If x is not greater than am, the search for x is restricted to the first half of the list, which is a1,
a2,…am.The search has now been restricted to a list with no more than _n/2_ elements. (Recall that
[x] is the smallest integer greater than or equal to x.) Using the same procedure, compare x to the
786
middle term of the restricted list. Then restrict the search to the first or second half of the list.
Repeat this process until a list with one term is obtained. Then determine whether this term is x.
Pseudocode for the binary search algorithm is displayed as Algorithm 3.
The binary search algorithm:
procedure binary search (x: integer, a1, a2, . . . , an: increasing integers)
i := 1{i is left endpoint of search interval}
j := n {j is right endpoint of search interval}
while i < j
m := _(i + j)/2_
if x > am then i := m + 1
else j := m
if x = ai then location := i
else location := 0
return location{location is the subscript i of the term ai equal to x, or 0 if x is not found}
Algorithm 3 proceeds by successively narrowing down the part of the sequence being searched. At
any given stage only the terms from ai to aj are under consideration. In other words, i and j are the
smallest and largest subscripts of the remaining terms, respectively.
Algorithm 3 continues narrowing the part of the sequence being searched until only one term of the
sequence remains. When this is done, a comparison is made to see whether this term equals x.
b) The type of complexity analysis done in Example 2 is a worstcase analysis. By the worst-case
performance of an algorithm, we mean the largest number of operations needed to solve the given
problem using this algorithm on input of specified size.
Worst-case analysis tells us how many operations an algorithm requires to guarantee that it will
produce a solution.
c) No-it depends on the lists involved. (However, the worst case complexity for binary search is
always better than that for linear search for lists of any given size except for very short lists.)
Q8. a) Describe the bubble sort algorithm.
b) Use the bubble sort algorithm to sort the list 5, 2, 4, 1, 3.
c) Give a big-O estimate for the number of comparisons used by the bubble sort.
A8: a) Bubble Sort: The bubble sort is one of the simplest sorting algorithms, but not one
of the most efficient. It puts a list into increasing order by successively comparing adjacent
elements, interchanging them if they are in the wrong order. To carry out the bubble sort, we
perform the basic operation, that is, interchanging a larger element with a smaller one following
it, starting at the beginning of the list, for a full pass.We iterate this procedure until the sort is
complete. Pseudocode for the bubble sort is given as Algorithm 4.We can imagine the elements
in the list pla ed i a olu . I the u le so t, the s alle ele e ts u le to the top as
the a e i te ha ged ith la ge ele e ts. The la ge ele e ts si k to the otto . This is
illustrated in Example 4. E.g: Use the bubble sort to put 3, 2, 4, 1, 5 into increasing order.
Note: Blue Color is for an interchange
Red Color for pair in correct order
Green Color is numbers in color
guaranteed to be in correct order.
For more information See book
First Pass
Second
Pass
Third
Pass
Forth
Pass
3 2 2 2 2 2 2 2 1 1
2 3 3 3 3 3 1 1 2 2
4 4 4 1 1 1 3 3 3 3
1 1 1 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
786
page no (197)
b) On the first pass, the 5 bubbles down to the end, producing 2 4 1 3 5. On the next pass, the 4
bubbles down to the end, producing 213 4 5. On the next pass, the 1 and the 2 are swapped. No
further changes are made on the fourth pass.
c) The bubble sort described before Example 4 in Section 3.1 sorts a list by performing a
sequence of passes through the list. During each pass the bubble sort successively compares
adjacent elements, interchanging them if necessary. When the ith pass begins, the i − 1 largest
elements are guaranteed to be in the correct positions. During this pass, n − i comparisons are used.
Consequently, the total number of comparisons used by the bubble sort to order a list of n elements
is
(n − 1) + (n − 2) +・ ・ ・+2 + 1 = (n − 1)n/2
Note that the bubble sort always uses this many comparisons, because it continues even if the list
becomes completely sorted at some intermediate step. Consequently, the bubble sort uses (n −
1)n/2 comparisons, so it has O(n2
) worst-case complexity in terms of
the number of comparisons used.
Q9. a) Describe the insertion sort algorithm.
b) Use the insertion sort algorithm to sort the list 2, 5, 1, 4, 3.
c) Give a big-O estimate for the number of comparisons used by the insertion sort.
A9: a) The insertion sort is a simple sorting algorithm, but it is usually not the most efficient. To sort
a list with n elements, the insertion sort begins with the second element. The insertion sort
compares this second element with the first element and inserts it before the first element if it does
not exceed the first element and after the first element if it exceeds the first element. At this point,
the first two elements are in the correct order. The third element is then compared with the first
element, and if it is larger than the first element, it is compared with the second element; it is
inserted into the correct position among the first three elements.
In general, in the j th step of the insertion sort, the j th element of the list is inserted into the correct
position in the list of the previously sorted j − 1 elements. To insert the j th element in the list, a
linear search technique is used (see Exercise 43); the j th element is successively compared with the
already sorted j − 1 elements at the start of the list until the first element that is not less than this
element is found or until it has been compared with all j − 1 elements; the j th element is inserted in
the correct position so that the first j elements are sorted. The algorithm continues until the last
element is placed in the correct position relative to the already sorted list of the first n − 1 elements.
The insertion sort is described in pseudocode in Algorithm 5.
E.g: Use the insertion sort to put the elements of the list 3, 2, 4, 1, 5 in increasing order.
Solution: The insertion sort first compares 2 and 3. Because 3 > 2, it places 2 in the first position,
producing the list 2, 3, 4, 1, 5 (the sorted part of the list is shown in color). At this point, 2 and 3 are
in the correct order. Next, it inserts the third element, 4, into the already sorted part of the list by
making the comparisons 4 > 2 and 4 > 3. Because 4 > 3, 4 remains in the third position.
At this point, the list is 2, 3, 4, 1, 5 and we know that the ordering of the first three elements is
correct. Next, we find the correct place for the fourth element, 1, among the already sorted
elements, 2, 3, 4. Because 1 < 2, we obtain the list 1, 2, 3, 4, 5. Finally, we insert 5 into the correct
position by successively comparing it to 1, 2, 3, and 4. Because 5 > 4, it stays at the end of the list,
producing the correct order for the entire list.
Insertion Sort algorithm:
procedure insertion sort(a1, a2, . . . , an: real numbers with n 2)
for j := 2 to n
i := 1
while aj > ai
i := i + 1
m := aj
786
for k := 0 to j − i − 1
aj−k := aj−k−1
ai := m
{a1, . . . , an is in increasing order}
b) On the first pass, the 5 is inserted into its correct position relative to the 2, producing 2 5 14 3.
On the next pass, the 1 is inserted into its correct position relative to 2 5, producing 1 2 5 4 3. On the
next pass, the
4 is inserted into its correct position relative to 1 2 5, producing 1 2 4 5 3. On the final pass, the 3 is
inserted, producing the sorted list.
c) O(n2 );
E.g: What is the worst-case complexity of the insertion sort in terms of the number of comparisons
made?
Solution: The insertion sort (described in Section 3.1) inserts the j th element into the correct
position among the first j − 1 elements that have already been put into the correct order. It does this
by using a linear search technique, successively comparing the j th element with successive terms
until a term that is greater than or equal to it is found or it compares aj with itself and stops because
aj is not less than itself. Consequently, in the worst case, j comparisons are required
to insert the j th element into the correct position. Therefore, the total number of comparisons
used by the insertion sort to sort a list of n elements is
2 + 3+・ ・ ・+n = n(n + 1)/2 – 1
using the summation formula for the sum of consecutive integers in line 2 of Table 2 of
Section 2.4 (and see Exercise 37(b) of Section 2.4), and noting that the first term, 1, is missing in this
sum. Note that the insertion sort may use considerably fewer comparisons if the smaller elements
started out at the end of the list. We conclude that the insertion sort has worst-case complexity
O(n2).
Q10. a) Explain the concept of a greedy algorithm.
b) Provide an example of a greedy algorithm that produces an optimal solution and explain
why it produces an optimal solution.
c) Provide an example of a greedy algorithm that does not always produce an optimal
solution and explain why it fails to do so.
A10: a) Algorithms that ake hat see s to e the est hoi e at ea h step a e alled greedy
algorithms.
Once we know that a greedy algorithm finds a feasible solution, we need to determine whether it
has fou d a opti al solutio . Note that e all the algo ith g eed whether or not it finds an
optimal solution.) To do this, we either prove that the solution is optimal or we show that there is a
counterexample where the algorithm yields a non optimal solution.
....See page NO (198) for extra details in Book
b) Consider the problem of making n cents change with quarters, dimes, nickels, and pennies,
and using the least total number of coins.We can devise a greedy algorithm for making change for n
cents by making a locally optimal choice at each step; that is, at each step we choose the coin of the
largest denomination possible to add to the pile of change without exceeding n cents. For example,
to make change for 67 cents, we first select a quarter (leaving 42 cents).We next select a second
quarter (leaving 17 cents), followed by a dime (leaving 7 cents), followed by a nickel (leaving 2
cents), followed by a penny (leaving 1 cent), followed by a penny.
We display a greedy change-making algorithm for n cents, using any set of denominations
of coins, as Algorithm 6.
Algorithm of Greedy Algorithm:
procedure change(c1, c2, . . . , cr : values of denominations of coins, where
c1 > c2 > ・ ・ ・ > cr ; n: a positive integer)
786
for i := 1 to r
di := 0 {di counts the coins of denomination ci used}
while n ci
di := di + 1 {add a coin of denomination ci}
n := n − ci
{di is the number of coins of denomination ci in the change for i = 1, 2, . . . , r}
We have described a greedy algorithm for making change using any finite set of coins with
denominations c1, c2, ..., cr . In the particular case where the four denominations are quarters
dimes, nickels, and pennies, we have c1 = 25, c2 = 10, c3 = 5, and c4 = 1. For this case, we will show
that this algorithm leads to an optimal solution in the sense that it uses the fewest coins possible.
Before we embark on our proof, we show that there are sets of coins for which the greedy algorithm
(Algorithm 6) does not necessarily produce change using the fewest coins possible. For example, if
we have only quarters, dimes, and pennies (and no nickels) to use, the greedy algorithm would make
change for 30 cents using six coins—a quarter and five pennies—whereas we could have used three
coins, namely, three dimes.
c) Use the greedy algorithm to make change using quarters, dimes, and pennies (but no nickels)
for each of the amounts given in Exercise 53. For which of these amounts does the greedy algorithm
use the fewest coins of these denominations possible?
Solution: Two quarters, one dime, nine pennies. In page (S-20) question No(55)
Q11. Define what it means for a problem to be tractable and what it means for a problem to be
solvable.
A11: A problem that is solvable using an algorithm with polynomial worst-case complexity is called
tractable, because the expectation is that the algorithm will produce the solution to the problem for
reasonably sized input in a relatively short time. However, if the polynomial in the big-_ estimate has
high degree (such as degree 100) or if the coefficients are extremely large, the algorithm may take
an extremely long time to solve the problem. Consequently, that a problem can be solved using an
algorithm with polynomial worst-case time complexity is no guarantee that the problem can be
solved in a reasonable amount of time for even relatively small input values. Fortunately, in practice,
the degree and coefficients of polynomials in such estimates are often small.
The situation is much worse for problems that cannot be solved using an algorithm with worst-case
polynomial time complexity. Such problems are called intractable. Usually, but not always, an
extremely large amount of time is required to solve the problem for the worst cases of even small
input values. In practice, however, there are situations where an algorithm with a certain worst-case
time complexity may be able to solve a problem much more quickly for most cases than for its worst
case. When we are willing to allow that some, perhaps small, number of cases may not be solved in a
reasonable amount of time, the average-case time complexity is a better measure of how long an
algorithm takes to solve a problem. Many problems important in industry are thought to be
intractable but can be practically solved for essentially all sets of input that arise in daily life. Another
way that intractable problems are handled when they arise in practical applications is that instead of
looking for exact solutions of a problem, approximate solutions are sought. It may be the case that
fast algorithms exist for finding such approximate solutions, perhaps even with a guarantee that
they do not differ by very much from an exact solution.
Some problems even exist for which it can be shown that no algorithm exists for solving them. Such
problems are called unsolvable (as opposed to solvable problems that can be solved using an
algorithm). The first proof that there are unsolvable problems was provided by the great English
mathematician and computer scientist Alan Turing when he showed that the halting problem is
unsolvable. Recall that we proved that the halting problem is unsolvable in Section 3.1
A solvable problem is simply one that can be solved by an algorithm. The halting problem is proved
on pp. 201-202 to be unsolvable.
Page : 307
786
Q1.Find 210 div 17 and 210 mod 17.
A1: Dividing 210 by 17 gives a quotient of 12 and a remainder of 6, which are the respective
requested values.
÷ = ∗ +
% =
Q . a Defi e hat it ea s fo a a d to e o g ue t odulo .
a) 7 | a - b
Whi h pai s of the i tege s − ,− ,− ,− , , , a d a e o g ue t odulo ?
b) 0 ≡ -7; -1 ≡ -8; 3 ≡ 17 ≡ -11
c) Sho that if a a d a e o g ue t odulo , the a + a d− + a e also o g ue t
modulo 7.
c) (10a + 13) - (-4b + 20) = 3(a - b) + 7(a + b - 1);
note that 7 divides both terms
Q . Sho that if a ≡ od a d ≡ d od , the a + ≡ + d od .
A3: THEOREM 5
Let e a positi e i tege . If a ≡ od a d ≡ d od , the a + ≡ + d od a d
a ≡ d od .
Proof:
We use a di e t p oof. Be ause a ≡ od a d ≡ d od , Theo e t
are integers s and t with b = a + sm and d = c + tm. Hence,
b + d = (a + sm) + (c + tm) = (a + c) + m(s + t)
and
bd = (a + sm)(c + tm) = ac + m(at + cs + stm).
Hence,
a + ≡ + d od a d a ≡ d od .
E.g 6 Be ause ≡ od a d ≡ od , it follows from Theorem 5 that
= + ≡ + = od , a d that
77 · ≡ · = od .
Q4.Describe a procedure for converting decimal (base 10) expansions of integers into
hexadecimal expansions.
A4:
E.g 5: Find the hexadecimal expansion of (177130)10.
Solution: First divide 177130 by 16 to obtain
177130 = 16 · 11070 + 10.
Successively dividing quotients by 16 gives
11070 = 16 · 691 + 14,
691 = 16 · 43 + 3,
43 = 16 · 2 + 11,
2 = 16 · 0 + 2.
The successive remainders that we have found, 10, 14, 3, 11, 2, give us the digits from the
right to the left of 177130 in the hexadecimal (base 16) expansion of (177130)10. It follows
that
(177130)10 = (2B3EA)16.
(Recall that the integers 10, 11, and 14 correspond to the hexadecimal digits A, B, and E,
respectively.)
786
Q5. Convert (1101 1001 0101 1011)2 to octal and hexadecimal representations.
A5: Octal: 154533;
hexadecimal: D95B
Q6. Convert (7206)8 and (A0EB)16 to a binary representation.
A6: (7206)8 =1110 1000 0110
(A0EB)16 =1010 0000 1110 1011;
Q7. State the fundamental theorem of arithmetic.
A7: THEOREM 1
The fundamental theorem of arithmetic:
Every integer greater than 1 can be written uniquely as a prime or as the product of two or more
primes where the prime factors are written in order of no decreasing size.
E.g: gives some prime factorizations of integers.
E.g 2: The prime factorizations of 100, 641, 999, and 1024 are given by
100 = 2 · 2 · 5 · 5 = 22
52
,
641 = 641,
999 = 3 · 3 · 3 · 37 = 33
· 37,
1024 = 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 = 210
.
Q8. a Des i e a p o edu e fo fi di g the p i e fa to izatio of a i tege .
A8:
Find the prime factorization of 7007.
Solution:
To fi d the p i e fa to izatio of , fi st pe fo di isio s of su essi e p i es,
beginning with 2. None of the primes 2, 3, and 5 divides 7007. However, 7 divides 7007, with 7007/7
= 1001. Next, divide 1001 by successive primes, beginning with 7.It is immediately seen that 7 also
divides 1001, because 1001/7 = 143. Continue by dividing 143 by successive primes, beginning with
7. Although 7 does not divide 143, 11 does divide 143, and 143/11 = 13. Because 13 is prime, the
procedure is completed. It follows that 7007 = 7 · 1001 = 7 · 7 · 143 = 7 · 7 · 11· 13. Consequently, the
prime factorization of 7007 is 7 · 7 · 11 · 13 = 72 · 11 · 13. ▲
Use this p o edu e to fi d the p i e fa to izatio of , .
b) 112
. 23 . 29
Q9. a) Defi e the g eatest o o di iso of t o i tege s.
A9: Let a and b be integers, not both zero. The largest integer d such that d | a and d | b is called the
greatest common divisor of a and b. The greatest common divisor of a and b is denoted by gcd(a, b).
E.g: What is the greatest common divisor of 24 and 36?
Solution: The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12. Hence, gcd(24, 36) = 12.
See the Note Also
a) Des i e at least th ee diffe e t a s to fi d the g eatest o o di iso of t o i tege s
.When does each method work best?
b) find all the common factors (not a good algorithm unless the numbers are really
small); find the prime
factorization of each integer (works well if the numbers aren't too big and therefore can be
easily factored); use the Euclidean algorithm (really the best method). See the Algorithm in Book
P()
a) Find the greatest common divisor of 1,234,567 and 7,654,321.
786
1,234,567 and 7,654,321 =1 (use the Euclidean algorithm)
a) Find the greatest common divisor of 23
35
57
79
11 and 29
37
55
73
13.
d) 23
35
55
73
Q10. a Ho a ou fi d a li ea o i atio ith i tege oeffi ie ts of t o i tege s that
equals their greatest common divisor?
a) Use the Euclidean algorithm; see Example 17 in Section 4.3.
EXAMPLE 17 Express gcd(252, 198) = 18 as a linear combination of 252 and 198.
Solution: To show that gcd(252, 198) = 18, the Euclidean algorithm uses these divisions:
252 = 1 · 198 + 54
198 = 3 · 54 + 36
54 = 1 · 36 + 18
36 = 2 · 18.
Using the next-to-last division (the third division), we can express gcd(252, 198) = 18 as a linear
o i atio of a d .We fi d that
= − · .
The second division tells us that
= − · .
Substituting this expression for 36 into the previous equation, we can express 18 as a linear
combination of 54 and 198.We have
= − · = − · − · = · − · .
The fi st di isio tells us that
= − · .
Substituting this expression for 54 into the previous equation, we can express 18 as a linear
combination of 252 and 198.We conclude that
= · − · − · = · − · ,
completing the solution.
b) Express gcd(84, 119) as a linear combination of 84 and 119.
b) 7 = 5 . 119 - 7. 84
Q11. a What does it ea fo a to e a i e se of a odulo ?
a aa’ = od m)
Ho a ou fi d a i e se of a odulo he is a positi e i tege a d g d a, = ?
b) Express 1 as sa + tm (see Review Question 10). Then s is the inverse of a modulo m.
c) Find an inverse of 7 modulo 19.
c) 11;
Q12. a Ho a a i e se of a odulo e used to sol e the o g ue e a ≡ od he
gcd (a ,m) = 1?
a) Multiply each side by the inverse of a modulo m.
Sol e the li ea o g ue e ≡ od .
b) { 10 + 19k I k E z }
Q13. a) State the Chinese remainder theorem.
A13:
THE CHINESE REMAINDER THEOREM
Let m1,m2,...,mn be pairwise relatively
prime positive integers greater than one and a1,a2,...,an arbitrary integers. Then the system
≡ a od m1),
786
≡ a od ,
·
·
·
≡ a od
has a unique solution modulo m = m1m2 ···mn. (That is, there is a solution x with
< , a d all othe solutio s a e o g ue t odulo to this solutio .
x = a M y + a M y +···+ a M y .
≡ akMk k ≡ ak od k),
for k = 1, 2,...,n.We have shown that x is a simultaneous solution to the n congruences.
EXAMPLE 5
To sol e the s ste of o g ue es i E a ple , fi st let = · · = , M = / =
35,M2 = m/5 = 21, and M3 = m/7 = 15.We see that 2 is an inverse of M1 = 35 modulo 3,
e ause · ≡ · ≡ od ; is a i e se of M = odulo , e ause ≡
od ; a d is a i e se of M = od , e ause ≡ od . The solutio s to
this system are those x such that
≡ a M + a M + a3M3y3 = 2 · 35 · 2 + 3 · 21 · 1 + 2 · 15 · 1
= ≡ od .
Fi d the solutio s to the s ste ≡ od , ≡ od , a d ≡ od .
b) { 17 + l40k I k E z}
Q14. Suppose that 2 −
≡ od .Is e essa il p i e?
No; n could be a pseudo prime such as 341.
. Use Fe at s little theo e to e aluate 200
mod 19.
9200
= 918
. 92
. 9180
= 918
. 92
. (918
)20
= 1 . 81 . 120
= 81 = 5 (mod 19)
16. Explain how the check digit is found for a 10-digit ISBN.
Example 6 :
I“BNs All ooks a e ide tified a I te atio al “ta da d Book Nu e I“BN-10),a
10-digit code x1x2 ...x10, assigned by the publisher. (Recently, a 13-digit code known as ISBN-
13 was introduced to identify a larger number of published works; see the preamble to Exercise
42 in the Supplementary Exercises.) An ISBN-10 consists of blocks identifying the language,
the pu lishe , the u e assig ed to the ook its pu lishi g o pa , a d fi all , a he k
digit that is either a digit or the letter X (used to represent 10). This check digit is selected so
that
� ≡ ∑ ��� mod
9
�=
or equivalently, so that
∑ ��� ≡ mod
�=
Answer these questions about ISBN-10s:
a The fi st i e digits of the I“BN-10 of the sixth edition of this book are 007288008.What is the
check digit?
(b) Is 084930149X a valid ISBN-10?
Solution: (a) The check digit is determined by the congruence 10
i= i i ≡ od . I se ti g the digits gi es ≡ · + · + · + · + · + ·
+ 7 · 0 + 8 · 0 +
786
· od . This ea s that ≡ + + + + + + + + od , so
≡ ≡ od . He e, = .
(b) To see whether 084930149X is a valid ISBN-10, we see if
10
i= i i ≡ od . We
see that 1 · 0 + 2 · 8 + 3 · 4 + 4 · 9 + 5 · 3 + 6 · 0 + 7 · 1 + 8 · 4 + 9 · 9 + 10 · 10 = 0 + 16 +
+ + + + + + + = ≡ ≡ od . He e, X is ot
a valid ISBN-10.
Q17. Encrypt the message APPLES AND ORANGES using a shift cipher with key k = 13.
A17: NCCYRF NAQ BENATRF
Q18. a) What is the difference between a public key and a private key cryptosystem?
‫غواړي‬ ‫کتل‬ ‫سم‬
b) Explain why using shift ciphers is a private key system.
b) The amount of shift, k, is kept secret. It is needed both to encode and to decode
messages.
c) Explain why the RSA cryptosystem is a public key system.
c) Although the key for decoding, d, is kept secret, the keys for encoding, n and e, are
published.
19. Explain how encryption and decryption are done in the RSA cryptosystem.
299-301 ‫کتل‬ ‫صفحه‬
. Des i e ho t o pa ties a sha e a se et ke usi g the Diffie-Hellman key exchange
protocol.
302 ‫کتل‬ ‫صفحه‬
Page : 378
Q1. a Ca ou use the p i iple of athe ati al i du tio to fi d a fo ula fo the su of the
first n terms of a sequence?
a) no
b) Can you use the principle of mathematical induction to determine whether a given formula
fo the su of the fi st te s of a se ue e is o e t?
b) Sometimes yes. If the given formula is correct, then it is often possible to prove it using
the principle of mathematical induction (although it would be wishful thinking to believe that
every such true formula could be so proved). If the formula is incorrect, then induction would not
work, of course; thus an incorrect formula could not be shown to be incorrect using the principle.
Fi d a fo ula fo the su of the fi st e e positi e i tege s, a d p o e it usi g
mathematical induction.
Exercise 9.
C Fi d a fo ula fo the su of the fi st e e positi e i tege s.
a) 2+4+6+···+2n = n(n+1)
b) Prove the formula that you conjectured in part (a).
b) Basis step: 2 = 1·(1+1) is true. Inductive step: Assume that 2 + 4 + 6 +···+ 2k = k(k + 1).
Then (2 + 4 + 6 + ··· + 2k) + 2(k + 1) = k(k+1)+2(k+1) = (k+1)(k+2).
Q2.
a Fo hi h positi e i tege s a e + n
?
786
a) n 7
b) Prove the conjecture you made in part (a) using mathematical induction.
Fo the asis step e just he k that · + . Fi 7, and assume the inductive
hypothesis, that 11n + 17 2n
. Then 11(n + 1) + 17= (11n+17) + 11 2n+11 < 2n
+ 2n = 2n+1
. The
strict inequality here follows from the fact that n 4.
Q3. a) Which amounts of postage can be formed using only 5-cent and 9-cent stamps?
a) Carefully considering all the possibilities shows that the amounts of postage less than 32
cents that can be achieved are 0, 5, 9, 10, 14, 15, 18, 19, 20, 23, 24, 25, 27, 28, 29, and 30.
All amounts greater than or equal to 32 cents can be achieved.
b) Prove the conjecture you made using mathematical induction.
b) To prove this latter statement, we check the basis step by noting that 32 = 9 + 9 + 9 + 5.
Assume that we can achieve n cents, and consider n + 1 cents, where n 32. If the stamps
used for n cents included a 9-cent stamp, then replacing it by two 5-cent stamps gives us n +
1 cents, as desired. Otherwise only 5-cent stamps were used to achieve n cents, and since n >
30, there must be at least seven such stamps. Replace seven of the 5-cent stamps by four 9-cent
stamps; this increases the amount of postage by 4 · 9 - 7 · 5 = 1 cent, again as desired.
c) Prove the conjecture you made using strong induction.
c) We check the base cases 32 = 3 · 9 + 5, 33 = 2 · 9 + 3 · 5, 34 = 9 + 5 · 5, 35 = 7 · 5, and 36 =
4 · 9. Fix n 37 and assume that all amounts from 32 to n - 1 can be achieved. To achieve n
cents postage, take the stamps used for n - 5 cents (since n 37, n - 5 32, so the inductive
hypothesis applies) and adjoin a 5-cent stamp.
d) Find a proof of your conjecture different from the ones you gave in (b) and (c).
d) Let n be an integer greater than or equal to 32. We want to express n as a sum of a
nonnegative multiple of 5 and a nonnegative multiple of 9. Divide n by 5 to obtain a quotient
q and remainder r such that n = 5q + r and 0 r 4. Note that since n 32, q 6. If r = 0,
then we already have n expressed in the desired form. If r = 1, then n 36, so q 7; thus we
can write n = 5q + 1 = 5(q - 7) + 4 · 9 to get the desired decomposition. If r = 2, then we
rewrite n = 5q + 2 = 5(q - 5) + 3 · 9. If r = 3, then we rewrite n = 5q + 3 = 5(q - 3) + 2 · 9.
And if r = 4, then we rewrite n = 5q + 4 = 5(q - 1) + 9. In each case we have the desired sum.
Q4. Give two different examples of proofs that use strong induction.
Section 5.2 example 2 and 3 page 336;
EXAMPLE 2 Show that if n is an integer greater than 1, then n can be written as the product of
primes.
Solution: Let P(n) be the proposition that n can be written as the product of primes.
BASIS STEP: P(2) is true, because 2 can be written as the product of one prime, itself. (Note that P(2)
is the fi st ase e eed to esta lish.
EXAMPLE 3 Consider a game in which two players take turns removing any positive number of
matches they want from one of two piles of matches. The player who removes the last match wins
the game.
Show that if the two piles contain the same number of matches initially, the second player can
always guarantee a win.
Solution: Let n be the number of matches in each pile. We will use strong induction to prove P(n),
the statement that the second player can win when there are initially n matches in each pile.
Q5. a) State the well-ordering property for the set of positive integers.
a) Seep. 314 and Appendix 1 (Axiom 4 for the positive integers).
Axiom 4 The Well-Ordering Property Every nonempty subset of the set of positive integers has a
least element.
In Sections 5.1 and 5.2 it is shown that the well-ordering principle is equivalent to the principle of
mathematical induction.
786
PRINCIPLE OF MATHEMATICAL INDUCTION
To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, we
complete two steps:
BASIS STEP: We verify that P(1) is true.
INDUCTIVE STEP: We sho that the o ditio al state e t P k → P k + is t ue fo all positi e
integers k.
a) Use this property to show that every positive integer greater than one can be written as
the product of primes.
b) Let S be the set of positive integers that cannot be written as the product of primes. If
S #- 0, then S has a least element, c. Clearly c ≠ 1, since 1 is the product of no primes.
Thus c is greater than 1. Now c cannot be prime, since as such it would already be
written as the product of primes (namely itself). Therefore c is a composite number, say c
=ab, where a and b are both positive integers less than c. Since c is the smallest element of S,
neither a nor b is in S. Therefore both a and b can be written as the product of primes. But
multiplying these products together patently shows that c is the product of primes. This is a
contradiction to the choice of c. Therefore our assumption that S ≠ 0 was wrong, and
the theorem is proved.
Q6. a) Explain why a function � from the set of positive integers to the set of real numbers is well-
defi ed if it is defi ed e u si el spe if i g � a d a ule fo fi di g � (n) from � − .
a) See Exercise 56 in Section 5.3.
. Use athe ati al i du tio to p o e that a fu tio F defi ed spe if i g F a d a ule fo
obtaining
F + f o F is ell defi ed.
‫نسته‬ ‫کي‬ ‫کت‬ ‫غواړي‬ ‫حل‬
P o ide a e u si e defi itio of the fu tio � (n) = (n + 1)!
b) f(1) = 2, and f(n) = (n + l)f(n - 1) for all n 2
Q . a Gi e a e u si e defi itio of the Fi o a i u e s.
a) See the top of p. 347.
Re all f o “e tio . that the Fi o a i u e s, f ,f ,f ,..., a e defi ed the e uations f0 = 0,f1
= , a d f = f − + f − fo = , , ,.... [We a thi k of the Fi o a i u e f eithe as the th
term of the sequence of Fibonacci numbers f0,f1,... or as the value at the integer n of a function f
.] We a use the e u si e definition of the Fibonacci numbers to prove many properties of these
numbers.We give one such property in Example 4.
EXAMPLE 4 “ho that he e e , f >α −
, he e α = +√ / .
Solution: We can use strong induction to prove this inequality. Let P(n) be the statement fn >α −
.We
want to show that P(n) is true whenever n is an integer greater than or equal to 3.
BA“I“ “TEP: Fi st, ote that α< = f , α = +√ / < = f , so P a d P a e t ue.
b) Show that � � > ��−
whenever n , he e � n is the nth term of the Fibonacci
sequence and
α = +√5)/2.
EXAMPLE 4 “ho that he e e , f >α −
, he e α = +√ / .
Solution: We can use strong induction to prove this inequality. Let P(n) be the statement
fn >α −
.We want to show that P(n) is true whenever n is an integer greater than or equal to 3.
BA“I“ “TEP: Fi st, ote that α< = f , α = +√ / < = f , so P a d P a e t ue.
Q8. a E plai h a se ue e a is ell defi ed if it is defi ed e u si el specifying a1 and a2
a d a ule fo fi di g an from a1,a2,...,a − for n = 3, 4, 5,....
a) See Exercise 57 in Section 5.3.
57. Use strong inductio to p o e that a fu tio F defi ed spe if i g F a d a ule fo o tai i g
F + f o the alues F k fo k = , , ,..., is ell defi ed.
786
. Let P e F is ell-defi ed. The P is t ue e ause F is spe ified. Assu e that P k is
true for all k<n. Then F(n) is well-defi ed at e ause F is gi e i te s of F , F , . . . , F −
1).So P(n) is true for all integers n.
b) Find the value of an if a1 = 1, a2 = 2, and an = a − + a − +···+ a1, for n = 3, 4, 5,....
b) an = 3 · 2n-3
for n 3
9. Give two examples of how well-fo ed fo ulae a e defi ed e u si el fo diffe e t sets of
elements and operators.
EXAMPLE 8
Well-Fo ed Fo ulae i P opositio al Logi We a defi e the set of ell-formed formulae in
propositional logic involving T, F, propositional variables, and operators from the set {¬, , ,→,↔}.
BASIS STEP: T, F, and s, where s is a propositional variable, are well-formed formulae.
RECURSIVE STEP: If E and F are well-formed formulae, then (¬E), (E F), (E F , E → F , a d E ↔ F
are well-formed formulae.For example, by the basis step we know that T, F, p, and q are well-formed
formulae, where p and q are propositional variables. From an initial application of the recursive step,
we know that (p q), (p → F), (F → q), and (q F) are well-formed formulae. A second application of
the recursive step shows that ((p q) → (q F)), (q (p , a d p → F → T a e ell-formed
formulae. We leave it to the reader to show that p¬ q, pq , and ¬ pq are not well-formed
formulae, by showing that none can be obtained using the basis step and one or more applications
of the recursive step. ▲
EXAMPLE 9
Well-Fo ed Fo ulae of Ope ato s a d Ope a ds We a defi e the set of ell-formed formulae
consisting of variables, u e als, a d ope ato s f o the set {+,−, ∗, /, ↑} (where ∗ denotes
ultipli atio a d ↑ de otes e po e tiatio e u si el .
BASIS STEP: x is a well-formed formula if x is a numeral or a variable.
RECURSIVE STEP: If F and G are well-formed formulae, the F + G , F − G , F ∗ G , F/G , a d F ↑G
are well-formed formulae. For example, by the basis step we see that x, y, 0, and 3 are well-formed
formulae (as is any variable or numeral).Well-formed formulae generated by applying the recursive
step once i lude + , + , − , − , ∗ 3), (3 ∗ y), (3/0), (x/y), (3↑x), and (0↑3).
Appl i g the e u si e step t i e sho s that fo ulae su h as + + a d − ∗ y)) are well-
formed formulae. [Note that (3/0) is a well-formed formula because we are concerned only with
syntax matters here.]We leave it to the reader to show that each of the formulae x3+, y ∗+x, and ∗
x/y is not a well-formed formula by showing that none of them can be obtained from the basis step
and one or more applications of the recursive step. ▲
Q . a Gi e a e u si e defi itio of the le gth of a st i g.
a) See Example 7 in Section 5.3.
EXAMPLE 7
Le gth of a “t i g Gi e a e u si e defi itio of l , the le gth of the st i g .
Solution: The length of a string a e e u si el defi ed
L λ = ;
L(wx) = L(w) + 1 if w ∈ ∑∗
and x ∈ ∑∗
.
Use the e u si e defi itio f o pa t a a d st u tu al i du tio to p o e that l = l
+ l(y).
EXAMPLE 12
Use structural induction to prove that l(xy) = l(x) + l(y), where x and y belong to
∗, the set of strings over the alphabet ∑ .
“olutio : We ill ase ou p oof o the e u si e defi itio of the set ∑∗ given in Definition 1 and
the defi itio of the le gth of a st i g i E a ple , hi h spe ifies that l λ = a d l = l +
when w ∈ ∗ and x ∈ . Let P(y) be the
statement that l(xy) = l(x) + l(y) whenever x belongs to ∑ ∗.
786
BA“I“ “TEP: To o plete the asis step, e ust sho that P λ is t ue. That is, e ust sho that
l λ = l + l λ fo all x ∈ ∗. Because l(xλ) = l(x) = l(x) + 0 = l(x) + l(λ)
fo e e st i g , it follo s that P λ is t ue.
Q11. a) What is a recursive algorithm?
See the beginning of Section 5.4.
DEFINITION 1
An algorithm is called recursive if it solves a problem by reducing it to an instance of the same
problem with smaller input.
EXAMPLE 2
Give a recursive algorithm for computing an, where a is a nonzero real number and n is a
nonnegative integer.
Solution: We a ase a e u si e algo ith o the e u si e defi itio of a . This defi itio states
that a + = a · a fo > a d the i itial o ditio a = . To fi d a , su essi el use the e u si e
step to reduce the exponent until it becomes zero. We give this procedure in Algorithm 2. ▲
b) Describe a recursive algorithm for computing the sum of n numbers in a sequence.
b) Call the sequence a 1 , a2 , ... , an. If n = 1, then the sum(a1) = a1. Otherwise
sum(a1,a2, ... ,an) =an + su a ,a ,…an-1 ).
Q12. Describe a recursive algorithm for computing the greatest common divisor of two positive
integers.
See Example 3 in Section 5.4.
EXAMPLE 3 Give a recursive algorithm for computing the greatest common divisor of two
nonnegative integers a and b with a<b.
Solution: We can base a recursive algorithm on the reduction gcd(a, b) = gcd(b mod a,a) and the
condition gcd(0,b) = b when b> 0. This produces the procedure inAlgorithm 3, which is a recursive
version of the Euclidean algorithm.
We illustrate the workings ofAlgorithm 3 with a trace when the input is a = 5, b = 8.With this input,
the algo ith uses the else lause to fi d that g d , = g d od , = g d , . It uses this
lause agai to fi d that g d , = g d od , = g d , , the to get g d , = g d od ,
2) = gcd(1, 2), the to get g d , = g d od , = g d , . Fi all , to fi d g d , it uses the
fi st step ith a = to fi d that g d , = .Co se ue tl , the algo ith fi ds that g d , = .
Q13. a) Describe the merge sort algorithm.
The Merge Sort
We now describe a recursive sorting algorithm called the merge sort algorithm. We will
demonstrate how the merge sort algorithm works with an example before describing it in generality.
In general, a merge sort proceeds by iteratively splitting lists into two sub lists of equal length (or
where one sub list has one more element than the other) until each sub list contains one element.
This succession of sub lists can be represented by a balanced binary tree. The procedure continues
by successively merging pairs of lists, where both lists are in increasing order, into a larger list with
elements in increasing order, until the original list is put into increasing order. The succession of
merged lists can be represented by a balanced binary tree.
b) Use the merge sort algorithm to put the list 4, 10, 1, 5, 3, 8, 7, 2, 6, 9 in increasing order.
b) We split the list into the two halves: 4, 10, 1, 5, 3 and 8, 7, 2, 6, 9. We then merge sort
each half by applying this algorithm recursively and merging the results. For the first half, for
example, this means splitting 4, 10, 1, 5, 3 into the two halves 4, 10, 1 and 5, 3, recursively
sorting each half, and merging. For the second half of this, for example, it means splitting into
5 and 3, recursively sorting each half, and merging. Since these two halves are already sorted,
we just merge, into the sorted list 3, 5. Similarly, we will get 1, 4, 10 for the result of merge sort
applied to 4, 10, 1. When we merge 1, 4, 10 and 3, 5, we get 1, 3, 4, 5, 10. Finally, we merge this
786
with the sorted second half, 2, 6, 7, 8, 9, to obtain the completely sorted list 1, 2, 3, 4, 5, 6, 7, 8, 9,
10.
c) Give a big-O estimate for the number of comparisons used by the merge sort.
LEMMA 1 Two sorted lists with m elements and n elements can be merged into a sorted list using no
o e tha + − o pa iso s.
THEOREM 1 The number of comparisons needed to merge sort a list with n elements is O(n log n).
Q14. a) Does testing a computer program to see whether it produces the correct output for certain
input values verify that the program always produces the correct output?
a) no
b) Does showing that a computer program is partially correct with respect to an initial
asse tio a d a fi al asse tio e if that the p og a al a s p odu es the o e t output? If ot,
what else is needed?
b) No-you also need to show that it halts for all inputs, and the initial and final assertions
for which you provide a proof of partial correctness need to be appropriate ones (i.e., relevant to
the question of whether the program produces the correct output).
15. What techniques can you use to show that a long computer program is partially correct with
respect to a i itial asse tio a d a fi al asse tio ?
See the rules displayed in Section 5.5.
Rules of Inference
A useful rule of inference proves that a program is correct by splitting the program into a sequence
of subprograms and then showing that each subprogram is correct. Suppose that the programS is
split into subprograms S1 and S2.Write S = S1; S2 to indicate that S is made up of S1 followed by S2.
“uppose that the o e t ess of “ ith espe t to the i itial asse tio p a d fi al asse tio , a d
the correct ess of “ ith espe t to the i itial asse tio a d the fi al asse tio , ha e ee
established. It follows that if p is true and S1 is executed and terminates, then q is true; and if q is
true, and S2 executes and terminates, then r is true. Thus, if p is true and S = S1; S2 is executed and
terminates, then r is true. This rule of inference, called the composition rule, can be stated as
p{S1}q
q{S2}r
∴ p{S1; S2}r.
This rule of inference will be used later in this section. Next, some rules of inference for program
segments involving conditional statements and loops will be given. Because programs can be split
into segments for proofs of correctness, this will let us verify many different programs.
Q16. What is a loop invariant? How is a loop invariant used?
while condition
S
note that S is repeatedly executed until condition becomes false. An assertion that remains true
each time S is executed must be chosen. Such an assertion is called a loop invariant. In other words,
p is a loop invariant if (p condition){S}p is true.
Example :
i := 1
factorial := 1
while i<n
i := i + 1
factorial := factorial · i
786
Page : 439
Q . E plai ho the su a d p odu t ules a e used to fi d the u e of it st i gs ith a
length not exceeding 10.
1 + 2 + 2. 2 + 2. 2. 2 + ... + 210
= 2047
Q . E plai ho to fi d the u e of it st i gs of le gth ot e eedi g that ha e at least o e
0 bit.
Subtract 11 from the answer to the previous review question, since >., 1, 11, ... , 11 ... 1 are
the bit strings that do not have at least one 0 bit.
Q3. a Ho a the p odu t ule e used to fi d the u e of fu tio s f o a set ith
elements to a set with n elements?
a) See Example 6 in Section 6.1.
example 6 : Counting Functions How many functions are there from a set with m elements to a set
with
n elements?
Solution: A function corresponds to a choice of one of the n elements in the codomain for each of
The m elements in the domain. Hence, by the product rule there are n · n · ··· · n = nm
functions from
a set with m elements to one with n elements. For example, there are 53
= 125 different functions
f o a set ith th ee ele e ts to a set ith fi e ele e ts. ▲
b) Ho a fu tio s a e the e f o a set ith fi e ele e ts to a set ith 10 elements?
b) 105
Ho a the p odu t ule e used to fi d the u e of o e-to-one functions from a set with
m elements to a set with n elements?
c) See Example 7 in Section 6.1.
example 7 : Counting One-to-One Functions How many one-to-one functions are there from a set
with m elements to one with n elements?
Solution: First note that when m>n there are no one-to-one functions from a set with m elements to
a set ith ele e ts. No let . “uppose the ele e ts i the do ai a e a ,a ,...,am. There
are n ways to choose the value of the function at a1. Because the function is one-to-one, the value
of the fu tio at a a e pi ked i − a s e ause the alue used fo a a ot e used
again). In general, the value of the function at ak a e hose i − k + a s. B the p odu t
ule, the e a e − − ··· − + o e-to-one functions from a set with m elements to one
with n elements. For example, there are 5 · 4 · 3 = 60 one-to-one functions from a set with three
ele e ts to a set ith fi e ele e ts. ▲
d) How many one-to-o e fu tio s a e the e f o a set ith fi e ele e ts to a set ith
elements?
d) 10·9·8·7·6
e Ho a o to fu tio s a e the e f o a set ith fi e ele e ts to a set ith
elements?
e) 0
. Ho a ou fi d the u e of possi le out o es of a pla off et ee t o tea s he e the
first team that wins four games wins the playoff?
with a tree diagram; see Example 22 in Section 6.1 (extended to larger tree)
EXAMPLE 22
A pla off et ee t o tea s o sists of at ost fi e ga es. The fi st tea that i s th ee ga es
wins the playoff. In how many different ways can the playoff occur?
786
Solution: The tree diagram in Figure 3 displays all the ways the playoff can proceed, with the winner
of each game shown. We see that there are 20 different ways for the playoff to occur. ▲
. Ho a ou fi d the u e of it st i gs of le gth te that eithe egi ith o e d ith
010?
Using the inclusion-exclusion principle. we get 27
+ 27
- 24
; see Example 18 in Section 6.1.
EXAMPLE 18 How many bit strings of length eight either start with a 1 bit or end with the two bits
00? Solution: We can construct a bit string of length eight that either starts with a 1 bit or ends with
the two bits 00, by constructing a bit string of length eight beginning with a 1 bit or by constructing a
bit string of length eight that ends with the two bits 00. We can construct a bit string of length eight
that begins witha1in27 = 128 way
the number of bit strings of length eight that begin witha1orend with a 00, which equals the number
of ways to construct a bit string of length eight that begins witha1or that ends with 00, equals 128 +
− = .
17‫دی‬ ‫درس‬ ‫ليکچر‬
Q6. a) State the pigeonhole principle.
Introduction
“uppose that a flo k of pigeo s flies i to a set of pigeo holes to oost. Be ause the e a e
pigeons but only 19 pigeonholes, a least one of these 19 pigeonholes must have at least two pigeons
in it. To see why this is true, note that if each pigeonhole had at most one pigeon in it, at most 19
pigeons, one per hole, could be accommodated. This illustrates a general principle called the
pigeonhole principle, which states that if there are more pigeons than pigeonholes, then there must
be at least one pigeonhole with at least two pigeons in it (see Figure 1). Of course, this principle
applies to other objects besides pigeons and pigeonholes.
THEOREM 1 THE PIGEONHOLE PRINCIPLE If k is a positive integer and k + 1 or more objects
are placed into k boxes, then there is at least one box containing two or more of the objects.
17 lecture look
b) Explain how the pigeonhole principle can be used to show that among any 11 integers, at
least two must have the same last digit.
b) 11 pigeons, 10 holes (digits)
Q7. a) State the generalized pigeonhole principle.
The pigeonhole principle states that there must be at least two objects in the same box when there
are more objects than boxes. However, even more can be said when the number of objects exceeds
a multiple of the number of boxes. For instance, among any set of 21 decimal digits there must be 3
that are the same. This follows because when 21 objects are distributed into 10 boxes, one box must
have more than 2 objects.
786
b) Explain how the generalized pigeonhole principle can be used to show that among any 91
integers, there are at least ten that end with the same digit.
b)N=91,k=10
Q8. a) What is the difference between an r-combination and an r-permutation of a set with n
elements?
a) Permutations are ordered arrangements; combinations are unordered (or just arbitrarily
ordered for convenience) selections
b) Derive an equation that relates the number of r-combinations and the number of r-
permutations of a set with n elements.
b) P(n,r) = C(n.r) · r! (see the proof of Theorem 2 in Section 6.3)
786
b) How many ways are there to select six students from a class of 25 to serve on a
committee?
c) C(25, 6)
c) How many ways are there to select six students from a class of 25 to hold six different
executive positions on a committee?
d) P(25, 6)
Q9.
a What is Pas al s t ia gle?
786
a) See pp. 418-419
419 ‫غواړي‬ ‫کتل‬ ‫صفحه‬
This t ia gle is k o as Pas al’s t ia gle. Pas al’s ide tit sho s that he t o adja e t i o ial
oeffi ie ts i this t ia gle a e added, the i o ial oeffi ie t i the e t o et ee these t o
oeffi ie ts is p odu ed
Ho a a o of Pas al s t ia gle e p odu ed f o the o e a o e it?
b) by adding the two numbers above each number in the new row
Q10. What is meant by a combinatorial proof of an identity? How is such a proof different from an
algebraic one?
A combinatorial proof is a proof of an algebraic identity that shows that both sides count the
same thing (in some application). An algebraic proof is totally different-it shows that the two sides
are equal by doing formal manipulations with the unknowns. with no reference to what the
expressions might mean in an application.
Q . E plai ho to p o e Pas al s ide tit usi g a o i atorial argument.
See p. 418.
786
12.
a) State the binomial theorem.
a) See p. 416
786
b) Explain how to prove the binomial theorem using a combinatorial argument.
b) See p. 416
Fi d the oeffi ie t of 100
y101
in the expansion of (2x + 5y)201
.
c) 2100
.5101
C (201, 101)
Q13.
a E plai ho to fi d a fo ula fo the u e of a s to sele t o je ts f o o je ts
when repetition is allowed and order does not matter.
a) See Theorem 2 in Section 6.5
786
Ho a a s a e the e to sele t a doze o je ts f o a o g o je ts of fi e diffe e t t pes if
objects of the same type are indistinguishable?
b) C(5 + 12 - 1, 12)
Ho a a s a e the e to sele t a doze o je ts f o these fi e diffe e t types if there must
e at least th ee o je ts of the fi st t pe?
c) C (5 + 9 - 1, 9)
d Ho a a s a e the e to sele t a doze o je ts f o these fi e diffe e t t pes if the e
a ot e o e tha fou o je ts of the fi st t pe?
d) C (5 + 12 -1.12) - C(5 + 7 - 1. 7)
e Ho a a s a e the e to sele t a doze o je ts f o these fi e diffe e t t pes if the e
ust e at least t o o je ts of the fi st t pe, ut o o e tha th ee o je ts of the se o d t pe?
e) C (5 + 10 - 1, 10) - C(5 + 6 - 1, 6)
14.
a) Let n and r be positive integers. Explain why the number of solutions of the equation x1 + x2
+···+ xn = r, where xi is a nonnegative integer for i = 1, 2, 3,...,n, equals the number of r-
combinations of a set with n elements.
a) See Example 5 in Section 6.5.
b) How many solutions in nonnegative integers are there to the equation x1 + x2 + x3 + x4 = 17?
b) C( 4 + 17 - 1, 17)
c) How many solutions in positive integers are there to the equation in part (b)?
c) C(4 + 13 - 1, 13) (see Exercise 15a in Section 6.5)
15. How many solutions are there to the equation x1 + x2 + x3 + x4 + x5 = 21, where xi , i = 1, 2, 3, 4,
5, is a nonnegative integer such that
786
a ?
i fo i = , , , , ?
?
d , < , a d ?
15. a) 10,626 b) 1,365 c) 11,649 d) 106
Q15. a) Derive a formula for the number of permutations of n objects of k different types, where
there are n1 indistinguishable objects of type one, n2 indistinguishable objects of type two,..., and
nk indistinguishable objects of type k.
a) See Theorem 3 in Section 6.5.
b) How many ways are there to order the letters of the word INDISCREETNESS?
b) 14!/(2!2!1!3!1!1!3!1!)
Q16. Describe an algorithm for generating all the permutations of the set of the n smallest positive
integers.
16. See pp. 435-436.‫غواړې‬ ‫کتل‬
Q . a Ho a a s a e the e to deal ha ds of fi e a ds to si pla e s f o a sta da d -
card deck?
a) C(52, 5) · C(47, 5) · C(42, 5) · C(37, 5) · C(32, 5) · C(27, 5)
b) How many ways are there to distribute n distinguishable objects into k distinguishable boxes so
that ni objects are placed in box i ?
b) See Theorem 4 in Section 6.5
786
Q18. Describe an algorithm for generating all the combinations of the set of the n smallest positive
integers.
See pp. 437-438
EXAMPLE 4 Find the next bit string after 10 0010 0111.
Solution: The fi st it f o the ight that is ota isthe fou th it f o the ight. Cha ge this bit to a 1
and change all the following bits to 0s. This produces the next larger bit string, 10 0010 1000
‫غواړې‬ ‫کتل‬
Page : 495
Q . a Defi e the p o a ilit of a e e t he all out o es a e e uall likel .
a) See p. 446.
786
b) What is the probability that you select the six winning numbers in a lottery if the six different
i i g u e s a e sele ted f o the fi st positi e i tege s?
b) 1/C(50, 6)
Q . a What o ditio s should e et the p o a ilities assig ed to the out o es f o a fi ite
sample space?
b) What probabilities should be assigned to the outcome of heads and the outcome of tails if
heads comes up three times as often as tails?
b) p(H) = 3/4, p(T) = ¼
786
Q . a Defi e the o ditio al p o a ilit of a e e t E gi e a e e t F. a) See p. 456
b) Suppose E is the event that when a die is rolled it comes up an even number, and F is the
event that when a die is rolled it comes up 1, 2, or 3.What is the probability of F given E?
b) 1/3
Q4. a) When are two events E and F independent?
a) See p. 457
The e e ts E a d F a e i depe de t if a d o l if p E ∩ F = p E p F .
EXAMPLE 5 Suppose E is the event that a randomly generated bit string of length four begins with a
1 and F is the event that this bit string contains an even number of 1s. Are E and F independent, if
the 16 bit strings of length four are equally likely?
786
Solution: There are eight bit strings of length four that begin with a one: 1000, 1001, 1010, 1011,
1100, 1101, 1110, and 1111. There are also eight bit strings of length four that contain an even
number of ones: 0000, 0011, 0101, 0110, 1001, 1010, 1100, 1111. Because there are 16 bit strings of
length four, it follows that p(E) = p(F) = 8/16 = 1/2.
Be ause E ∩ F ={ , , , }, e see that p E ∩ F = / = / .
Because p E ∩ F = / = / / = p E p F , we conclude that E and F are independent
b) Suppose E is the event that an even number appears when a fair die is rolled, and F is the event
that a 5 or 6 comes up. Are E and F independent?
b) yes
Q5. a) What is a random variable?
a) See p. 460
b) What are the possible values assigned by the random variable X that assigns to a roll of two
dice the larger number that appears on the two dice?
b) 1, 2, 3, 4, 5, 6
Q . a Defi e the e pe ted alue of a random variable X.
786
b) What is the expected value of the random variable X that assigns to a roll of two dice the
larger number that appears on the two dice?
Q7. a) Explain how the average- ase o putatio al o ple it of a algo ith , ith finitely many
possible input values, can be interpreted as an expected value.
a) See p. 482.
786
b) What is the average-case computational complexity of the linear search algorithm, if the
probability that the element for which we search is in the list is 1/3, and it is equally likely that this
element is any of the n elements in the list?
b) (5n + 6)/3 (see Example 8 in Section 7.4)
Q8. a) What is meant by a Bernoulli trial?
a) See p. 458
b) What is the probability of k successes in n independent Bernoulli trials?
b) See Theorem 2 in Section 7.2
786
c) What is the expected value of the number of successes in n independent Bernoulli trials?
c) See Theorem 2 in Section 7.4
786
Q9. a) What does the linearity of expectations of random variables mean?
a) See p. 480.
786
Ho a the li ea it of e pe tatio s help us fi d the e pe ted u e of people ho e ei e
the correct hat when a hatcheck person returns hats at random?
b) See Example 6 in Section 7.4.
Q10. a) How can probability be used to solve a decision problem, if a small probability of error is
acceptable?
a) See the discussion of Monte Carlo algorithms on p. 463
786
b) How can we quickly determine whether a positive integer is prime, if we are willing to accept a
small probability of making an error?
b) See Example 16 in Section 7.2.
786
Q . State Ba es theo e a d use it to fi d p F | E if p E | F = / , p E | F = / , a d p F = / ,
where E and F are events from a sample space S.
786
Q12. a) What does it mean to say that a random variable has ageometric distribution with
parameter p?
a) See pp. 484-485
786
786
b) What is the mean of a geometric distribution with parameter p?
b) See Theorem 4 in Section 7.4.
‫ده‬ ‫قضيه‬ ‫څلورمه‬ ‫پورته‬ ‫دغه‬
Q13. a) What is the variance of a random variable?
786
b) What is the variance of a Bernoulli trial with probability p of success?
b) See Example 14 in Section 7.4.
Q14. a) What is the variance of the sum of n independent random variables?
786
b) What is the variance of the number of successes when n independent Bernoulli trials, each with
probability p of success, are carried out?
b) See Example 18 in Section 7.4.
‫پورته‬ ‫دغه‬ 18 ‫دی‬ ‫ل‬ ‫مث‬
Q . What does Che she s i e ualit tell us a out the probability that a random variable
de iates f o its ea o e tha a spe ified a ou t? See p. 491.
786
Special Thanks from Azizullah ‘Mahjoor’ that help me for solving these Question
Prepared by Samiullah ‘Yousafi’
Solved by Samiullah Yousafi & ‘Azizullah Mahjoor’
Students of Kandahar Computer Science Faculty
1395-02-27
Monday, May-16-2016

More Related Content

Similar to Answers Of Discrete Mathematics

Sets functions-sequences-exercises
Sets functions-sequences-exercisesSets functions-sequences-exercises
Sets functions-sequences-exercisesRoshayu Mohamad
 
Ch1 sets and_logic(1)
Ch1 sets and_logic(1)Ch1 sets and_logic(1)
Ch1 sets and_logic(1)Kwonpyo Ko
 
CMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set OperationsCMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set Operationsallyn joy calcaben
 
module 1Final flat FLAT Notes-1-101.pptx
module 1Final  flat FLAT Notes-1-101.pptxmodule 1Final  flat FLAT Notes-1-101.pptx
module 1Final flat FLAT Notes-1-101.pptxSrinivasRedyySarviga
 
Final maths presentation on sets
Final maths presentation on setsFinal maths presentation on sets
Final maths presentation on setsRahul Avicii
 
mathematical sets.pdf
mathematical sets.pdfmathematical sets.pdf
mathematical sets.pdfJihudumie.Com
 
Bba i-bm-u-1.2 set theory -
Bba i-bm-u-1.2 set theory  - Bba i-bm-u-1.2 set theory  -
Bba i-bm-u-1.2 set theory - Rai University
 
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...7anantsharma7
 
Definationofset
DefinationofsetDefinationofset
DefinationofsetJoy Saha
 
Sets in Maths (Complete Topic)
Sets in Maths (Complete Topic)Sets in Maths (Complete Topic)
Sets in Maths (Complete Topic)Manik Bhola
 
20200911-XI-Maths-Sets-2 of 2-Ppt.pdf
20200911-XI-Maths-Sets-2 of 2-Ppt.pdf20200911-XI-Maths-Sets-2 of 2-Ppt.pdf
20200911-XI-Maths-Sets-2 of 2-Ppt.pdfMridulDhamija
 
SETS - Vedantu.pdf
SETS - Vedantu.pdfSETS - Vedantu.pdf
SETS - Vedantu.pdfAneeshRenu
 

Similar to Answers Of Discrete Mathematics (20)

Sets functions-sequences-exercises
Sets functions-sequences-exercisesSets functions-sequences-exercises
Sets functions-sequences-exercises
 
Sets.pdf
Sets.pdfSets.pdf
Sets.pdf
 
Ch1 sets and_logic(1)
Ch1 sets and_logic(1)Ch1 sets and_logic(1)
Ch1 sets and_logic(1)
 
CMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set OperationsCMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set Operations
 
module 1Final flat FLAT Notes-1-101.pptx
module 1Final  flat FLAT Notes-1-101.pptxmodule 1Final  flat FLAT Notes-1-101.pptx
module 1Final flat FLAT Notes-1-101.pptx
 
Final maths presentation on sets
Final maths presentation on setsFinal maths presentation on sets
Final maths presentation on sets
 
mathematical sets.pdf
mathematical sets.pdfmathematical sets.pdf
mathematical sets.pdf
 
Sets
SetsSets
Sets
 
SETS
SETSSETS
SETS
 
Bba i-bm-u-1.2 set theory -
Bba i-bm-u-1.2 set theory  - Bba i-bm-u-1.2 set theory  -
Bba i-bm-u-1.2 set theory -
 
SET THEORY
SET THEORYSET THEORY
SET THEORY
 
Finite Maths Problems
Finite Maths ProblemsFinite Maths Problems
Finite Maths Problems
 
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
 
Sets
SetsSets
Sets
 
Chpt 2-sets v.3
Chpt 2-sets v.3Chpt 2-sets v.3
Chpt 2-sets v.3
 
Definationofset
DefinationofsetDefinationofset
Definationofset
 
6.1_set.pptx
6.1_set.pptx6.1_set.pptx
6.1_set.pptx
 
Sets in Maths (Complete Topic)
Sets in Maths (Complete Topic)Sets in Maths (Complete Topic)
Sets in Maths (Complete Topic)
 
20200911-XI-Maths-Sets-2 of 2-Ppt.pdf
20200911-XI-Maths-Sets-2 of 2-Ppt.pdf20200911-XI-Maths-Sets-2 of 2-Ppt.pdf
20200911-XI-Maths-Sets-2 of 2-Ppt.pdf
 
SETS - Vedantu.pdf
SETS - Vedantu.pdfSETS - Vedantu.pdf
SETS - Vedantu.pdf
 

More from Sabrina Green

There Are Several Advantages You C
There Are Several Advantages You CThere Are Several Advantages You C
There Are Several Advantages You CSabrina Green
 
Printable Primary Writing Paper - Printable World Ho
Printable Primary Writing Paper - Printable World HoPrintable Primary Writing Paper - Printable World Ho
Printable Primary Writing Paper - Printable World HoSabrina Green
 
Leather Writing Case With Writing Paper And Envelopes
Leather Writing Case With Writing Paper And EnvelopesLeather Writing Case With Writing Paper And Envelopes
Leather Writing Case With Writing Paper And EnvelopesSabrina Green
 
Reflective Essay - Grade B - Reflective Essay Introducti
Reflective Essay - Grade B - Reflective Essay IntroductiReflective Essay - Grade B - Reflective Essay Introducti
Reflective Essay - Grade B - Reflective Essay IntroductiSabrina Green
 
Piece Of Paper With Word Anxiety. Black And White S
Piece Of Paper With Word Anxiety. Black And White SPiece Of Paper With Word Anxiety. Black And White S
Piece Of Paper With Word Anxiety. Black And White SSabrina Green
 
J 176 Media Fluency For The Digital Age Example Of A O
J 176 Media Fluency For The Digital Age Example Of A OJ 176 Media Fluency For The Digital Age Example Of A O
J 176 Media Fluency For The Digital Age Example Of A OSabrina Green
 
FROG STREET PRESS FST6541 SMART START
FROG STREET PRESS FST6541 SMART STARTFROG STREET PRESS FST6541 SMART START
FROG STREET PRESS FST6541 SMART STARTSabrina Green
 
Essay Writing Service In Australia
Essay Writing Service In AustraliaEssay Writing Service In Australia
Essay Writing Service In AustraliaSabrina Green
 
Five Paragraph Essay Graphic Organizer In 2023
Five Paragraph Essay Graphic Organizer In 2023Five Paragraph Essay Graphic Organizer In 2023
Five Paragraph Essay Graphic Organizer In 2023Sabrina Green
 
Essential Features Of A Good Term Paper Writing Service Provider
Essential Features Of A Good Term Paper Writing Service ProviderEssential Features Of A Good Term Paper Writing Service Provider
Essential Features Of A Good Term Paper Writing Service ProviderSabrina Green
 
How To Write A College Research Paper Step By Ste
How To Write A College Research Paper Step By SteHow To Write A College Research Paper Step By Ste
How To Write A College Research Paper Step By SteSabrina Green
 
Essay My Teacher My Role Model - Pg
Essay My Teacher My Role Model - PgEssay My Teacher My Role Model - Pg
Essay My Teacher My Role Model - PgSabrina Green
 
Best College Essay Writing Service - The Writing Center.
Best College Essay Writing Service - The Writing Center.Best College Essay Writing Service - The Writing Center.
Best College Essay Writing Service - The Writing Center.Sabrina Green
 
Rutgers Admission Essay Help Essay Online Writers
Rutgers Admission Essay Help Essay Online WritersRutgers Admission Essay Help Essay Online Writers
Rutgers Admission Essay Help Essay Online WritersSabrina Green
 
How To Write An Essay - English Learn Site
How To Write An Essay - English Learn SiteHow To Write An Essay - English Learn Site
How To Write An Essay - English Learn SiteSabrina Green
 
I Need Someone To Write An Essay For Me
I Need Someone To Write An Essay For MeI Need Someone To Write An Essay For Me
I Need Someone To Write An Essay For MeSabrina Green
 
How To Properly Write A Bibliography
How To Properly Write A BibliographyHow To Properly Write A Bibliography
How To Properly Write A BibliographySabrina Green
 
Example Of An Autobiography That Will Point Your Writing I
Example Of An Autobiography That Will Point Your Writing IExample Of An Autobiography That Will Point Your Writing I
Example Of An Autobiography That Will Point Your Writing ISabrina Green
 
(PDF) Steps For Writing A Term P
(PDF) Steps For Writing A Term P(PDF) Steps For Writing A Term P
(PDF) Steps For Writing A Term PSabrina Green
 

More from Sabrina Green (20)

There Are Several Advantages You C
There Are Several Advantages You CThere Are Several Advantages You C
There Are Several Advantages You C
 
Printable Primary Writing Paper - Printable World Ho
Printable Primary Writing Paper - Printable World HoPrintable Primary Writing Paper - Printable World Ho
Printable Primary Writing Paper - Printable World Ho
 
Leather Writing Case With Writing Paper And Envelopes
Leather Writing Case With Writing Paper And EnvelopesLeather Writing Case With Writing Paper And Envelopes
Leather Writing Case With Writing Paper And Envelopes
 
Reflective Essay - Grade B - Reflective Essay Introducti
Reflective Essay - Grade B - Reflective Essay IntroductiReflective Essay - Grade B - Reflective Essay Introducti
Reflective Essay - Grade B - Reflective Essay Introducti
 
Piece Of Paper With Word Anxiety. Black And White S
Piece Of Paper With Word Anxiety. Black And White SPiece Of Paper With Word Anxiety. Black And White S
Piece Of Paper With Word Anxiety. Black And White S
 
J 176 Media Fluency For The Digital Age Example Of A O
J 176 Media Fluency For The Digital Age Example Of A OJ 176 Media Fluency For The Digital Age Example Of A O
J 176 Media Fluency For The Digital Age Example Of A O
 
Cat Writing Paper
Cat Writing PaperCat Writing Paper
Cat Writing Paper
 
FROG STREET PRESS FST6541 SMART START
FROG STREET PRESS FST6541 SMART STARTFROG STREET PRESS FST6541 SMART START
FROG STREET PRESS FST6541 SMART START
 
Essay Writing Service In Australia
Essay Writing Service In AustraliaEssay Writing Service In Australia
Essay Writing Service In Australia
 
Five Paragraph Essay Graphic Organizer In 2023
Five Paragraph Essay Graphic Organizer In 2023Five Paragraph Essay Graphic Organizer In 2023
Five Paragraph Essay Graphic Organizer In 2023
 
Essential Features Of A Good Term Paper Writing Service Provider
Essential Features Of A Good Term Paper Writing Service ProviderEssential Features Of A Good Term Paper Writing Service Provider
Essential Features Of A Good Term Paper Writing Service Provider
 
How To Write A College Research Paper Step By Ste
How To Write A College Research Paper Step By SteHow To Write A College Research Paper Step By Ste
How To Write A College Research Paper Step By Ste
 
Essay My Teacher My Role Model - Pg
Essay My Teacher My Role Model - PgEssay My Teacher My Role Model - Pg
Essay My Teacher My Role Model - Pg
 
Best College Essay Writing Service - The Writing Center.
Best College Essay Writing Service - The Writing Center.Best College Essay Writing Service - The Writing Center.
Best College Essay Writing Service - The Writing Center.
 
Rutgers Admission Essay Help Essay Online Writers
Rutgers Admission Essay Help Essay Online WritersRutgers Admission Essay Help Essay Online Writers
Rutgers Admission Essay Help Essay Online Writers
 
How To Write An Essay - English Learn Site
How To Write An Essay - English Learn SiteHow To Write An Essay - English Learn Site
How To Write An Essay - English Learn Site
 
I Need Someone To Write An Essay For Me
I Need Someone To Write An Essay For MeI Need Someone To Write An Essay For Me
I Need Someone To Write An Essay For Me
 
How To Properly Write A Bibliography
How To Properly Write A BibliographyHow To Properly Write A Bibliography
How To Properly Write A Bibliography
 
Example Of An Autobiography That Will Point Your Writing I
Example Of An Autobiography That Will Point Your Writing IExample Of An Autobiography That Will Point Your Writing I
Example Of An Autobiography That Will Point Your Writing I
 
(PDF) Steps For Writing A Term P
(PDF) Steps For Writing A Term P(PDF) Steps For Writing A Term P
(PDF) Steps For Writing A Term P
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Answers Of Discrete Mathematics

  • 1. 786 Answers of Discrete_Mathematics Page No (186) Q1. Explain what it means for one set to be a subset of another set. How do you prove that one set is a subset of another set? A1: The set A is a subset of B if and only if every element of A is also an element of B. We use the notation A ⊆ B to indicate that A is a subset of the set B. We see that A ⊆ B if and only if the quantification ∀x(x ∈ A → x ∈ B) is true. Note that to show that A is not a subset of B we need only find one element x ∈ A with x /∈ B. Such an x is a counterexample to the claim that x ∈ A implies x ∈ B. We have these useful rules for determining whether one set is a subset of another: Showing that A is a Subset of B. To show that A ⊆ B, show that if x belongs to A then x also belongs to B. Showing that A is Not a Subset of B. To show that A _⊆ B, find a single x ∈ A such that x _∈B. Q2. What is the empty set? Show that the empty set is a subset of every set. A2: The empty set is the set with no elements. It satisfies the definition of being a subset of every set vacuously. Q . a Defi e |S|, the a di alit of the set S. b) Give a formula for |A ∪ B|, where A and B are sets. A3: a) Showing Two Sets are Equal. To show that two sets A and B are equal, show that A ⊆ B and B ⊆A. b) Sets may have other sets as members. For instance, we have the sets A = {∅, {a}, {b}, {a, b}} and B = {x | x is a subset of the set {a, b}}. Note that these two sets are equal, that is, A = B. Also note that {a} ∈ A, but a /∈ A. Q4. a Defi e the po e set of a set S. b) When is the empty set in the power set of a set S? c) How many elements does the power set of a set S with n elements have? A4: a) Given a set S, the power set of S is the set of all subsets of the set S. The power set of S is denoted by P(S). b) Always c) 2n Q5. a Defi e the u io , i te se tio , diffe e e, a d s et i diffe e e of t o sets. b) What are the union, intersection, difference, and symmetric difference of the set of positive integers and the set of odd integers? A5:a) Union: Let A and B be sets. The union of the sets A and B, denoted by A ∪ B, is the set that contains those elements that are either in A or in B, or in both. An element x belongs to the union of the sets A and B if and only if x belongs to A or x belongs to B. This tells us that (A ∪ B = {x | x ∈ A x ∈ B}). E.g. The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, {1, 3, 5} ∪ {1, 2, 3} = {1, 2, 3, 5}. Intersection: Let A and B be sets. The intersection of the sets A and B, denoted by A ∩ B, is the set containing those elements in both A and B. An element x belongs to the intersection of the sets A and B if and only if x belongs to A and x belongs to B. This tells us that (A ∩ B = {x | x ∈ A x ∈ B}). E.g. The intersection of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 3}; that is, {1, 3, 5} ∩ {1, 2, 3} = {1, 3}. b) Union: integers that are odd or positive, intersection: odd positive integers, difference: even positive integers, symmetric difference: even positive integers together with odd negative integers
  • 2. 786 Q6. a) Explain what it means for two sets to be equal. b) Describe as many of the ways as you can to show that two sets are equal. c) Show in at least two different ways that the sets A − B ∩ C a d A − B ∪ A − C a e e ual. A6: a) A= B = (A<:;;; B / B <:;;;A)= Vx(x EA+-+ x EB) b) If you want extra about this Question see book. Page no (129-132) TABLE Set Identities. Identity Name A ∩ U = A A ∪ ∅ = A Identity laws A ∪ U = U A∩∅ = ∅ Domination laws A ∪ A = A A ∩ A = A Idempotent laws (A) = A Complementation law A ∪ B = B ∪ A A ∩ B = B ∩ A Commutative laws A ∪ (B ∪ C) = (A ∪ B) ∪ C A ∩ (B ∩ C) = (A ∩ B) ∩ C Associative laws A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) Distributive laws A ∩ B = A ∪ B A ∪ B = A ∩ B De Mo ga ’s la s A ∪ (A ∩ B) = A A ∩ (A ∪ B) = A Absorption laws A ∪ A = U A ∩ A = ∅ Complement laws c) An B n C =An (Bu C) = (An B) u (An C) = (A- B) u (A - C); use Venn diagrams Q7. Explain the relationship between logical equivalences and set identities. A7: Underlying each set identity is a logical equivalence. These follow directly from the corresponding properties for the logical operations or and and. a) AU B = { x I x E A V x E B} = { x I x E B V x E A} = B U A b) An B = { x Ix EA/ x EB}= { x Ix EB / x EA}= B n A Q8. a Defi e the do ai , odo ai , a d a ge of a fu tio . b) Let f (n) be the function from the set of integers to the set of integers such that f (n) = n2 + 1. What are the domain, codomain, and range of this function? A8: a) Z, Z, z+ = N - {O} b) If f is a function from A to B, we say that A is the domain of f and B is the codomain of f. If f (a) = b, we say that b is the image of a and a is a preimage of b. The range, or image, of f is the set of all images of elements of A. Also, if f is a function from A to B, we say that f maps A to B. Q9. a) Define what it means for a function from the set of positive integers to the set of positive integers to be one-to-one. b) Define what it means for a function from the set of positive integers to the set of positive integers to be onto.
  • 3. 786 c) Give an example of a function from the set of positive integers to the set of positive integers that is both one-to-one and onto. d) Give an example of a function from the set of positive integers to the set of positive integers that is one-to-one but not onto. e) Give an example of a function from the set of positive integers to the set of positive integers that is not one-to-one but is onto. f ) Give an example of a function from the set of positive integers to the set of positive integers that is neither one-to-one nor onto. A9: a) A function f is said to be one-to-one, or an injunction, if and only if f (a) = f (b) implies that a = b for all a and b in the domain of f.A function is said to be injective if it is one-to-one. b) A function f from A to B is called onto, or a surjection, if and only if for every element b ∈ B there is an element a ∈ A with f (a) = b.A function f is called surjective if it is onto. Remark: A function f is onto if ∀y∃x(f (x) = y), where the domain for x is the domain of thefunction and the domain for y is the codomain of the function. E.g1: Let f be the function from {a, b, c, d} to {1, 2, 3} defined by f (a) = 3, f (b) = 2, f (c) = 1, and f (d) = 3. Is f an onto function? Solution: Because all three elements of the codomain are images of elements in the domain, we see that f is onto. This is illustrated in Figure 4. Note that if the codomain were {1, 2, 3,4}, then f would not be onto. E.g2: Is the function f (x) = x2 from the set of integers to the set of integers onto? Solution: The function f is not onto because there is no integer x with x2 = −1, for instance. c) f(n) = n d) f(n) = 2n e) f(n) = f n/21 f) f(n) = 42548 Q10. a) Define the inverse of a function. b) When does a function have an inverse? c) Does the function f (n) = 10 − n from the set of integers to the set of integers have an inverse? If so, what is it? A10: a) Let f be a one-to-one correspondence from the set A to the set B. The inverse function of f is the function that assigns to an element b belonging to B the unique element a in A such that f (a) =b. The inverse function of f is denoted by f−1. Hence, f −1 (b) = a when f (a) = b. (f-1 (b) =a= f (a) = b) b) when it is one-to-one and onto c) yes-itself Q11. a) Define the floor and ceiling functions from the set of real numbers to the set of integers. b) For which real numbers x is it true that _x_ = _x_? A11: a) The floor function assigns to the real number x the largest integer that is less than or equal to x. The value of the floor function at x is denoted by _x_. The ceiling function assigns to the real number x the smallest integer that is greater than or equal to x. The value of the ceiling function at x is denoted by _x_. Remark: The floor function is often also called the greatest integer function. It is often denoted by [x]. E.g: These are some values of the floor and ceiling functions: [1/2]= 0, [1/2]= 1, [-1/2]= -1, [-1/2]= 0, [3.1]= 3, [3.1]= 4, [7] = 7, [7] = 7 We display the graphs of the floor and ceiling functions in Figure 10. In Figure 10(a) we display the graph of the floor function _x_. Note that this function has the same value throughout the interval
  • 4. 786 [n, n + 1), namely n, and then it jumps up to n + 1 when x = n + 1. In Figure 10(b) we display the graph of the ceiling function _x_. Note that this function has the same value throughout the interval (n, n + 1], namely n + 1, and then jumps to n + 2 when x is a little larger than n + 1. The floor and ceiling functions are useful in a wide variety of applications, including those involving data storage and data transmission. E.g: Data stored on a computer disk or transmitted over a data network are usually represented as a string of bytes. Each byte is made up of 8 bits. How many bytes are required to encode 100 bits of data? Solution: To determine the number of bytes needed, we determine the smallest integer that is at least as large as the quotient when 100 is divided by 8, the number of bits in a byte. Consequently, [100/8] = [12.5] = 13 bytes are required. b) Integers Q12. Conjecture a formula for the terms of the sequence that begins 8, 14, 32, 86, 248 and find the next three terms of your sequence. A12: Hint: subtract 5 from each term and look at the resulting sequence. Q13. Suppose that an = an−1 − 5 for n = 1, 2, ... Find a formula for an. A13: The formula depends on the initial condition, namely the value of a0 . After that, each term is 5 less than the preceding term, so an = ao - 5n. Q14. What is the sum of the terms of the geometric progression a + ar +・ ・ ・+arn when r _= 1? A14: Q15. Show that the set of odd integers is countable. A15: Set up a one-to-one correspondence between the set of positive integers and the set of all odd integers, such as 1 ++ 1, 2 ++ 1, 3 ++ 3, 4 ++ 3, 5 ++ 5, 6 ++ 5, and so on. Answer of (232) number page Q1. a) Define the term algorithm. b) What are the different ways to describe algorithms? c) What is the difference between an algorithm for solving a problem and a computer program that solves this problem? A1: a) An algorithm is a finite sequence of precise instructions for performing a computation or for solving a problem. b) In English, In a computer language, In pseudocode c) An algorithm is more of an abstract idea-a method in theory that will solve a problem. A computer program is the implementation of that idea into a specific syntactically correct set of instructions that a real computer can use to solve the problem. It is rather like the difference between a dollar (a certain amount of money, capable in theory of purchasing a certain quantity of goods and services) and a dollar bill. Q2. a) Describe, using English, an algorithm for finding the largest integer in a list of n integers. b) Express this algorithm in pseudocode. c) How many comparisons does the algorithm use? A2: a) This algorithm first assigns the initial term of the sequence, a1, to the variable max. The fo loop is used to successively examine terms of the sequence. If a term is greater than the current value of max, it is assigned to be the new value of max. b) procedure max(a1, a2, . . . , an: integers) max := a1 for i := 2 to n if max < ai then max := ai return max{max is the largest element}
  • 5. 786 c) Solution: The number of comparisons will be used as the measure of the time complexity of the algorithm, because comparisons are the basic operations used. To find the maximum element of a set with n elements, listed in an arbitrary order, the temporary maximum is first set equal to the initial term in the list. Then, after a comparison i n has been done to determine that the end of the list has not yet been reached, the temporary maximum and second term are compared, updating the temporary maximum to the value of the second term if it is larger. This procedure is continued, using two additional comparisons for each term of the list—one i n, to determine that the end of the list has not been reached and another max < ai , to determine whether to update the temporary maximum. Because two comparisons are used for each of the second through the nth elements and one more comparison is used to exit the loop when i = n + 1, exactly 2(n − 1) + 1 = 2n − 1 comparisons are used whenever this algorithm is applied. Hence, the algorithm for finding the maximum of a set of n elements has time complexity _(n), measured in terms of the number of comparisons used. Note that for this algorithm the number of comparisons is independent of particular input of n numbers. Next, we will analyze the time complexity of searching algorithms 3. a) State the definition of the fact that f (n) is O(g(n)), where f (n) and g(n) are functions from the set of positive integers to the set of real numbers. b) Use the definition of the fact that f (n) is O (g (n)) directly to prove or disprove that n2 + 18n + 107 is O (n3). c) Use the definition of the fact n is O (g (n)) directly to prove or disprove that n3 is O (n2 + 18n + 107). A3: a) Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers.We say that f (x) is O(g(x)) if there are constants C and k such that |f (x)| C|g(x)| whenever x > k. [This is ead as f (x) is big-oh of g(x). ] b) n2 +l8n+107:::; n3 + n3 + n3 = 3n3 for all n > 107. c) n3 is not less than a constant times n2 + 18n + 107, since their ratio exceeds n3 / (3n2) = n/3 for all n > 107. Q4. List these functions so that each function is big-O of the next function in the list: (log n)3 , n3/1000000, √n,100n + 101, 3n , n!, 2n n2 . A4: (log n)3 , √n, l00n + 101, n3 /1000000, 2n n2 , 3n , n! Q5. a) How can you produce a big-O estimate for a function that is the sum of different terms where each term is the product of several functions? b) Give a big-O estimate for the function f (n) = (n! + 1)(2n + 1) + (nn−2 + 8nn−3) (n3 + 2n). For the function g in your estimate f (x) is O(g(x)) use a simple function of smallest possible order. A5: a) For the sum, take the largest term; for the product multiply the factors together. b) g(n) = nn-2 2n = (2n)n /n2 Q6. a) Define what the worst-case time complexity, average case time complexity, and best-case time complexity (in terms of comparisons) mean for an algorithm that finds the smallest integer in a list of n integers. b) What are the worst-case, average-case, and best-case time complexities, in terms of comparisons, of the algorithm that finds the smallest integer in a list of n integers by comparing each of the integers with the smallest integer found so far? A6: a) the largest, average, and smallest number of comparisons used by the algorithm before it stops, among all lists of n integers b) all are n - 1 Q7. a) Describe the linear search and binary search algorithm for finding an integer in a list of integers in increasing order. b) Compare the worst-case time complexities of these two algorithms.
  • 6. 786 c) Is one of these algorithms always faster than the other (measured in terms of comparisons)? A7: a) The linear search: The first algorithm that we will present is called the linear search, or sequential search, algorithm. The linear search algorithm begins by comparing x and a1. When x = a1, the solution is the location of a1, namely, 1. When x _= a1, compare x with a2. If x = a2, the solution is the location of a2, namely, 2. When x _= a2, compare x with a3. Continue this process, comparing x successively with each term of the list until a match is found, where the solution is the location of that term, unless no match occurs. If the entire list has been searched without locating x, the solution is 0. The pseudocode for the linear search algorithm is displayed as Algorithm 2. The linear search algorithm. procedure linear search(x: integer, a1, a2, . . . , an: distinct integers) i := 1 while (i n and x _= ai ) i := i + 1 if i n then location := i else location := 0 return location{location is the subscript of the term that equals x, or is 0 if x is not found} The binary search: We will now consider another searching algorithm. This algorithm can be used when the list has terms occurring in order of increasing size (for instance: if the terms are numbers, they are listed from smallest to largest; if they are words, they are listed in lexicographic, or alphabetic, order). This second searching algorithm is called the binary search algorithm. It proceeds by comparing the element to be located to the middle term of the list. The list is then split into two smaller sublists of the same size, or where one of these smaller lists has one fewer term than the other. The search continues by restricting the search to the appropriate sublist based on the comparison of the element to be located and the middle term. In Section 3.3, it will be shown that the binary search algorithm is much more efficient than the linear search algorithm. Example 3 demonstrates how a binary search works. E.g: To search for 19 in the list 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22, first split this list, which has 16 terms, into two smaller lists with eight terms each, namely, 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22. Then, compare 19 and the largest term in the first list. Because 10 < 19, the search for 19 can be restricted to the list containing the 9th through the 16th terms of the original list. Next, split this list, which has eight terms, into the two smaller lists of four terms each, namely, 12 13 15 16 18 19 20 22. Because 16 < 19 (comparing 19 with the largest term of the first list) the search is restricted to the second of these lists, which contains the 13th through the 16th terms of the original list. The list 18 19 20 22 is split into two lists, namely, 18 19 20 22. Because 19 is not greater than the largest term of the first of these two lists, which is also 19, the search is restricted to the first list: 18 19, which contains the 13th and 14th terms of the original list. Next, this list of two terms is split into two lists of one term each: 18 and 19. Because 18 < 19, the search is restricted to the second list: the list containing the 14th term of the list, which is 19. Now that the search has been narrowed down to one term, a comparison is made, and 19 is located as the 14th term in the original list. We now specify the steps of the binary search algorithm. To search for the integer x in the list a1, a2, . . . , an, where a1 < a2 < ・ ・ ・ < an, begin by comparing x with the middle term am of the list, where m = _(n + 1)/2_. (Recall that _x_ is the greatest integer not exceeding x.) If x > am, the search for x is restricted to the second half of the list, which is am+1, am+2, . . . , an. If x is not greater than am, the search for x is restricted to the first half of the list, which is a1, a2,…am.The search has now been restricted to a list with no more than _n/2_ elements. (Recall that [x] is the smallest integer greater than or equal to x.) Using the same procedure, compare x to the
  • 7. 786 middle term of the restricted list. Then restrict the search to the first or second half of the list. Repeat this process until a list with one term is obtained. Then determine whether this term is x. Pseudocode for the binary search algorithm is displayed as Algorithm 3. The binary search algorithm: procedure binary search (x: integer, a1, a2, . . . , an: increasing integers) i := 1{i is left endpoint of search interval} j := n {j is right endpoint of search interval} while i < j m := _(i + j)/2_ if x > am then i := m + 1 else j := m if x = ai then location := i else location := 0 return location{location is the subscript i of the term ai equal to x, or 0 if x is not found} Algorithm 3 proceeds by successively narrowing down the part of the sequence being searched. At any given stage only the terms from ai to aj are under consideration. In other words, i and j are the smallest and largest subscripts of the remaining terms, respectively. Algorithm 3 continues narrowing the part of the sequence being searched until only one term of the sequence remains. When this is done, a comparison is made to see whether this term equals x. b) The type of complexity analysis done in Example 2 is a worstcase analysis. By the worst-case performance of an algorithm, we mean the largest number of operations needed to solve the given problem using this algorithm on input of specified size. Worst-case analysis tells us how many operations an algorithm requires to guarantee that it will produce a solution. c) No-it depends on the lists involved. (However, the worst case complexity for binary search is always better than that for linear search for lists of any given size except for very short lists.) Q8. a) Describe the bubble sort algorithm. b) Use the bubble sort algorithm to sort the list 5, 2, 4, 1, 3. c) Give a big-O estimate for the number of comparisons used by the bubble sort. A8: a) Bubble Sort: The bubble sort is one of the simplest sorting algorithms, but not one of the most efficient. It puts a list into increasing order by successively comparing adjacent elements, interchanging them if they are in the wrong order. To carry out the bubble sort, we perform the basic operation, that is, interchanging a larger element with a smaller one following it, starting at the beginning of the list, for a full pass.We iterate this procedure until the sort is complete. Pseudocode for the bubble sort is given as Algorithm 4.We can imagine the elements in the list pla ed i a olu . I the u le so t, the s alle ele e ts u le to the top as the a e i te ha ged ith la ge ele e ts. The la ge ele e ts si k to the otto . This is illustrated in Example 4. E.g: Use the bubble sort to put 3, 2, 4, 1, 5 into increasing order. Note: Blue Color is for an interchange Red Color for pair in correct order Green Color is numbers in color guaranteed to be in correct order. For more information See book First Pass Second Pass Third Pass Forth Pass 3 2 2 2 2 2 2 2 1 1 2 3 3 3 3 3 1 1 2 2 4 4 4 1 1 1 3 3 3 3 1 1 1 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5
  • 8. 786 page no (197) b) On the first pass, the 5 bubbles down to the end, producing 2 4 1 3 5. On the next pass, the 4 bubbles down to the end, producing 213 4 5. On the next pass, the 1 and the 2 are swapped. No further changes are made on the fourth pass. c) The bubble sort described before Example 4 in Section 3.1 sorts a list by performing a sequence of passes through the list. During each pass the bubble sort successively compares adjacent elements, interchanging them if necessary. When the ith pass begins, the i − 1 largest elements are guaranteed to be in the correct positions. During this pass, n − i comparisons are used. Consequently, the total number of comparisons used by the bubble sort to order a list of n elements is (n − 1) + (n − 2) +・ ・ ・+2 + 1 = (n − 1)n/2 Note that the bubble sort always uses this many comparisons, because it continues even if the list becomes completely sorted at some intermediate step. Consequently, the bubble sort uses (n − 1)n/2 comparisons, so it has O(n2 ) worst-case complexity in terms of the number of comparisons used. Q9. a) Describe the insertion sort algorithm. b) Use the insertion sort algorithm to sort the list 2, 5, 1, 4, 3. c) Give a big-O estimate for the number of comparisons used by the insertion sort. A9: a) The insertion sort is a simple sorting algorithm, but it is usually not the most efficient. To sort a list with n elements, the insertion sort begins with the second element. The insertion sort compares this second element with the first element and inserts it before the first element if it does not exceed the first element and after the first element if it exceeds the first element. At this point, the first two elements are in the correct order. The third element is then compared with the first element, and if it is larger than the first element, it is compared with the second element; it is inserted into the correct position among the first three elements. In general, in the j th step of the insertion sort, the j th element of the list is inserted into the correct position in the list of the previously sorted j − 1 elements. To insert the j th element in the list, a linear search technique is used (see Exercise 43); the j th element is successively compared with the already sorted j − 1 elements at the start of the list until the first element that is not less than this element is found or until it has been compared with all j − 1 elements; the j th element is inserted in the correct position so that the first j elements are sorted. The algorithm continues until the last element is placed in the correct position relative to the already sorted list of the first n − 1 elements. The insertion sort is described in pseudocode in Algorithm 5. E.g: Use the insertion sort to put the elements of the list 3, 2, 4, 1, 5 in increasing order. Solution: The insertion sort first compares 2 and 3. Because 3 > 2, it places 2 in the first position, producing the list 2, 3, 4, 1, 5 (the sorted part of the list is shown in color). At this point, 2 and 3 are in the correct order. Next, it inserts the third element, 4, into the already sorted part of the list by making the comparisons 4 > 2 and 4 > 3. Because 4 > 3, 4 remains in the third position. At this point, the list is 2, 3, 4, 1, 5 and we know that the ordering of the first three elements is correct. Next, we find the correct place for the fourth element, 1, among the already sorted elements, 2, 3, 4. Because 1 < 2, we obtain the list 1, 2, 3, 4, 5. Finally, we insert 5 into the correct position by successively comparing it to 1, 2, 3, and 4. Because 5 > 4, it stays at the end of the list, producing the correct order for the entire list. Insertion Sort algorithm: procedure insertion sort(a1, a2, . . . , an: real numbers with n 2) for j := 2 to n i := 1 while aj > ai i := i + 1 m := aj
  • 9. 786 for k := 0 to j − i − 1 aj−k := aj−k−1 ai := m {a1, . . . , an is in increasing order} b) On the first pass, the 5 is inserted into its correct position relative to the 2, producing 2 5 14 3. On the next pass, the 1 is inserted into its correct position relative to 2 5, producing 1 2 5 4 3. On the next pass, the 4 is inserted into its correct position relative to 1 2 5, producing 1 2 4 5 3. On the final pass, the 3 is inserted, producing the sorted list. c) O(n2 ); E.g: What is the worst-case complexity of the insertion sort in terms of the number of comparisons made? Solution: The insertion sort (described in Section 3.1) inserts the j th element into the correct position among the first j − 1 elements that have already been put into the correct order. It does this by using a linear search technique, successively comparing the j th element with successive terms until a term that is greater than or equal to it is found or it compares aj with itself and stops because aj is not less than itself. Consequently, in the worst case, j comparisons are required to insert the j th element into the correct position. Therefore, the total number of comparisons used by the insertion sort to sort a list of n elements is 2 + 3+・ ・ ・+n = n(n + 1)/2 – 1 using the summation formula for the sum of consecutive integers in line 2 of Table 2 of Section 2.4 (and see Exercise 37(b) of Section 2.4), and noting that the first term, 1, is missing in this sum. Note that the insertion sort may use considerably fewer comparisons if the smaller elements started out at the end of the list. We conclude that the insertion sort has worst-case complexity O(n2). Q10. a) Explain the concept of a greedy algorithm. b) Provide an example of a greedy algorithm that produces an optimal solution and explain why it produces an optimal solution. c) Provide an example of a greedy algorithm that does not always produce an optimal solution and explain why it fails to do so. A10: a) Algorithms that ake hat see s to e the est hoi e at ea h step a e alled greedy algorithms. Once we know that a greedy algorithm finds a feasible solution, we need to determine whether it has fou d a opti al solutio . Note that e all the algo ith g eed whether or not it finds an optimal solution.) To do this, we either prove that the solution is optimal or we show that there is a counterexample where the algorithm yields a non optimal solution. ....See page NO (198) for extra details in Book b) Consider the problem of making n cents change with quarters, dimes, nickels, and pennies, and using the least total number of coins.We can devise a greedy algorithm for making change for n cents by making a locally optimal choice at each step; that is, at each step we choose the coin of the largest denomination possible to add to the pile of change without exceeding n cents. For example, to make change for 67 cents, we first select a quarter (leaving 42 cents).We next select a second quarter (leaving 17 cents), followed by a dime (leaving 7 cents), followed by a nickel (leaving 2 cents), followed by a penny (leaving 1 cent), followed by a penny. We display a greedy change-making algorithm for n cents, using any set of denominations of coins, as Algorithm 6. Algorithm of Greedy Algorithm: procedure change(c1, c2, . . . , cr : values of denominations of coins, where c1 > c2 > ・ ・ ・ > cr ; n: a positive integer)
  • 10. 786 for i := 1 to r di := 0 {di counts the coins of denomination ci used} while n ci di := di + 1 {add a coin of denomination ci} n := n − ci {di is the number of coins of denomination ci in the change for i = 1, 2, . . . , r} We have described a greedy algorithm for making change using any finite set of coins with denominations c1, c2, ..., cr . In the particular case where the four denominations are quarters dimes, nickels, and pennies, we have c1 = 25, c2 = 10, c3 = 5, and c4 = 1. For this case, we will show that this algorithm leads to an optimal solution in the sense that it uses the fewest coins possible. Before we embark on our proof, we show that there are sets of coins for which the greedy algorithm (Algorithm 6) does not necessarily produce change using the fewest coins possible. For example, if we have only quarters, dimes, and pennies (and no nickels) to use, the greedy algorithm would make change for 30 cents using six coins—a quarter and five pennies—whereas we could have used three coins, namely, three dimes. c) Use the greedy algorithm to make change using quarters, dimes, and pennies (but no nickels) for each of the amounts given in Exercise 53. For which of these amounts does the greedy algorithm use the fewest coins of these denominations possible? Solution: Two quarters, one dime, nine pennies. In page (S-20) question No(55) Q11. Define what it means for a problem to be tractable and what it means for a problem to be solvable. A11: A problem that is solvable using an algorithm with polynomial worst-case complexity is called tractable, because the expectation is that the algorithm will produce the solution to the problem for reasonably sized input in a relatively short time. However, if the polynomial in the big-_ estimate has high degree (such as degree 100) or if the coefficients are extremely large, the algorithm may take an extremely long time to solve the problem. Consequently, that a problem can be solved using an algorithm with polynomial worst-case time complexity is no guarantee that the problem can be solved in a reasonable amount of time for even relatively small input values. Fortunately, in practice, the degree and coefficients of polynomials in such estimates are often small. The situation is much worse for problems that cannot be solved using an algorithm with worst-case polynomial time complexity. Such problems are called intractable. Usually, but not always, an extremely large amount of time is required to solve the problem for the worst cases of even small input values. In practice, however, there are situations where an algorithm with a certain worst-case time complexity may be able to solve a problem much more quickly for most cases than for its worst case. When we are willing to allow that some, perhaps small, number of cases may not be solved in a reasonable amount of time, the average-case time complexity is a better measure of how long an algorithm takes to solve a problem. Many problems important in industry are thought to be intractable but can be practically solved for essentially all sets of input that arise in daily life. Another way that intractable problems are handled when they arise in practical applications is that instead of looking for exact solutions of a problem, approximate solutions are sought. It may be the case that fast algorithms exist for finding such approximate solutions, perhaps even with a guarantee that they do not differ by very much from an exact solution. Some problems even exist for which it can be shown that no algorithm exists for solving them. Such problems are called unsolvable (as opposed to solvable problems that can be solved using an algorithm). The first proof that there are unsolvable problems was provided by the great English mathematician and computer scientist Alan Turing when he showed that the halting problem is unsolvable. Recall that we proved that the halting problem is unsolvable in Section 3.1 A solvable problem is simply one that can be solved by an algorithm. The halting problem is proved on pp. 201-202 to be unsolvable. Page : 307
  • 11. 786 Q1.Find 210 div 17 and 210 mod 17. A1: Dividing 210 by 17 gives a quotient of 12 and a remainder of 6, which are the respective requested values. ÷ = ∗ + % = Q . a Defi e hat it ea s fo a a d to e o g ue t odulo . a) 7 | a - b Whi h pai s of the i tege s − ,− ,− ,− , , , a d a e o g ue t odulo ? b) 0 ≡ -7; -1 ≡ -8; 3 ≡ 17 ≡ -11 c) Sho that if a a d a e o g ue t odulo , the a + a d− + a e also o g ue t modulo 7. c) (10a + 13) - (-4b + 20) = 3(a - b) + 7(a + b - 1); note that 7 divides both terms Q . Sho that if a ≡ od a d ≡ d od , the a + ≡ + d od . A3: THEOREM 5 Let e a positi e i tege . If a ≡ od a d ≡ d od , the a + ≡ + d od a d a ≡ d od . Proof: We use a di e t p oof. Be ause a ≡ od a d ≡ d od , Theo e t are integers s and t with b = a + sm and d = c + tm. Hence, b + d = (a + sm) + (c + tm) = (a + c) + m(s + t) and bd = (a + sm)(c + tm) = ac + m(at + cs + stm). Hence, a + ≡ + d od a d a ≡ d od . E.g 6 Be ause ≡ od a d ≡ od , it follows from Theorem 5 that = + ≡ + = od , a d that 77 · ≡ · = od . Q4.Describe a procedure for converting decimal (base 10) expansions of integers into hexadecimal expansions. A4: E.g 5: Find the hexadecimal expansion of (177130)10. Solution: First divide 177130 by 16 to obtain 177130 = 16 · 11070 + 10. Successively dividing quotients by 16 gives 11070 = 16 · 691 + 14, 691 = 16 · 43 + 3, 43 = 16 · 2 + 11, 2 = 16 · 0 + 2. The successive remainders that we have found, 10, 14, 3, 11, 2, give us the digits from the right to the left of 177130 in the hexadecimal (base 16) expansion of (177130)10. It follows that (177130)10 = (2B3EA)16. (Recall that the integers 10, 11, and 14 correspond to the hexadecimal digits A, B, and E, respectively.)
  • 12. 786 Q5. Convert (1101 1001 0101 1011)2 to octal and hexadecimal representations. A5: Octal: 154533; hexadecimal: D95B Q6. Convert (7206)8 and (A0EB)16 to a binary representation. A6: (7206)8 =1110 1000 0110 (A0EB)16 =1010 0000 1110 1011; Q7. State the fundamental theorem of arithmetic. A7: THEOREM 1 The fundamental theorem of arithmetic: Every integer greater than 1 can be written uniquely as a prime or as the product of two or more primes where the prime factors are written in order of no decreasing size. E.g: gives some prime factorizations of integers. E.g 2: The prime factorizations of 100, 641, 999, and 1024 are given by 100 = 2 · 2 · 5 · 5 = 22 52 , 641 = 641, 999 = 3 · 3 · 3 · 37 = 33 · 37, 1024 = 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 = 210 . Q8. a Des i e a p o edu e fo fi di g the p i e fa to izatio of a i tege . A8: Find the prime factorization of 7007. Solution: To fi d the p i e fa to izatio of , fi st pe fo di isio s of su essi e p i es, beginning with 2. None of the primes 2, 3, and 5 divides 7007. However, 7 divides 7007, with 7007/7 = 1001. Next, divide 1001 by successive primes, beginning with 7.It is immediately seen that 7 also divides 1001, because 1001/7 = 143. Continue by dividing 143 by successive primes, beginning with 7. Although 7 does not divide 143, 11 does divide 143, and 143/11 = 13. Because 13 is prime, the procedure is completed. It follows that 7007 = 7 · 1001 = 7 · 7 · 143 = 7 · 7 · 11· 13. Consequently, the prime factorization of 7007 is 7 · 7 · 11 · 13 = 72 · 11 · 13. ▲ Use this p o edu e to fi d the p i e fa to izatio of , . b) 112 . 23 . 29 Q9. a) Defi e the g eatest o o di iso of t o i tege s. A9: Let a and b be integers, not both zero. The largest integer d such that d | a and d | b is called the greatest common divisor of a and b. The greatest common divisor of a and b is denoted by gcd(a, b). E.g: What is the greatest common divisor of 24 and 36? Solution: The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12. Hence, gcd(24, 36) = 12. See the Note Also a) Des i e at least th ee diffe e t a s to fi d the g eatest o o di iso of t o i tege s .When does each method work best? b) find all the common factors (not a good algorithm unless the numbers are really small); find the prime factorization of each integer (works well if the numbers aren't too big and therefore can be easily factored); use the Euclidean algorithm (really the best method). See the Algorithm in Book P() a) Find the greatest common divisor of 1,234,567 and 7,654,321.
  • 13. 786 1,234,567 and 7,654,321 =1 (use the Euclidean algorithm) a) Find the greatest common divisor of 23 35 57 79 11 and 29 37 55 73 13. d) 23 35 55 73 Q10. a Ho a ou fi d a li ea o i atio ith i tege oeffi ie ts of t o i tege s that equals their greatest common divisor? a) Use the Euclidean algorithm; see Example 17 in Section 4.3. EXAMPLE 17 Express gcd(252, 198) = 18 as a linear combination of 252 and 198. Solution: To show that gcd(252, 198) = 18, the Euclidean algorithm uses these divisions: 252 = 1 · 198 + 54 198 = 3 · 54 + 36 54 = 1 · 36 + 18 36 = 2 · 18. Using the next-to-last division (the third division), we can express gcd(252, 198) = 18 as a linear o i atio of a d .We fi d that = − · . The second division tells us that = − · . Substituting this expression for 36 into the previous equation, we can express 18 as a linear combination of 54 and 198.We have = − · = − · − · = · − · . The fi st di isio tells us that = − · . Substituting this expression for 54 into the previous equation, we can express 18 as a linear combination of 252 and 198.We conclude that = · − · − · = · − · , completing the solution. b) Express gcd(84, 119) as a linear combination of 84 and 119. b) 7 = 5 . 119 - 7. 84 Q11. a What does it ea fo a to e a i e se of a odulo ? a aa’ = od m) Ho a ou fi d a i e se of a odulo he is a positi e i tege a d g d a, = ? b) Express 1 as sa + tm (see Review Question 10). Then s is the inverse of a modulo m. c) Find an inverse of 7 modulo 19. c) 11; Q12. a Ho a a i e se of a odulo e used to sol e the o g ue e a ≡ od he gcd (a ,m) = 1? a) Multiply each side by the inverse of a modulo m. Sol e the li ea o g ue e ≡ od . b) { 10 + 19k I k E z } Q13. a) State the Chinese remainder theorem. A13: THE CHINESE REMAINDER THEOREM Let m1,m2,...,mn be pairwise relatively prime positive integers greater than one and a1,a2,...,an arbitrary integers. Then the system ≡ a od m1),
  • 14. 786 ≡ a od , · · · ≡ a od has a unique solution modulo m = m1m2 ···mn. (That is, there is a solution x with < , a d all othe solutio s a e o g ue t odulo to this solutio . x = a M y + a M y +···+ a M y . ≡ akMk k ≡ ak od k), for k = 1, 2,...,n.We have shown that x is a simultaneous solution to the n congruences. EXAMPLE 5 To sol e the s ste of o g ue es i E a ple , fi st let = · · = , M = / = 35,M2 = m/5 = 21, and M3 = m/7 = 15.We see that 2 is an inverse of M1 = 35 modulo 3, e ause · ≡ · ≡ od ; is a i e se of M = odulo , e ause ≡ od ; a d is a i e se of M = od , e ause ≡ od . The solutio s to this system are those x such that ≡ a M + a M + a3M3y3 = 2 · 35 · 2 + 3 · 21 · 1 + 2 · 15 · 1 = ≡ od . Fi d the solutio s to the s ste ≡ od , ≡ od , a d ≡ od . b) { 17 + l40k I k E z} Q14. Suppose that 2 − ≡ od .Is e essa il p i e? No; n could be a pseudo prime such as 341. . Use Fe at s little theo e to e aluate 200 mod 19. 9200 = 918 . 92 . 9180 = 918 . 92 . (918 )20 = 1 . 81 . 120 = 81 = 5 (mod 19) 16. Explain how the check digit is found for a 10-digit ISBN. Example 6 : I“BNs All ooks a e ide tified a I te atio al “ta da d Book Nu e I“BN-10),a 10-digit code x1x2 ...x10, assigned by the publisher. (Recently, a 13-digit code known as ISBN- 13 was introduced to identify a larger number of published works; see the preamble to Exercise 42 in the Supplementary Exercises.) An ISBN-10 consists of blocks identifying the language, the pu lishe , the u e assig ed to the ook its pu lishi g o pa , a d fi all , a he k digit that is either a digit or the letter X (used to represent 10). This check digit is selected so that � ≡ ∑ ��� mod 9 �= or equivalently, so that ∑ ��� ≡ mod �= Answer these questions about ISBN-10s: a The fi st i e digits of the I“BN-10 of the sixth edition of this book are 007288008.What is the check digit? (b) Is 084930149X a valid ISBN-10? Solution: (a) The check digit is determined by the congruence 10 i= i i ≡ od . I se ti g the digits gi es ≡ · + · + · + · + · + · + 7 · 0 + 8 · 0 +
  • 15. 786 · od . This ea s that ≡ + + + + + + + + od , so ≡ ≡ od . He e, = . (b) To see whether 084930149X is a valid ISBN-10, we see if 10 i= i i ≡ od . We see that 1 · 0 + 2 · 8 + 3 · 4 + 4 · 9 + 5 · 3 + 6 · 0 + 7 · 1 + 8 · 4 + 9 · 9 + 10 · 10 = 0 + 16 + + + + + + + + = ≡ ≡ od . He e, X is ot a valid ISBN-10. Q17. Encrypt the message APPLES AND ORANGES using a shift cipher with key k = 13. A17: NCCYRF NAQ BENATRF Q18. a) What is the difference between a public key and a private key cryptosystem? ‫غواړي‬ ‫کتل‬ ‫سم‬ b) Explain why using shift ciphers is a private key system. b) The amount of shift, k, is kept secret. It is needed both to encode and to decode messages. c) Explain why the RSA cryptosystem is a public key system. c) Although the key for decoding, d, is kept secret, the keys for encoding, n and e, are published. 19. Explain how encryption and decryption are done in the RSA cryptosystem. 299-301 ‫کتل‬ ‫صفحه‬ . Des i e ho t o pa ties a sha e a se et ke usi g the Diffie-Hellman key exchange protocol. 302 ‫کتل‬ ‫صفحه‬ Page : 378 Q1. a Ca ou use the p i iple of athe ati al i du tio to fi d a fo ula fo the su of the first n terms of a sequence? a) no b) Can you use the principle of mathematical induction to determine whether a given formula fo the su of the fi st te s of a se ue e is o e t? b) Sometimes yes. If the given formula is correct, then it is often possible to prove it using the principle of mathematical induction (although it would be wishful thinking to believe that every such true formula could be so proved). If the formula is incorrect, then induction would not work, of course; thus an incorrect formula could not be shown to be incorrect using the principle. Fi d a fo ula fo the su of the fi st e e positi e i tege s, a d p o e it usi g mathematical induction. Exercise 9. C Fi d a fo ula fo the su of the fi st e e positi e i tege s. a) 2+4+6+···+2n = n(n+1) b) Prove the formula that you conjectured in part (a). b) Basis step: 2 = 1·(1+1) is true. Inductive step: Assume that 2 + 4 + 6 +···+ 2k = k(k + 1). Then (2 + 4 + 6 + ··· + 2k) + 2(k + 1) = k(k+1)+2(k+1) = (k+1)(k+2). Q2. a Fo hi h positi e i tege s a e + n ?
  • 16. 786 a) n 7 b) Prove the conjecture you made in part (a) using mathematical induction. Fo the asis step e just he k that · + . Fi 7, and assume the inductive hypothesis, that 11n + 17 2n . Then 11(n + 1) + 17= (11n+17) + 11 2n+11 < 2n + 2n = 2n+1 . The strict inequality here follows from the fact that n 4. Q3. a) Which amounts of postage can be formed using only 5-cent and 9-cent stamps? a) Carefully considering all the possibilities shows that the amounts of postage less than 32 cents that can be achieved are 0, 5, 9, 10, 14, 15, 18, 19, 20, 23, 24, 25, 27, 28, 29, and 30. All amounts greater than or equal to 32 cents can be achieved. b) Prove the conjecture you made using mathematical induction. b) To prove this latter statement, we check the basis step by noting that 32 = 9 + 9 + 9 + 5. Assume that we can achieve n cents, and consider n + 1 cents, where n 32. If the stamps used for n cents included a 9-cent stamp, then replacing it by two 5-cent stamps gives us n + 1 cents, as desired. Otherwise only 5-cent stamps were used to achieve n cents, and since n > 30, there must be at least seven such stamps. Replace seven of the 5-cent stamps by four 9-cent stamps; this increases the amount of postage by 4 · 9 - 7 · 5 = 1 cent, again as desired. c) Prove the conjecture you made using strong induction. c) We check the base cases 32 = 3 · 9 + 5, 33 = 2 · 9 + 3 · 5, 34 = 9 + 5 · 5, 35 = 7 · 5, and 36 = 4 · 9. Fix n 37 and assume that all amounts from 32 to n - 1 can be achieved. To achieve n cents postage, take the stamps used for n - 5 cents (since n 37, n - 5 32, so the inductive hypothesis applies) and adjoin a 5-cent stamp. d) Find a proof of your conjecture different from the ones you gave in (b) and (c). d) Let n be an integer greater than or equal to 32. We want to express n as a sum of a nonnegative multiple of 5 and a nonnegative multiple of 9. Divide n by 5 to obtain a quotient q and remainder r such that n = 5q + r and 0 r 4. Note that since n 32, q 6. If r = 0, then we already have n expressed in the desired form. If r = 1, then n 36, so q 7; thus we can write n = 5q + 1 = 5(q - 7) + 4 · 9 to get the desired decomposition. If r = 2, then we rewrite n = 5q + 2 = 5(q - 5) + 3 · 9. If r = 3, then we rewrite n = 5q + 3 = 5(q - 3) + 2 · 9. And if r = 4, then we rewrite n = 5q + 4 = 5(q - 1) + 9. In each case we have the desired sum. Q4. Give two different examples of proofs that use strong induction. Section 5.2 example 2 and 3 page 336; EXAMPLE 2 Show that if n is an integer greater than 1, then n can be written as the product of primes. Solution: Let P(n) be the proposition that n can be written as the product of primes. BASIS STEP: P(2) is true, because 2 can be written as the product of one prime, itself. (Note that P(2) is the fi st ase e eed to esta lish. EXAMPLE 3 Consider a game in which two players take turns removing any positive number of matches they want from one of two piles of matches. The player who removes the last match wins the game. Show that if the two piles contain the same number of matches initially, the second player can always guarantee a win. Solution: Let n be the number of matches in each pile. We will use strong induction to prove P(n), the statement that the second player can win when there are initially n matches in each pile. Q5. a) State the well-ordering property for the set of positive integers. a) Seep. 314 and Appendix 1 (Axiom 4 for the positive integers). Axiom 4 The Well-Ordering Property Every nonempty subset of the set of positive integers has a least element. In Sections 5.1 and 5.2 it is shown that the well-ordering principle is equivalent to the principle of mathematical induction.
  • 17. 786 PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, we complete two steps: BASIS STEP: We verify that P(1) is true. INDUCTIVE STEP: We sho that the o ditio al state e t P k → P k + is t ue fo all positi e integers k. a) Use this property to show that every positive integer greater than one can be written as the product of primes. b) Let S be the set of positive integers that cannot be written as the product of primes. If S #- 0, then S has a least element, c. Clearly c ≠ 1, since 1 is the product of no primes. Thus c is greater than 1. Now c cannot be prime, since as such it would already be written as the product of primes (namely itself). Therefore c is a composite number, say c =ab, where a and b are both positive integers less than c. Since c is the smallest element of S, neither a nor b is in S. Therefore both a and b can be written as the product of primes. But multiplying these products together patently shows that c is the product of primes. This is a contradiction to the choice of c. Therefore our assumption that S ≠ 0 was wrong, and the theorem is proved. Q6. a) Explain why a function � from the set of positive integers to the set of real numbers is well- defi ed if it is defi ed e u si el spe if i g � a d a ule fo fi di g � (n) from � − . a) See Exercise 56 in Section 5.3. . Use athe ati al i du tio to p o e that a fu tio F defi ed spe if i g F a d a ule fo obtaining F + f o F is ell defi ed. ‫نسته‬ ‫کي‬ ‫کت‬ ‫غواړي‬ ‫حل‬ P o ide a e u si e defi itio of the fu tio � (n) = (n + 1)! b) f(1) = 2, and f(n) = (n + l)f(n - 1) for all n 2 Q . a Gi e a e u si e defi itio of the Fi o a i u e s. a) See the top of p. 347. Re all f o “e tio . that the Fi o a i u e s, f ,f ,f ,..., a e defi ed the e uations f0 = 0,f1 = , a d f = f − + f − fo = , , ,.... [We a thi k of the Fi o a i u e f eithe as the th term of the sequence of Fibonacci numbers f0,f1,... or as the value at the integer n of a function f .] We a use the e u si e definition of the Fibonacci numbers to prove many properties of these numbers.We give one such property in Example 4. EXAMPLE 4 “ho that he e e , f >α − , he e α = +√ / . Solution: We can use strong induction to prove this inequality. Let P(n) be the statement fn >α − .We want to show that P(n) is true whenever n is an integer greater than or equal to 3. BA“I“ “TEP: Fi st, ote that α< = f , α = +√ / < = f , so P a d P a e t ue. b) Show that � � > ��− whenever n , he e � n is the nth term of the Fibonacci sequence and α = +√5)/2. EXAMPLE 4 “ho that he e e , f >α − , he e α = +√ / . Solution: We can use strong induction to prove this inequality. Let P(n) be the statement fn >α − .We want to show that P(n) is true whenever n is an integer greater than or equal to 3. BA“I“ “TEP: Fi st, ote that α< = f , α = +√ / < = f , so P a d P a e t ue. Q8. a E plai h a se ue e a is ell defi ed if it is defi ed e u si el specifying a1 and a2 a d a ule fo fi di g an from a1,a2,...,a − for n = 3, 4, 5,.... a) See Exercise 57 in Section 5.3. 57. Use strong inductio to p o e that a fu tio F defi ed spe if i g F a d a ule fo o tai i g F + f o the alues F k fo k = , , ,..., is ell defi ed.
  • 18. 786 . Let P e F is ell-defi ed. The P is t ue e ause F is spe ified. Assu e that P k is true for all k<n. Then F(n) is well-defi ed at e ause F is gi e i te s of F , F , . . . , F − 1).So P(n) is true for all integers n. b) Find the value of an if a1 = 1, a2 = 2, and an = a − + a − +···+ a1, for n = 3, 4, 5,.... b) an = 3 · 2n-3 for n 3 9. Give two examples of how well-fo ed fo ulae a e defi ed e u si el fo diffe e t sets of elements and operators. EXAMPLE 8 Well-Fo ed Fo ulae i P opositio al Logi We a defi e the set of ell-formed formulae in propositional logic involving T, F, propositional variables, and operators from the set {¬, , ,→,↔}. BASIS STEP: T, F, and s, where s is a propositional variable, are well-formed formulae. RECURSIVE STEP: If E and F are well-formed formulae, then (¬E), (E F), (E F , E → F , a d E ↔ F are well-formed formulae.For example, by the basis step we know that T, F, p, and q are well-formed formulae, where p and q are propositional variables. From an initial application of the recursive step, we know that (p q), (p → F), (F → q), and (q F) are well-formed formulae. A second application of the recursive step shows that ((p q) → (q F)), (q (p , a d p → F → T a e ell-formed formulae. We leave it to the reader to show that p¬ q, pq , and ¬ pq are not well-formed formulae, by showing that none can be obtained using the basis step and one or more applications of the recursive step. ▲ EXAMPLE 9 Well-Fo ed Fo ulae of Ope ato s a d Ope a ds We a defi e the set of ell-formed formulae consisting of variables, u e als, a d ope ato s f o the set {+,−, ∗, /, ↑} (where ∗ denotes ultipli atio a d ↑ de otes e po e tiatio e u si el . BASIS STEP: x is a well-formed formula if x is a numeral or a variable. RECURSIVE STEP: If F and G are well-formed formulae, the F + G , F − G , F ∗ G , F/G , a d F ↑G are well-formed formulae. For example, by the basis step we see that x, y, 0, and 3 are well-formed formulae (as is any variable or numeral).Well-formed formulae generated by applying the recursive step once i lude + , + , − , − , ∗ 3), (3 ∗ y), (3/0), (x/y), (3↑x), and (0↑3). Appl i g the e u si e step t i e sho s that fo ulae su h as + + a d − ∗ y)) are well- formed formulae. [Note that (3/0) is a well-formed formula because we are concerned only with syntax matters here.]We leave it to the reader to show that each of the formulae x3+, y ∗+x, and ∗ x/y is not a well-formed formula by showing that none of them can be obtained from the basis step and one or more applications of the recursive step. ▲ Q . a Gi e a e u si e defi itio of the le gth of a st i g. a) See Example 7 in Section 5.3. EXAMPLE 7 Le gth of a “t i g Gi e a e u si e defi itio of l , the le gth of the st i g . Solution: The length of a string a e e u si el defi ed L λ = ; L(wx) = L(w) + 1 if w ∈ ∑∗ and x ∈ ∑∗ . Use the e u si e defi itio f o pa t a a d st u tu al i du tio to p o e that l = l + l(y). EXAMPLE 12 Use structural induction to prove that l(xy) = l(x) + l(y), where x and y belong to ∗, the set of strings over the alphabet ∑ . “olutio : We ill ase ou p oof o the e u si e defi itio of the set ∑∗ given in Definition 1 and the defi itio of the le gth of a st i g i E a ple , hi h spe ifies that l λ = a d l = l + when w ∈ ∗ and x ∈ . Let P(y) be the statement that l(xy) = l(x) + l(y) whenever x belongs to ∑ ∗.
  • 19. 786 BA“I“ “TEP: To o plete the asis step, e ust sho that P λ is t ue. That is, e ust sho that l λ = l + l λ fo all x ∈ ∗. Because l(xλ) = l(x) = l(x) + 0 = l(x) + l(λ) fo e e st i g , it follo s that P λ is t ue. Q11. a) What is a recursive algorithm? See the beginning of Section 5.4. DEFINITION 1 An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with smaller input. EXAMPLE 2 Give a recursive algorithm for computing an, where a is a nonzero real number and n is a nonnegative integer. Solution: We a ase a e u si e algo ith o the e u si e defi itio of a . This defi itio states that a + = a · a fo > a d the i itial o ditio a = . To fi d a , su essi el use the e u si e step to reduce the exponent until it becomes zero. We give this procedure in Algorithm 2. ▲ b) Describe a recursive algorithm for computing the sum of n numbers in a sequence. b) Call the sequence a 1 , a2 , ... , an. If n = 1, then the sum(a1) = a1. Otherwise sum(a1,a2, ... ,an) =an + su a ,a ,…an-1 ). Q12. Describe a recursive algorithm for computing the greatest common divisor of two positive integers. See Example 3 in Section 5.4. EXAMPLE 3 Give a recursive algorithm for computing the greatest common divisor of two nonnegative integers a and b with a<b. Solution: We can base a recursive algorithm on the reduction gcd(a, b) = gcd(b mod a,a) and the condition gcd(0,b) = b when b> 0. This produces the procedure inAlgorithm 3, which is a recursive version of the Euclidean algorithm. We illustrate the workings ofAlgorithm 3 with a trace when the input is a = 5, b = 8.With this input, the algo ith uses the else lause to fi d that g d , = g d od , = g d , . It uses this lause agai to fi d that g d , = g d od , = g d , , the to get g d , = g d od , 2) = gcd(1, 2), the to get g d , = g d od , = g d , . Fi all , to fi d g d , it uses the fi st step ith a = to fi d that g d , = .Co se ue tl , the algo ith fi ds that g d , = . Q13. a) Describe the merge sort algorithm. The Merge Sort We now describe a recursive sorting algorithm called the merge sort algorithm. We will demonstrate how the merge sort algorithm works with an example before describing it in generality. In general, a merge sort proceeds by iteratively splitting lists into two sub lists of equal length (or where one sub list has one more element than the other) until each sub list contains one element. This succession of sub lists can be represented by a balanced binary tree. The procedure continues by successively merging pairs of lists, where both lists are in increasing order, into a larger list with elements in increasing order, until the original list is put into increasing order. The succession of merged lists can be represented by a balanced binary tree. b) Use the merge sort algorithm to put the list 4, 10, 1, 5, 3, 8, 7, 2, 6, 9 in increasing order. b) We split the list into the two halves: 4, 10, 1, 5, 3 and 8, 7, 2, 6, 9. We then merge sort each half by applying this algorithm recursively and merging the results. For the first half, for example, this means splitting 4, 10, 1, 5, 3 into the two halves 4, 10, 1 and 5, 3, recursively sorting each half, and merging. For the second half of this, for example, it means splitting into 5 and 3, recursively sorting each half, and merging. Since these two halves are already sorted, we just merge, into the sorted list 3, 5. Similarly, we will get 1, 4, 10 for the result of merge sort applied to 4, 10, 1. When we merge 1, 4, 10 and 3, 5, we get 1, 3, 4, 5, 10. Finally, we merge this
  • 20. 786 with the sorted second half, 2, 6, 7, 8, 9, to obtain the completely sorted list 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. c) Give a big-O estimate for the number of comparisons used by the merge sort. LEMMA 1 Two sorted lists with m elements and n elements can be merged into a sorted list using no o e tha + − o pa iso s. THEOREM 1 The number of comparisons needed to merge sort a list with n elements is O(n log n). Q14. a) Does testing a computer program to see whether it produces the correct output for certain input values verify that the program always produces the correct output? a) no b) Does showing that a computer program is partially correct with respect to an initial asse tio a d a fi al asse tio e if that the p og a al a s p odu es the o e t output? If ot, what else is needed? b) No-you also need to show that it halts for all inputs, and the initial and final assertions for which you provide a proof of partial correctness need to be appropriate ones (i.e., relevant to the question of whether the program produces the correct output). 15. What techniques can you use to show that a long computer program is partially correct with respect to a i itial asse tio a d a fi al asse tio ? See the rules displayed in Section 5.5. Rules of Inference A useful rule of inference proves that a program is correct by splitting the program into a sequence of subprograms and then showing that each subprogram is correct. Suppose that the programS is split into subprograms S1 and S2.Write S = S1; S2 to indicate that S is made up of S1 followed by S2. “uppose that the o e t ess of “ ith espe t to the i itial asse tio p a d fi al asse tio , a d the correct ess of “ ith espe t to the i itial asse tio a d the fi al asse tio , ha e ee established. It follows that if p is true and S1 is executed and terminates, then q is true; and if q is true, and S2 executes and terminates, then r is true. Thus, if p is true and S = S1; S2 is executed and terminates, then r is true. This rule of inference, called the composition rule, can be stated as p{S1}q q{S2}r ∴ p{S1; S2}r. This rule of inference will be used later in this section. Next, some rules of inference for program segments involving conditional statements and loops will be given. Because programs can be split into segments for proofs of correctness, this will let us verify many different programs. Q16. What is a loop invariant? How is a loop invariant used? while condition S note that S is repeatedly executed until condition becomes false. An assertion that remains true each time S is executed must be chosen. Such an assertion is called a loop invariant. In other words, p is a loop invariant if (p condition){S}p is true. Example : i := 1 factorial := 1 while i<n i := i + 1 factorial := factorial · i
  • 21. 786 Page : 439 Q . E plai ho the su a d p odu t ules a e used to fi d the u e of it st i gs ith a length not exceeding 10. 1 + 2 + 2. 2 + 2. 2. 2 + ... + 210 = 2047 Q . E plai ho to fi d the u e of it st i gs of le gth ot e eedi g that ha e at least o e 0 bit. Subtract 11 from the answer to the previous review question, since >., 1, 11, ... , 11 ... 1 are the bit strings that do not have at least one 0 bit. Q3. a Ho a the p odu t ule e used to fi d the u e of fu tio s f o a set ith elements to a set with n elements? a) See Example 6 in Section 6.1. example 6 : Counting Functions How many functions are there from a set with m elements to a set with n elements? Solution: A function corresponds to a choice of one of the n elements in the codomain for each of The m elements in the domain. Hence, by the product rule there are n · n · ··· · n = nm functions from a set with m elements to one with n elements. For example, there are 53 = 125 different functions f o a set ith th ee ele e ts to a set ith fi e ele e ts. ▲ b) Ho a fu tio s a e the e f o a set ith fi e ele e ts to a set ith 10 elements? b) 105 Ho a the p odu t ule e used to fi d the u e of o e-to-one functions from a set with m elements to a set with n elements? c) See Example 7 in Section 6.1. example 7 : Counting One-to-One Functions How many one-to-one functions are there from a set with m elements to one with n elements? Solution: First note that when m>n there are no one-to-one functions from a set with m elements to a set ith ele e ts. No let . “uppose the ele e ts i the do ai a e a ,a ,...,am. There are n ways to choose the value of the function at a1. Because the function is one-to-one, the value of the fu tio at a a e pi ked i − a s e ause the alue used fo a a ot e used again). In general, the value of the function at ak a e hose i − k + a s. B the p odu t ule, the e a e − − ··· − + o e-to-one functions from a set with m elements to one with n elements. For example, there are 5 · 4 · 3 = 60 one-to-one functions from a set with three ele e ts to a set ith fi e ele e ts. ▲ d) How many one-to-o e fu tio s a e the e f o a set ith fi e ele e ts to a set ith elements? d) 10·9·8·7·6 e Ho a o to fu tio s a e the e f o a set ith fi e ele e ts to a set ith elements? e) 0 . Ho a ou fi d the u e of possi le out o es of a pla off et ee t o tea s he e the first team that wins four games wins the playoff? with a tree diagram; see Example 22 in Section 6.1 (extended to larger tree) EXAMPLE 22 A pla off et ee t o tea s o sists of at ost fi e ga es. The fi st tea that i s th ee ga es wins the playoff. In how many different ways can the playoff occur?
  • 22. 786 Solution: The tree diagram in Figure 3 displays all the ways the playoff can proceed, with the winner of each game shown. We see that there are 20 different ways for the playoff to occur. ▲ . Ho a ou fi d the u e of it st i gs of le gth te that eithe egi ith o e d ith 010? Using the inclusion-exclusion principle. we get 27 + 27 - 24 ; see Example 18 in Section 6.1. EXAMPLE 18 How many bit strings of length eight either start with a 1 bit or end with the two bits 00? Solution: We can construct a bit string of length eight that either starts with a 1 bit or ends with the two bits 00, by constructing a bit string of length eight beginning with a 1 bit or by constructing a bit string of length eight that ends with the two bits 00. We can construct a bit string of length eight that begins witha1in27 = 128 way the number of bit strings of length eight that begin witha1orend with a 00, which equals the number of ways to construct a bit string of length eight that begins witha1or that ends with 00, equals 128 + − = . 17‫دی‬ ‫درس‬ ‫ليکچر‬ Q6. a) State the pigeonhole principle. Introduction “uppose that a flo k of pigeo s flies i to a set of pigeo holes to oost. Be ause the e a e pigeons but only 19 pigeonholes, a least one of these 19 pigeonholes must have at least two pigeons in it. To see why this is true, note that if each pigeonhole had at most one pigeon in it, at most 19 pigeons, one per hole, could be accommodated. This illustrates a general principle called the pigeonhole principle, which states that if there are more pigeons than pigeonholes, then there must be at least one pigeonhole with at least two pigeons in it (see Figure 1). Of course, this principle applies to other objects besides pigeons and pigeonholes. THEOREM 1 THE PIGEONHOLE PRINCIPLE If k is a positive integer and k + 1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects. 17 lecture look b) Explain how the pigeonhole principle can be used to show that among any 11 integers, at least two must have the same last digit. b) 11 pigeons, 10 holes (digits) Q7. a) State the generalized pigeonhole principle. The pigeonhole principle states that there must be at least two objects in the same box when there are more objects than boxes. However, even more can be said when the number of objects exceeds a multiple of the number of boxes. For instance, among any set of 21 decimal digits there must be 3 that are the same. This follows because when 21 objects are distributed into 10 boxes, one box must have more than 2 objects.
  • 23. 786 b) Explain how the generalized pigeonhole principle can be used to show that among any 91 integers, there are at least ten that end with the same digit. b)N=91,k=10 Q8. a) What is the difference between an r-combination and an r-permutation of a set with n elements? a) Permutations are ordered arrangements; combinations are unordered (or just arbitrarily ordered for convenience) selections b) Derive an equation that relates the number of r-combinations and the number of r- permutations of a set with n elements. b) P(n,r) = C(n.r) · r! (see the proof of Theorem 2 in Section 6.3)
  • 24. 786 b) How many ways are there to select six students from a class of 25 to serve on a committee? c) C(25, 6) c) How many ways are there to select six students from a class of 25 to hold six different executive positions on a committee? d) P(25, 6) Q9. a What is Pas al s t ia gle?
  • 25. 786 a) See pp. 418-419 419 ‫غواړي‬ ‫کتل‬ ‫صفحه‬ This t ia gle is k o as Pas al’s t ia gle. Pas al’s ide tit sho s that he t o adja e t i o ial oeffi ie ts i this t ia gle a e added, the i o ial oeffi ie t i the e t o et ee these t o oeffi ie ts is p odu ed Ho a a o of Pas al s t ia gle e p odu ed f o the o e a o e it? b) by adding the two numbers above each number in the new row Q10. What is meant by a combinatorial proof of an identity? How is such a proof different from an algebraic one? A combinatorial proof is a proof of an algebraic identity that shows that both sides count the same thing (in some application). An algebraic proof is totally different-it shows that the two sides are equal by doing formal manipulations with the unknowns. with no reference to what the expressions might mean in an application. Q . E plai ho to p o e Pas al s ide tit usi g a o i atorial argument. See p. 418.
  • 26. 786 12. a) State the binomial theorem. a) See p. 416
  • 27. 786 b) Explain how to prove the binomial theorem using a combinatorial argument. b) See p. 416 Fi d the oeffi ie t of 100 y101 in the expansion of (2x + 5y)201 . c) 2100 .5101 C (201, 101) Q13. a E plai ho to fi d a fo ula fo the u e of a s to sele t o je ts f o o je ts when repetition is allowed and order does not matter. a) See Theorem 2 in Section 6.5
  • 28. 786 Ho a a s a e the e to sele t a doze o je ts f o a o g o je ts of fi e diffe e t t pes if objects of the same type are indistinguishable? b) C(5 + 12 - 1, 12) Ho a a s a e the e to sele t a doze o je ts f o these fi e diffe e t types if there must e at least th ee o je ts of the fi st t pe? c) C (5 + 9 - 1, 9) d Ho a a s a e the e to sele t a doze o je ts f o these fi e diffe e t t pes if the e a ot e o e tha fou o je ts of the fi st t pe? d) C (5 + 12 -1.12) - C(5 + 7 - 1. 7) e Ho a a s a e the e to sele t a doze o je ts f o these fi e diffe e t t pes if the e ust e at least t o o je ts of the fi st t pe, ut o o e tha th ee o je ts of the se o d t pe? e) C (5 + 10 - 1, 10) - C(5 + 6 - 1, 6) 14. a) Let n and r be positive integers. Explain why the number of solutions of the equation x1 + x2 +···+ xn = r, where xi is a nonnegative integer for i = 1, 2, 3,...,n, equals the number of r- combinations of a set with n elements. a) See Example 5 in Section 6.5. b) How many solutions in nonnegative integers are there to the equation x1 + x2 + x3 + x4 = 17? b) C( 4 + 17 - 1, 17) c) How many solutions in positive integers are there to the equation in part (b)? c) C(4 + 13 - 1, 13) (see Exercise 15a in Section 6.5) 15. How many solutions are there to the equation x1 + x2 + x3 + x4 + x5 = 21, where xi , i = 1, 2, 3, 4, 5, is a nonnegative integer such that
  • 29. 786 a ? i fo i = , , , , ? ? d , < , a d ? 15. a) 10,626 b) 1,365 c) 11,649 d) 106 Q15. a) Derive a formula for the number of permutations of n objects of k different types, where there are n1 indistinguishable objects of type one, n2 indistinguishable objects of type two,..., and nk indistinguishable objects of type k. a) See Theorem 3 in Section 6.5. b) How many ways are there to order the letters of the word INDISCREETNESS? b) 14!/(2!2!1!3!1!1!3!1!) Q16. Describe an algorithm for generating all the permutations of the set of the n smallest positive integers. 16. See pp. 435-436.‫غواړې‬ ‫کتل‬ Q . a Ho a a s a e the e to deal ha ds of fi e a ds to si pla e s f o a sta da d - card deck? a) C(52, 5) · C(47, 5) · C(42, 5) · C(37, 5) · C(32, 5) · C(27, 5) b) How many ways are there to distribute n distinguishable objects into k distinguishable boxes so that ni objects are placed in box i ? b) See Theorem 4 in Section 6.5
  • 30. 786 Q18. Describe an algorithm for generating all the combinations of the set of the n smallest positive integers. See pp. 437-438 EXAMPLE 4 Find the next bit string after 10 0010 0111. Solution: The fi st it f o the ight that is ota isthe fou th it f o the ight. Cha ge this bit to a 1 and change all the following bits to 0s. This produces the next larger bit string, 10 0010 1000 ‫غواړې‬ ‫کتل‬ Page : 495 Q . a Defi e the p o a ilit of a e e t he all out o es a e e uall likel . a) See p. 446.
  • 31. 786 b) What is the probability that you select the six winning numbers in a lottery if the six different i i g u e s a e sele ted f o the fi st positi e i tege s? b) 1/C(50, 6) Q . a What o ditio s should e et the p o a ilities assig ed to the out o es f o a fi ite sample space? b) What probabilities should be assigned to the outcome of heads and the outcome of tails if heads comes up three times as often as tails? b) p(H) = 3/4, p(T) = ¼
  • 32. 786 Q . a Defi e the o ditio al p o a ilit of a e e t E gi e a e e t F. a) See p. 456 b) Suppose E is the event that when a die is rolled it comes up an even number, and F is the event that when a die is rolled it comes up 1, 2, or 3.What is the probability of F given E? b) 1/3 Q4. a) When are two events E and F independent? a) See p. 457 The e e ts E a d F a e i depe de t if a d o l if p E ∩ F = p E p F . EXAMPLE 5 Suppose E is the event that a randomly generated bit string of length four begins with a 1 and F is the event that this bit string contains an even number of 1s. Are E and F independent, if the 16 bit strings of length four are equally likely?
  • 33. 786 Solution: There are eight bit strings of length four that begin with a one: 1000, 1001, 1010, 1011, 1100, 1101, 1110, and 1111. There are also eight bit strings of length four that contain an even number of ones: 0000, 0011, 0101, 0110, 1001, 1010, 1100, 1111. Because there are 16 bit strings of length four, it follows that p(E) = p(F) = 8/16 = 1/2. Be ause E ∩ F ={ , , , }, e see that p E ∩ F = / = / . Because p E ∩ F = / = / / = p E p F , we conclude that E and F are independent b) Suppose E is the event that an even number appears when a fair die is rolled, and F is the event that a 5 or 6 comes up. Are E and F independent? b) yes Q5. a) What is a random variable? a) See p. 460 b) What are the possible values assigned by the random variable X that assigns to a roll of two dice the larger number that appears on the two dice? b) 1, 2, 3, 4, 5, 6 Q . a Defi e the e pe ted alue of a random variable X.
  • 34. 786 b) What is the expected value of the random variable X that assigns to a roll of two dice the larger number that appears on the two dice? Q7. a) Explain how the average- ase o putatio al o ple it of a algo ith , ith finitely many possible input values, can be interpreted as an expected value. a) See p. 482.
  • 35. 786 b) What is the average-case computational complexity of the linear search algorithm, if the probability that the element for which we search is in the list is 1/3, and it is equally likely that this element is any of the n elements in the list? b) (5n + 6)/3 (see Example 8 in Section 7.4) Q8. a) What is meant by a Bernoulli trial? a) See p. 458 b) What is the probability of k successes in n independent Bernoulli trials? b) See Theorem 2 in Section 7.2
  • 36. 786 c) What is the expected value of the number of successes in n independent Bernoulli trials? c) See Theorem 2 in Section 7.4
  • 37. 786 Q9. a) What does the linearity of expectations of random variables mean? a) See p. 480.
  • 38. 786 Ho a the li ea it of e pe tatio s help us fi d the e pe ted u e of people ho e ei e the correct hat when a hatcheck person returns hats at random? b) See Example 6 in Section 7.4. Q10. a) How can probability be used to solve a decision problem, if a small probability of error is acceptable? a) See the discussion of Monte Carlo algorithms on p. 463
  • 39. 786 b) How can we quickly determine whether a positive integer is prime, if we are willing to accept a small probability of making an error? b) See Example 16 in Section 7.2.
  • 40. 786 Q . State Ba es theo e a d use it to fi d p F | E if p E | F = / , p E | F = / , a d p F = / , where E and F are events from a sample space S.
  • 41. 786 Q12. a) What does it mean to say that a random variable has ageometric distribution with parameter p? a) See pp. 484-485
  • 42. 786
  • 43. 786 b) What is the mean of a geometric distribution with parameter p? b) See Theorem 4 in Section 7.4. ‫ده‬ ‫قضيه‬ ‫څلورمه‬ ‫پورته‬ ‫دغه‬ Q13. a) What is the variance of a random variable?
  • 44. 786 b) What is the variance of a Bernoulli trial with probability p of success? b) See Example 14 in Section 7.4. Q14. a) What is the variance of the sum of n independent random variables?
  • 45. 786 b) What is the variance of the number of successes when n independent Bernoulli trials, each with probability p of success, are carried out? b) See Example 18 in Section 7.4. ‫پورته‬ ‫دغه‬ 18 ‫دی‬ ‫ل‬ ‫مث‬ Q . What does Che she s i e ualit tell us a out the probability that a random variable de iates f o its ea o e tha a spe ified a ou t? See p. 491.
  • 46. 786 Special Thanks from Azizullah ‘Mahjoor’ that help me for solving these Question Prepared by Samiullah ‘Yousafi’ Solved by Samiullah Yousafi & ‘Azizullah Mahjoor’ Students of Kandahar Computer Science Faculty 1395-02-27 Monday, May-16-2016