Algo 10
Algo 10
أ حمد تم ول ي
(program memory structure) Code Segment
Program Memory
PrintName("Ahmed","Metwally");
first, last
Stack
011110101010100000101
001010101101011100110
Code 010101010101011100110
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
(a function that calling herself) Recursion
using System;
class Program {
Program Memory
return num * Factorial(num -1); Factorial: num=1
}
}
Factorial: num=2
public static void Main (string[] args) {
Console.WriteLine( Factorial(4) );
} Factorial: num=3
}
Console.WriteLine( Factorial(4)
24 ); Factorial: num=4
Factorial(4) = 4 * Factorial(4-1)
6 Stack
Factorial(4-1) = 3 * Factorial(3-1)
2
011110101010100000101
001010101101011100110
Factorial(3-1) = 2 * Factorial(2-1)
1 Code 010101010101011100110
Factorial(2-1) = 1
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
Merge Sort
9 5 1 4
9 5 1 4
9 5 1 4
5 9 1 4
1 4 5 9
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
Merge Sort
6 5 12 10 9 1
6 5 12 10 9 1
6 5 12 10 9 1
5 12 9 1
5 12 1 9
5 6 12 1 9 10
6 5 12 10 9 1
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
(How merge done #01) Merge Sort
10 1 9
10 1 9 1
10 1 9 1 9
10 1 9 1 9 10
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
(How merge done #02) Merge Sort
5 6 12 1 9 10
5 6 12 1 9 10 1
5 6 12 1 9 10 1 5
5 6 12 1 9 10 1 5 6
5 6 12 1 9 10 1 5 6 9
5 6 12 1 9 10 1 5 6 9 10
5 6 12 1 9 10 1 5 6 9 10 12
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
(How merge done #03) Merge Sort
8 10 14 1 7
8 10 14 1 7 1
8 10 14 1 7 17 7
8 10 14 1 7 1 7 8 10 14
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
(Algorithm) Merge Sort
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ
(Algorithm #02 merge only) Merge Sort
أ حمد تم ول ي Algorithms Analysis and Design from scratch ﻣﻦ ﺗﺤﺖAlgorithms ﲓ ﺗﺤﻠﻴﻞ وﺗ