Uploaded by qussay alhassany

elebda3.net-5604

advertisement
‫ر‬
‫ا‬
‫س اب‬
‫ أب اب‬: ‫ا‬
5
9-6
14-10
(Mathematical Inductions) !"# ‫ا ج ا‬
: ‫ا اول‬
(Relations Recurrence) #‫ ت ا ار‬:;‫ ا‬:!78‫ا‬
11
‫ا‬
2
12-11
(General methods) >‫? او‬# @‫ا‬
2
14-13
( Repeated Substitution& guess)78‫? ا‬# @‫ا‬
2
31-15
(Tree)‫ر‬HI‫ا‬
:G8‫ا ا‬
3
16
‫ر‬HI‫اع ا‬7‫أ‬
3
16
(Free Tree) ‫ ة ا ة‬HM‫ا‬
3
17
(Rooted Tree) ‫ور‬OH‫ ة ذات ا‬HM‫ا‬
3
(Binary Trees ) Q 8‫ر ا‬HI‫ا‬
3
( Floor Ceiling Function ) ‫ اا‬T?‫أر" و‬
3
24-22
(tree traversal) ‫ر‬HIV WM‫ز ا‬Y‫ا‬
3
27-25
( Binary Search Trees (B.S.T) ) !Q 8‫ ا‬G[‫ر ا‬HI‫أ‬
3
29-27
(Building tree using B. S .T) !Q 8‫ ا‬G[‫ ة `_^ام ا‬HM‫ء ا‬b `
3
31-29
.( Deletion& insert) ‫ ة‬HM‫ا;ت ! ا‬
3
17-16
20-18
21
41-32
( Graph ) 7[‫ا^@@ت ا‬
33
:d`‫ا ا ا‬
4
33
7[‫أ _م ا^@@ت ا‬
4
34
(Paths and Cycles) ‫ا_رات واورات‬
4
f‫ ! ا‬7[‫ ا^@@ت ا‬8g
4
(MST)‫ ة اة‬HM >7‫ ازون وا اد‬7[‫ا م ا‬
4
40-39
(krukel) ‫? آ ول‬# k
4
41-40
(prim) # ` ?# k
4
37-35
38
48-42
(Logic Math) !"# ‫ ا‬n@ ‫ا‬
: mW^‫ا ا‬
43
g
43
!"# ‫ ا‬n@ ‫ز ا‬W‫ر‬
5
5
?@ ‫ا[ا`ت ا‬
5
45-44
2
48-46
!"# ‫ ا‬n@ ‫@[?ت ! ا‬g
50-49
. ‫ وا‬References ‫ا ا‬
3
5
5
‫ا[ب اول‬
!"# ‫ا ج ا‬
Math.Induction
‫ا‬
! pW‫;ت ه‬g
‫أب اب‬
!78‫ا[ب ا‬
#‫ ت ا ار‬:;‫ا‬
(Relations)
mW^‫ا[ب ا‬
n@ ‫ا‬
(Logic)
d`‫ا[ب ا ا‬
7[‫ا^@@ت ا‬
( Graph )
G8‫ا[ب ا‬
‫ر‬HI‫ا‬
(Tree)
4
‫ا ‪:‬‬
‫‪;g‬ت ه‪ ! pW‬أب اب وآ ‪t#tu vw:g‬ي ‪` rW‬ا‪ #‬اب ا> ‪ p# 7‬أن أب اب ‪m‬‬
‫آ‪ !:‬وا; ‪ u‬آ ا‪, f‬و? أ‪u‬ة ! ه‪O‬ا اب ‪ >u‬ا[_‪ k‬وا_‪y"g ! :‬‬
‫ا ر `‪ >M‬ا@ ق ‪ g >w‬ا;‪ M` W‬وا"‪ y‬ى ا?! ‪.‬‬
‫‪W:u‬ت ‪ ! p"g‬اب ‪:‬‬
‫ه‪O‬ا ا;‪H W:‬ه ‪` u‬ا‪ #‬آ درس وه! ‪ tW g‬ا> أن ا;‪W‬ت ا?‪ W‬أ‪W‬م ه‪ ~O‬ا;‪ W:‬ه! إ| ‪Q‬‬
‫‪ rW #tg‬إدراآ ه `; > أ‪ W?W 7‬درس ‪.‬‬
‫‪u‬م ا;ب‬
‫ارس `‪ M‬ا@ب ‪.‬‬
‫‪5‬‬
6
CH.1
‫ا[ب اول‬
Mathematical Induction
!"# ‫ا ج ا‬
. !"#‫ن ر‬7 ‫[„ ƒ أي‬8g p: rW  # ‫ ` هن‬k_` ` ‫"! ه‬# ‫ا‚ ج أو ا? اء ا‬
. ‫ ح آ @ة‬I dW ‫! @ات ا‬# W ! ‫ @ات ا‬dW ‫ن‬# ‫ ح‬M‫ا‬
Q.1: Use End.Math show that :
1+2+3+4+……+ n =
n=1,2,3,4,5…..
Ans:
: ‫ث @ات‬:| rW ‫ن‬g w ?# k‫و‬
7
‫أ‪ w 7‬ا_”‬
‫‪ •w:W p‬ه‪ fH# W‬أن ‪ ;g‬إن ا_” ‪ _? g‬ا> أ| ن ا?‪7‬ن و =‪u n= p[_ ` n‬ة أ‪I‬ل‬
‫او ‪ W 8W ?# r#‬ه ‪YW‬د ! ا_” وه ا‪ M‬ر و|‪ G` ?# rW 7‬أن ‪ ! g n‬إ>‬
‫‪ N‬آ‪:‬ه ‪ ™;` 8W‬و‪ r‬ا ‪:‬ف ن ! ‪ W:u‬ا_وي ‪ rW‬ا‪ r‬أن ‪ @;#‬أآ[ ‪ rW‬أو أƒ— ‪rW‬‬
‫وآ أ ر ‪_W rW d‬ى ا_šال ‪.‬‬
‫‪8‬‬
Q.2 _ Use End.Math show that : 1+3+5+….+(2n-1)=
Ans:
9
n=1,2,3,….
10
CH.2
!78‫ا[ب ا‬
Recurrence Relations
#‫ ت ا ار‬:;‫ا‬
."# ‫ ا;دت ا‬r` #‫ ا ار‬:;‫ اب ! ر`œ ا‬Gw rW ‫ن‬g‫ ƒر‬g "#‫;دت ر‬W !‫ه‬
: #‫ ت ا ار‬:;‫ ا‬g !‫ ا;دت ا‬r?# k Y# ‫ ه ك آ‬#‫ ا;دت ا ار‬
: (General methods) >‫? او‬# @‫ا‬
. 78‫ ا‬Y‫ ار‬rW ‫;د‬W I >u ‫ن‬g ‫أن‬
11
12
: ( Repeated Substitution& guess)78‫? ا‬# @‫ا‬
. p‫[ع ا^@ات ا‬gb` ‫ن ذا‬# 78‫> ارة ا‬u !‫ ا‬Q_‫ ا‬
: (Solution steps) ‫@ات ا‬
Tn=aTn-1
Tn=a[aTn-2]
Tn=a^2 Tn-2
Tn=a^2 [aTn-3]
Tn=a^3 Tn-3
In step : i= a^i Tn-i ,i=1,2..
So: Tn=a^nTn-n , T0=c , i=n , n=0,1,2..
The result : Tn= Ca^n
Q.1: solving the recurrence relation : Tn=(n-1)+Tn-1 , T0=0
Ans:
Tn=(n-1)+Tn-1
Tn=(n-1)+[(n-2)+Tn-2]
Tn=(n-1)+(n-2)+Tn-3
Tn=(n-1)+ (n-2)+ [(n-3)+Tn-3]
In step : Tn=(n-1)+ (n-2)+ ….+(n-i)+ Tn-i , i=1,2,3…n
=1+2+3+…+n-1
=
13
Q.2: solving the recurrence relation : Tn= 1+T(n/2), T1=1 , n=2^k, k
N ?
Ans:
Tn= 1+T(n/2)
Tn= 1+ [1+T(n/2)]
Tn= 2+T(n/4)
Tn= 2+ [1+T(n/8)]
Tn= 3+T(n/8)
in step : i=i +T(n/2^i) , i=1,2,3…k
at :
i=k
= k+T(n/2^k)
at :T=1
T=k+1
Q.3:we have 2 algorithms to solve agiven problem P.Which one would you Use ?
Why?
A: an iterative algorithm Which takes n^2 operation?
B: an algorithms Which applies divide and conquer. Its number of operation is
given solving the recurrence relation:
N?
T(n)=n+2T(n/2) , T(1)=0,n=2^k,K
Ans:
A: n^2
B:
T(n)=n+2T(n/2) , T(1)=0,n=2^k,K
T(n)=n+2[ (n/2)+2T(n/2)]
T(n)=2n+4T(n/4)
T(n)=3n+8T(n/8)
N
in step : i=ni +2^i T(n/2^i) , i=1,2,3…k
at :
i=k
= nk+2^kT(1)
=nk= n log2 n , O(n^2)
14
15
‫اب ا‬
‫‪CH.3‬‬
‫ار‬
‫‪Trees‬‬
‫‪ &ُ%‬ا‪1‬ر وا‪ (! .&/‬أه‪ +‬ا‪#$‬ت ا*) !( ! ‪$$‬ت ا'ت ا ‪#$% &%‬ت ! اة ا‬
‫‪ ,‬و;‪ +‬ا‪48‬ب ‪& =9 >? @AB‬م ار ‪#$%‬ت ;&‪&9‬ة !( أه‪ (9* % :‬وأ‪678‬ع ا‪!4‬ت‬
‫;( ‪ H%7% I97J‬ا'ت ور‪CF; GB‬ت ‪&;C DB :EB‬ة ا'ت ‪ ,‬آ ‪ &%‬ار ا=)‪K‬‬
‫ا‪ 97SO‬آ‪4>4‬ل ا‪ Q‬ا‪ PC4‬ا‪; H8O‬ت ا‪ NOA‬وا‪ H%7‬وا‪7‬ز ‪.‬آ‪T‬ا‪& =% U‬م ار ا‪+SO‬‬
‫‪ F‬ا! ‪4W%‬ن !( ;&ت آت وا‪W‬ت ‪4W%‬ن !( ;&ت ا‪=C‬م وه‪. VTW‬‬
‫ا ‪ KWZB :OA% (W9‬ه‪ً !7‬‬
‫أ'‪4‬اع ار ‪:‬‬
‫ه‪O‬ك '‪ (! (;4‬ا‪1‬ر وه آ ‪:‬‬
‫‪ -A‬ا‪7Z‬ة ا‪7‬ة )‪ : (Free Tree‬ه ! ‪ I#9 G=B 'B G$‬ا‪7Z‬ط ا ‪:‬‬
‫إذا آن ‪ v,w‬رأ‪7 (8‬ة ‪=! &649 @'g ,‬ر ‪ v (! G=B‬ا‪. w Q‬‬
‫‪ -B‬ا‪7Z‬ة ذات ا‪T‬ور )‪ : (Rooted Tree‬ه ‪7‬ة ‪ .‬رأس ?ص ‪ @; I$9‬ا‪T‬ر ‪. Root‬‬
‫‪4> DB‬ر ا‪1‬ر ذات ا‪T‬ور ‪:‬‬
‫‪: (Family Tree) -1‬‬
‫•‬
‫•‬
‫!‪S/F‬ت ‪:‬‬
‫;&د ‪ node = n‬و ;&د ‪. edge = n-1‬‬
‫‪=! &649 1‬ر !‪. Iy‬‬
‫‪16‬‬
. ! !7:‫م ا‬SO‫ ا‬K! : (Hierarchical Structures ) -2
. ! #B=! ‫@ او‬4$B K : (Tournament Tree) -3
: (Expression Tree ) -4
17
: (Binary Trees ) )O‫ار ا‬
‫ أي‬:T v ‫ رأس‬KW @=OB @'‫ ا‬B @%7! ‫ؤوس وا'ت‬7B $%7! : ‫) ا'ت‬O„ ‫ة‬7 ‫ه‬
;7‫ة ا‬7 ‫'ت‬B 7AO; ‫ وأي‬, ‫ ا'ت‬7AO; (! 7y>‫أس أ‬7 ‫ى‬7=‫; ا‬7‫ ا‬.7Z‫ ا‬7AO;
. ‫أس‬7‫ ا'ت ا‬7AO; (! 7‫أس أآ‬7 QO‫ا‬
@:% +„ 7‫رن ا( !‡ ا=ر !( اآ‬#% +„ .7Z‫ ا‬C (! ‫&اء‬% , ! 7AO; (; ‫&ا‬O; : 7A B
. .7W‫‰ ا‬E% @!1‫@ و!‡ ا‬O; ‫اد ا‬7‫ ا‬7AO‫ ا‬Q‫ل ا‬4>4‫ ا‬Q‫ا ا‬TW‫ وه‬7‫آ‬1‫ ا‬Q‫ا‬
. .7=!‫@ و‬O! ‫ة‬7Z‫*ء ا‬%‫) و‬O‫ ام ا‬KWZ‫ا ا‬T‫ه‬
:(Mathematical Induction Proof Trees) Š97‫اء ا‬7#8B ‫ ا„ت ‹ر‬DB
Q.1 _ Use End.Math show that Proof the num. of edges in a tree = The num.node
in tree -1 ?
Ans :
18
. ‫ة‬7 P= :'‫ ا‬O9 ‫ا‬T‫ وه‬cycle #y! ‫ن‬4W8 edges (! 7‫& اŠ آ‬O; : S/F!
Q.2-Use End.Math show that Proof the num. of node at Level <= 2^i-1 , i=1,2,3.?
19
Q.3 -Use End.Math show that Proof the num. of node(n) is Binary Tree of High h
h<=2^n-1
,
h= 1,2,3…
20
: ( Floor Ceiling Function ) ‫ ا&ا‬N#8‫أرŠ و‬
The notation for the floor and ceiling functions is shown below:
1-The floor functions:
2- The ceiling functions:
21
: (tree traversal) ‫ ‹ر‬K!Z‫ز ا‬61‫ا‬
7AO; K‫ ; !&دة آ‬TOB ‫م‬4#'‫ و‬, SO! #97$B ‫ة‬7Z‫ ا‬7>O; (! 7AO; K‫رة آ‬9*B ‫م‬4#% ‫ه أن‬
‫ة‬7Z‫ !‡ ا‬K!‫ ا‬+9 Q/ 7Z‫ ا‬7>O; ‫ث‬F„ P7! H6 O‫ وه‬, 7AOB > ‫; ا'ت ا‬J K!
: I97$‫ ا‬.T‫ق وه‬7J ‫ث‬F„ ‫ك‬O‫ة ه‬7Z‫ز ا‬6‫ ( و‬root – left – right ) ‫ب وه‬4$‫ ا‬H%7B
.(inorder traversal ) %7‫ز ا‬61‫ ا‬.A
.(preorder traversal) H%7‫ ا‬IB8 ‫ز‬61‫ ا‬.B
.(postrder traversal) H%7‫ ا‬I/1‫ز ا‬61‫ ا‬.C
.(inorder traversal ) %7‫ز ا‬61‫ ا‬-A
: ‫@ آ‬#97$‫ن ا‬4W%‫و‬
: H%7B 9 ! TOB ‫م‬4#' O'g ? ‫ة‬7Z‫( ا‬W% + ‫إذا‬
.( ‫ب‬48‫ى )!= &!( ذات ا‬7=‫; ا‬7‫ة ا‬7Z‫ ا‬7>O; ‫رة‬9‫ ز‬-1
.‫ة‬7Z‫ر ا‬T6 ‫رة‬9‫ ز‬-2
.( ‫ب‬48‫ )!= &!( ذات ا‬QO‫; ا‬7‫ة ا‬7Z‫ ا‬7>O; ‫رة‬9‫ ز‬-3
Q.1 –Apply inorder traversal to print the tree ?
Ans :
Using Method inorder traversal :
Left : h d b e
Root : a
Right: f c g
The result : h d b e a f c g
22
.(preorder traversal) H%7‫ ا‬IB8 ‫ز‬61‫ا‬- B
: ‫@ آ‬#97$‫ن ا‬4W%‫و‬
: H%7B 9 ! TOB ‫م‬4#' O'g ? ‫ة‬7Z‫( ا‬W% + ‫إذا‬
.‫ة‬7Z‫ر ا‬T6 ‫رة‬9‫ ز‬-1
.( ‫ب‬48‫ى )!= &!( ذات ا‬7=‫; ا‬7‫ة ا‬7Z‫ ا‬7>O; ‫رة‬9‫ ز‬-2
.( ‫ب‬48‫ )!= &!( ذات ا‬QO‫; ا‬7‫ة ا‬7Z‫ ا‬7>O; ‫رة‬9‫ ز‬-3
Q.2 –Apply preorder traversal to print the tree ?
Ans :
Using Method preorder traversal:
Root : a
Left :b d h e
Right: c f g
The result :a b d h e c f g
23
.(postrder traversal) H%7‫ ا‬I/1‫ز ا‬61‫ ا‬-C
: ‫@ آ‬#97$‫ن ا‬4W%‫و‬
: H%7B 9 ! TOB ‫م‬4#' O'g ? ‫ة‬7Z‫( ا‬W% + ‫إذا‬
.( ‫ب‬48‫ى )!= &!( ذات ا‬7=‫; ا‬7‫ة ا‬7Z‫ ا‬7>O; ‫رة‬9‫ ز‬-1
.( ‫ب‬48‫ )!= &!( ذات ا‬QO‫; ا‬7‫ة ا‬7Z‫ ا‬7>O; ‫رة‬9‫ ز‬-2
.‫ة‬7Z‫ر ا‬T6 ‫رة‬9‫ ز‬-3
Q.3 –Apply postrder traversal to print the tree ?
Ans :
Using Method postrder traversal:
Left :h d e b
Right: f g c
Root : a
The result : h d e b f g c a
24
: ( Binary Search Trees (B.S.T) ) )O‫أر ا ا‬
KWZB ‫ة‬7 ‫ء‬OB ‫ آ‬Q‫Š ا‬1B ‫ة‬7Z‫ !&د ا‬7AO; ‫د‬9‫ إ‬Q; ‫ف‬7' )O‫ أر ا ا‬
. H%7!
‫ء‬8‫وف او أ‬7/ ‫م او‬C‫ أر‬Q; ‫ي‬4% ‫( ان‬W‫ة !( ا‬7Z‫ ا‬7>O; : @O%
: (Algorithm C++ Binary Search Trees) )O‫ارز! ا ا‬4?
def search_binary_tree(node, key):
if (key == data root)
"key is found"
else if (key < data root)
search left subtree
else
search Right subtree
else
"key cannot exist"
. G# ‰Š4 !‫ارز‬4 ‫ ا‬.T‫ ه‬: @O%
: ‫ة‬7Z‫ ا‬7AO; (; ‫ا‬
‫ل‬4>4‫اد ا‬7‫ ا‬7AO;1‫ ا‬Q‫ب ا‬7C1B 7>O‫ر'ت ا‬#! ‫ل‬F? (! ‫ة‬7Z‫ ا‬7AO‫ ;( ا‬B U‫ن ذا‬4W9
@!1‫ ا‬K , 7AO‫& ا ;( ا‬O; ‫ر'ت‬#‫ ;&د ا‬Q‫Š@ ا‬1B 1 ‫د ام‬464! 7AO‫ ا‬K‫ف ه‬7' :O!‫ا@ و‬
. 7‫ة اآ‬7W‫( ا‬%
25
Q.1 – Search For Key =20 , 45 , 15?
Ans:
Key =20
7>O‫ ;&د ا‬: N= 7
‫ر'ت‬#‫ ;&د ا‬: 4
‫د‬464! 7AO‫ا‬
Key =45
7>O‫ ;&د ا‬: N= 7
‫ر'ت‬#‫ ;&د ا‬: 3
‫د‬464! 7AO‫ا‬
Key = 15
26
‫‪&; : N= 7‬د ا‪7>O‬‬
‫‪&; : 4‬د ا‪#‬ر'ت‬
‫ا‪464! 7£ 7AO‬د‬
‫‪7‬ح !=‪ : G‬ا‪1‬ن ‪Z! &B‬ه&ة ال '‪ ¥/F‬ان ;( ا ;( ;‪ ‡! K!' 7AO‬ا‪ KWZB 7AO‬ا '&ء‬
‫!( ا‪T‬ر „‪#' +‬رن ذات ا‪ 7AO‬اذا آن ا‪ 7AO‬اآ‪ (! 7‬ا‪T‬ر '@ ا‪ Q‬ا( وأذا ا>‪ @' 7y‬ا‪ Q‬ا=ر‬
‫ا‪ Q‬ان '‪ KA‬ا‪ 9:' Q‬ا‪ 7Z‬أذا و‪ '&6‬ا‪ 7AO‬آن ‪ :B‬وأن ‪4#' .&' +‬ل ان ا‪464! 7£ 7AO‬د ‪7ZB‬ة ‪.‬‬
‫‪¦OB‬ء ا‪7Z‬ة ‪& =B‬ام ا ا‪:(Building tree using B. S .T) )O‬‬
‫‪4W9‬ن ذا‪%¦B U‬ع ‪ K==%‬ا‪1‬ر‪C‬م ‪ H=/ H%7! KWZB‬ا‪ ¨$‬ا=§ال ‪4W9 B‬ن ا‪ +C7‬ا‪1‬ول ه‪ 4‬ا‪T‬ر و!(‬
‫„‪Z' +‬ه& ا‪ +C7‬ا‪T‬ي ‪ @9‬و'‪#‬ر'@ ‪TB‬ر أذا اآ‪ (! 7‬ا‪T‬ر '@ ا‪ Q‬ا( وأذا أ>‪=9 @' 7y‬ر ‪ ,‬و'‡‬
‫ذ‪V‬ت ا‪481‬ب ا‪ Q‬ان '‪OB (! :O‬ء ا‪7Z‬ة ‪Z! &O; ًJ ,‬ه&ة ا‪ @!1‬وا‪ ‰E% I$‬اآ‪ 7‬ا‪7W‬ة‪.‬‬
‫‪ UO! H$9 ! F‬أ;دة‬
‫;‪OB &O‬ء ‪7‬ة ‪ H$9‬ا‪7% 7!1‬آ* ‪1‬ن ;‪ &O‬ا?‪F‬ف ;‪ 7AO‬وا‪ 7y% &/‬ا‪7Z‬ة !ُ ً‬
‫ا‪ .7! BW‬ا?‪7‬ا او ا‪4C4‬ع ا ‪$‬ء ‪.‬‬
‫‪27‬‬
: )O‫= &ام ا ا‬B ‫ة‬7Z‫¦ء ا‬OB Q; @!‫أ‬
Q.1 – Building Binary Search Trees with the data set: 50, 60, 40, 30, 20, 45, 65 ?
Ans :
28
Q.2 – Building Binary Search Trees with the data set: 10, 20, 30, 40, and 50?
: ( Deletion& insert) ‫ة‬7Z‫ات ا‬
: ‫ ا‬4O‫ ا‬Q; ‫ة ه‬7Z‫ ا‬:)‫ا‬76¦B ‫م‬4#' ‫ز ات ا‬7B‫أ‬
. 7AO; Š‫ ا‬-1
. 7AO; ‫ف‬T/ -2
: ( Add or insert ) Š‫ ا‬-1
7AO‫ ا ;( ا‬9:' &O; O‫( ه‬W 7AO; (; ‫& ا‬O; @#97$‫ع '¬ ا‬%¦B 7AO; Š¦B U‫وذا‬
. ‫ة‬7Z @Š‫اد أ‬7‫ ا‬7AO‫¦Š ا‬B ‫م‬4#'
29
Q.1 –How to Add insert ,1 element X= 62 to B.S.T ?
30
: ( Deletion ) ‫ف‬T‫ ا‬-2
‫م‬4#' ‫اد‬7‫ ا‬7AO ‫ل‬4>4‫& ا‬O; O‫( ه‬W 7AO; (; ‫& ا‬O; @#97$‫ع '¬ ا‬%¦B 7AO; ‫ف‬TB U‫وذا‬
. ‫ة‬7Z‫@ !( ا‬TB
Q.1 –How to Deletion, element in Tree : Deletion X, G and D to B.S.T ?
31
32
CH. 4
‫اب ا ا‬
Graphs
‫ات ا‬
‫" ا! ب وا‬#$ %&' ‫ م‬#)‫* ا‬+ ,$ -. ‫ل هم‬1+ 2!‫ ا‬34 ‫ ا‬-. ‫ ات ا‬5)'
. ‫ء‬7‫د وا‬954:‫" ا‬#$‫ و‬7‫ا‬
: ‫;م ات ا‬4‫أ‬
: (directed Graph) @ ‫ ا‬-‫ ا‬A‫ ا‬- A
: ‫ ا)م‬%7&‫ا‬
. ‫ ا)م‬%7&‫ ا‬. ) -I57
: (Undirected Graph) @ + K‫ ا‬-‫ ا‬A‫ ا‬- B
: ‫ ا)م‬%7&‫ا‬
. ‫ب‬57‫* ا‬+ %9I‫ ا‬NO‫ ه‬P ‫ درا‬R#$ "5, ‫ي‬O‫ ا‬%7&‫وه ا‬
: +)‫ رة ا‬9‫ا‬
G=[V,E]
. -‫ ا‬A‫ ا‬:G
. -‫ ا‬A‫ ا‬V$ -‫ ه‬:V
.edges V)‫ * ا‬R#V ‫ ا ط ا‬-‫ ه‬:E
Q.1 – Find the components of the chart the following?
Ans :
G=(V,E)
V={a,b,c,d}
E={(a,b),(b,c),(b,d),(a,c),(c,d) }
N=|| V || = 4 vertices
M=|| E ||= 5 edges
33
: (Paths and Cycles) ‫ا;رات واورات‬
:(Paths) ‫ا;رات‬
‫ا‬O‫ار ه‬P+‫ ل و‬r ‫;ر‬+ %7 ‫ ن‬7,‫ و‬9$ %‫ ن * آ‬7' -5‫ ا‬#95‫ ا ا ط ا‬-P5#' -5‫ ا‬V)‫ ا‬-‫ه‬
u‫ ا‬9$ *+ %9' u5v ‫ج‬5!' ‫;ر‬+ "‫ آ‬x‫و) أ‬.‫ ا;ر‬-. V)‫ * ا‬%V ‫ ا ط ا‬-‫ا ل ه‬
. -‫ ا‬A‫ ا‬-. 9$
:(Cycles) ‫اورات‬
, -. 9)‫ ا;ر ه ذات ا‬,‫ ا‬-. 9)‫ أن ا‬zv -‫ ا‬A‫ ا‬-. P#K‫د ا;رات ا‬$ -‫ه‬
.Cycles ‫{ أو دورة‬#K+ ‫;ر‬+ , ‫ ن‬7' ‫ا;ر‬
Q.1 –Some list Paths from a to c ?
Ans :
Path
(a,c)
(a,b),(b,c)
(a,b),(b,d),(d,c)
length
1
2
3
Q.2 –Some list Cycle in Graph ?
Ans :
Path
a,b,c,a
d,b,c,d
a,b,d,c,a
length
3
3
4
34
: !‫ ا‬-. ‫ ات ا‬%€'
: ‫ ن ذا‚ )ت ا أ زه‬7,‫و‬
: (incidence matrix) . I9‫ ا‬-1
‫ر‬P ‫ م‬P R. I9‫ ء ا‬$ ‫ت أن‬. I9‫ام ا‬5 ‫ ات ا‬%€' „2 5 ‫ رة‬V A;‫أ‬
* ‫;ر‬+ @ ,: 0 ‫* وأن‬, 9)‫;ر * ا‬+ ‫ و@ د‬u#$ ‫ل‬, ‫ا‬O‫ ه‬1 @‫ أن و‬R. I9‫ة ا‬$‫ ف وا‬IV
. *, 9)‫ا‬
Q.1 – Representation Graph to using incidence matrix ?
Ans :
0 Š ‫;ر أذًا‬+ @ ,: a ‫ و‬a ‫ ف‬I9‫ة وا‬$:‫رن * ا‬P {;‫ ا‬-. ‫ آ ذآ‬: %!‫ ا‬4 r
. ŒO7‫ وه‬... 1 Š ‫;ر أذًا‬+ @ , b ‫ و‬a ‫ر‬P+ $‫و‬
Q.2 – Representation Graph to using incidence matrix ?
Ans:
35
:(Adjacency List structure) -2
Q.1 – Representation Graph to using Adjacency List ?
Ans :
Q.2 – Representation Graph to using Adjacency List ?
Ans :
36
: (complete graph ) ‫ ا)م‬-‫ ا‬A‫ ا‬-3
If there is edge between every 2 Vertices
.(Subgraph) ‘1‫ ات ا‬-4
: +)‫ رة ا‬9‫ا‬
Ex_1:
37
Weighted Graphs and the Minimum Spanning Tree (MST):
: ‫ ة ا ة‬1& u‫ا م ا ا زون وا! ا•د‬
. edges ‫ ع أوزان‬1+ ‫ وه‬: (Weighted Graphs) -‫ ا‬A‫وزن ا‬
Q.1 –Find Weighted by graph ?
Ans :
N= 6
M=10
W(g)=430
: (Minimum Spanning Tree (MST)) ‫ ة ا ة‬1& u‫ا! ا•د‬
@‫( و‬prim) ", P, r ‫( و‬krukel) ‫ل‬7‫ آ و‬P, r ‫* ه‬5P, r ‫ هك‬, ‫ ة ا ة ا‬1&‫د ا‬1,•
. (MST) ‫ ة ا ة‬1& ‫د‬:‫ ض وه إ@د ا! ا‬K‫œ ا‬I u‫* 'دي ا‬5P, ‫ا‬
38
: (krukel) ‫ل‬7‫ آ و‬P, r -1
$‫ " @ وا زن و‬M V)‫ * ا‬%V ‫ ط ا‬x ‫د‬$ " n V)‫د ا‬$ @ :ً ‫ او‬: P, ‫Ÿ ح ا‬
' ' R' + ‫وزان‬:‫ ن ا‬7' ‫ ان‬1,‫ و‬P#K+ ‫ ن‬7' : R ‫ ا‬-. -‫" ان ا'¡ ا‬#)' ‫ ان‬1, " ‫ا‬
. ‫ ح‬2‫ ن اآ€ و‬7'‫ ة و‬7I‫ ا‬%V ' R#€+:‫ ا‬%!‫ و‬m=n-1 ‫ ن‬7' ‫ ان‬u‫ ا‬R.2: , ‫ي‬$9'
Krukel algorithm to find MST :
Input :
G: a comneted weighted graph .
Output :
T : a MST of G .
1- the edges by weighted in Ascending order .
2- start with T heving all the vertices without any edges .
3- K=1 .
4- while K<=n-1 //a MST has n-1 edges .
T=T U {e} vadd e to T
K=k+1
Q.1: Find a weighted MST by :
F =(1,3),(4,6), (2,5),(3,6), (1,4),(3,4), (2,3),(5,6), (3,5)
Wt :10,20,30,40,50,50,50,60,60,60
Ans :
Wt : 150
39
Q.2: Apply Krukel to find a MST ?
Ans :
N=6
M=9
W(g)=170
F: (1,2),(6,1), (6,4),(6,5), (2,3), (5,4),(1,4), (1,3),(4,3).
Wt : 5,10,10,15,15,20,30,30,30,35
W(G)= 55
: (prim) ", P, r -2
Prim algorithm to find MST :
Input :
G: (V,E) , a comneted weighted graph .
Output : a MST of G
1- start with any vertices V .
2- V1={V} , T= .
v)
3- while (v1
v1& y
# let e =(x,y) : x
# V1 = v1 U {y}
# T=TU {(x,y)}
v1
40
Q.1: Apply Prim to find a MST ?
Ans :
N=6
M=9
W(g)=170
V=1
V1={1} , T=
W(G)= 55
41
42
‫‪CH.5‬‬
‫اب ا‪œ+‬‬
‫‪Logic Math .‬‬
‫ا{ ا ‪-2,‬‬
‫ا{ ا ‪ *+ -2,‬أ‪ 5+‬ا)‪ #‬م ن و@«ء و ‪&+ %v‬آ‪ #‬و‪ ' :‬ع ‪ 4 u#$‬ا‪, K5' : R5 $‬‬
‫و‪ -.‬ه‪O‬ا اب ‪ P‬م ‪ "7$‬ا‪ P‬ا‪ $‬ا‪ :‬ا‪ @ %v %;5 5. )+ ) *+ u5‬ا;‪ %‬ا‪P#)5‬‬
‫‪O‬ا ا‪. %9I‬‬
‫ر‪ +‬ز ا{ ا ‪: -2,‬‬
‫ا ‪‘+‬‬
‫ا ¬‪ I‬أو ا)‪#‬‬
‫" ‪ " Not‬ا‪ œ7)' -), -I‬ا‪ 9‬اب و)‪œ7‬‬
‫‪ OR‬ا‪5‬‬
‫‪ And‬ا)®‬
‫‪$ -), If…..then‬ر‪ &+ N‬و‪r‬‬
‫‪$ -), If and only‬ر‪  N‬ا& ط‬
‫آ® ‪ + %+)5‬ه‪ NO‬ا ‪ +‬ز ؟ !‪ %‬ا‪ #€+:‬و‪ Ÿ " *+‬ح آ‪ %P)# u;5, u5v R#$ %‬أدراآ ‪.‬‬
‫و‪ %4 *7‬أن Š ا‪ 1, #€+:‬أن أ‪ x‬ك ‪‘,‘$‬ي أن ‪+‬ه ‪ @ +‬د ‪ -.‬ا‪1‬ول ه‪ 1+ -‬د ر‪ +‬ز و¬‪ 5I‬و‪*7‬‬
‫‪+‬ذا ‪ *$‬ا‪Ÿ:‬ء ا‪ #$ OI -5‬ه‪ NO‬ا)‪#‬ت و‪+‬ذا ‪ -. . ) $ ¡5,‬ا‪. ,O!5‬‬
‫'‪ 1‬ي ‪‚#' #$‬‬
‫ه‪ NO‬اه" @‘‪ 5. )+ 1, R‬أن هك ‪ K5+3 AP.‬ات وه‪-‬‬
‫ا)‪#‬ت و'‪ AP. ‚ ¡5‬أ‪ T +‬أو ‪ „V , -), F‬أو ‪x‬ء ‪ r‬د «ث ‪ K5+‬ات ؟ ‪ -. :‬ا‪*, K5+ K‬‬
‫وه‪ -‬ا‪ Ÿ:‬و‪ + *7‬ا‪O‬ي ‪ -. ®#5,‬ا!‪ %‬أن آن «ث أو أ ن ه‪O‬ا ‪ 2 + -. „2‬ع آ® '€‪.7' 3‬ا‬
‫‪5 P+ 4«$‬ام ا‪1‬ول ‪.‬‬
‫ا‪:‬ن أ‪@ ‚,, * 2‬ول آ‪: #$ %‬‬
‫'!‪ / ²I‬و‪ -7‬أ‪ ‚#$ %‬ا!‪ ²I‬ال ‪ Not‬أ‪ ".‬أ ا)‪ œ7‬و ‪Or‬أ ‪ +‬آ‪$ + T -Ÿ %‬ى ‪FF‬ب‪F‬أ‪+‬‬
‫‪ +and‬آ‪$+ F -Ÿ %‬ى ‪T T +‬ب‪T‬‬
‫‪43‬‬
‫ا ات ا‪: P‬‬
‫‪Not‬‬
‫‪And‬‬
‫‪Or‬‬
‫‪----------------------------------------------------------------------------------------------------‬‬‫‪ /²Iv‬و‪ u5v‬أ‪ ‚#$ %‬ا!‪ Ÿ ²I‬ف  ا& ط ‪ )+‬أن أذا أ'‪ -), PI‬ب ‪T‬و ‪T -),T‬وأ‪F Š,‬و ‪F‬‬
‫‪ : RT -),‬ا'‪ PI‬أرآ‘ ‪ #$‬أ‪ +‬أذا أ‪ I#5x‬ب ‪.F‬‬
‫أ‪ -. +‬ا& و‪ #$ + #$ r‬م رآ‘ ‪ Ÿ -)+‬ي ' وح ‪ K5#‬ا‪O‬ي ‪ R R15,‬ا;" و'!‪ A‬آ‪ V %‬اب ‪-. R.‬‬
‫@ول ا'¡ " ' وح ‪ K5#‬ا‪ R+ r -‬ا;" و'& ف ه‪ + {I5+ %‬ا‪ -‬أ‪ R++‬ا‪ -#‬ه ‪q K5+‬إذا ه‬
‫‪@ -. Š' R)+ {I5+‬ول ا‪ V ¡5‬اب أ‪ +‬إذا أ‪x Š5. ®#5x‬ء ‪.‬‬
‫ا& و‪r‬‬
‫ ا& ط‬
‫هك ‪ K5+‬ان أو «ث ‪ ®#5,‬ذا‚ ‪ 3€' +$‬أو '&‪u‬ء ‪ * 4«$‬ا‪ K5‬ات ‪ -.‬ا‪1‬اول ‪:‬ن هك ‪ 4‬ن‬
‫هم وه أن ‪$‬د أ‪:5v‬ت ا‪ 9‬اب واء )ا‪ -5‬ه‪P ,q -‬وا‪:‬ن ‪;, ( v %x‬وي ‪2‬أس ‪$‬د ا‪ K5‬ات ‪,‬‬
‫‪ -. -),‬ا‪1‬اول ا‪ -. -5‬ا‪ u#$:‬ه‪ ¶v: %‬ذا @ول ‪ AP. not‬أ‪:5v‬ن ‪:‬ن هك ‪ K5+‬وا‪AP. v‬‬
‫و‪ P‬ن ‪ „9,‬ا‪1‬ول ‪2‬أس وا‪ 2 = v‬أي أ‪:5v‬ن وه‪O7‬ا ‪ -.‬ا‪1‬ول ‪and‬و ‪ Or‬أو أي @ول ‪#,‬‬
‫‪ P' ‚+‬ل ‪$‬د ا‪ K5‬ات آ" و'Š) آ وس ‪2 %‬وا'¡ ه ‪$‬د ا‪:5v:‬ت ‪.‬‬
‫‪44‬‬
Q:1 Show that :
Ans.
Q:2 Show that :
Ans.
Q:3 Show that :
Ans.
45
: {‫ ا‬-. ‫ت‬P'
:( Logic Equivalent
) ‫ا‬.75‫(_ ا‬1
-7 *5P, r‫ أو‬u#$ ‫ م‬P' -‫ا ) ( وه‬.75‫‘ ا‬+‫ ر‬-‫ ; وه‬N‫د‬,‘ AP. 5v Ÿ -5‫ر ا‬7.:‫œ ا‬I -‫ه‬
. *‫ ا‬P‫ام ا‬5 €‫ول وا‬1‫ام ا‬5 u‫و‬:‫·ن ا‬.75+ ‫ن‬. ‫ أن ا‬3€'
: ‫اول‬1‫ام ا‬5 _(A
Ex:4 Show that using Table :
Ans.
Ex:5 Show that using Table :
46
: {‫ ا* ا‬4 ‫ام‬5 _(B
Q.6_ show that using method:
47
: Tautology & contradiction _( 2
. ‫ اب‬V ‫ ن‬7' ‫ د‬u) -‫ ه‬:(
. x ‫ ن‬7' ‫ د‬u) -‫ ه‬:(
)Tautology
)contradiction
Ex:1_ show that:
Ans.
: Principle & Duality _( 3
u‫ اب ا‬V %‫وآ‬, „!V œ7)‫ وا‬or u‫ ا‬and %‫œ آ‬7)' ‫أ ا€ وه أن‬+ ‫ ه‬: % ‫ م @ا‬I‫ا ا‬O‫ه‬
. œ7) œ7)‫ وا‬x
Ex:1_ show that:
Ans:
48
References:
1- Discrete mathematics with applications, 3rd Edition by Susanna S. Epp
2-Discrete Structures, Logic, and Computability, Third Edition
James L. Hein, Portland State University
3-Discrete Structures, Logic, and Computability, Second Edition byJones .
4-Theory and Problems of discrete mathematics third edition seymourlipschutz,
ph.d
bindajan@windowslive.com
49
‫‪ 'x‬ا‪57‬ب ‪:‬‬
‫ه‪O‬ا ا‪57‬ب Œ@)‪ R@ 9x ¼ R#‬ا‪ ", 7‬و¼ ا! أو‪ :‬وŒ‪ x‬ا و¬ه ا و‪v r‬ا آ€ ا ‪+ r‬رآ ‪ R.‬آ‬
‫‪ !,‬ر و‪ -9! : R! u2 ,‬ء ‪ R#$‬ه آ أ ‪ R;I u#$ u‬و‪ u#V‬ا¼ ‪ !+ u#$‬‬
‫ا•و* وا½‪ *, x‬وأآ م ا;‪ *P‬وا«‪ *Pv‬و‪ @ u#$‬إ‪ x‬ا‪ R‬ا* وا ‪ *#‬وŒل آ‪ %‬و ا‪*!9‬‬
‫ور‪ -2‬ا¼ ‪ *$‬د' و‪4‬د' أ‪!V‬ب ر ل ا¼ أ@)* و‪ *$‬ا)‪#‬ء ا)‪ *#+‬و‪ #$ *$‬و‪&+‬‬
‫وأ‪ 5‬أ اى وا‪.*,‬‬
‫‪Copyright ©BinDajan 2010‬‬
‫‪50‬‬
Download