Algorithm 1
Dr Benabderrezak
Researcher in Cyber Security
Full-stack Web developer 1
Workplan
1. What is an Algorithm ?
2. Variables and Constants
3. Data Types / Operators
4. Input / Output
5. Conditions / Loops
6. Arrays (1-D , 2-D)
7. Strings
8. Structures (Structs)
9. Functions
2
2
Introduction
3
4
4
Inputs
Refer to the data that is read by the algorithm from an external source, such as keyboard
input
ﻣﺜﻞ ﻣﺪﺧﻼت ﻟﻮﺣﺔ اﻟﻤﻔﺎﺗﯿﺢ،اﻟﺒﯿﺎﻧﺎت اﻟﺘﻲ ﺗﻘﺮأھﺎ اﻟﺨﻮارزﻣﯿﺔ ﻣﻦ ﻣﺼﺪر ﺧﺎرﺟﻲ
5
Output
The output of an algorithm defines the results that must be achieved upon its completion
ﯾﺤﺪد ﻧﺎﺗﺞ اﻟﺨﻮارزﻣﯿﺔ اﻟﻨﺘﺎﺋﺞ اﻟﺘﻲ ﯾﺠﺐ ﺗﺤﻘﯿﻘﮭﺎ ﻋﻨﺪ اﻛﺘﻤﺎﻟﮭﺎ
6
Basic structure
7
Basic structure
8
Characteristics of an Algorithm
ﺧﺼﺎﺋﺺ اﻟﺨﻮارزﻣﯿﺔ
9
Characteristics of an algorithm ?
● Clear and Unambiguous واﺿﺢ ﻻ ﻟﺒﺲ ﻓﯿﮫ
Each of its steps should be clear in all aspects and must lead to only one meaning.
.وﯾﻨﺒﻐﻲ أن ﺗﻜﻮن ﻛﻞ ﺧﻄﻮة ﻣﻦ ﺧﻄﻮاﺗﮭﺎ واﺿﺤﺔ ﻣﻦ ﺟﻤﯿﻊ اﻟﺠﻮاﻧﺐ وأن ﺗﻔﻀﻲ إﻟﻰ ﻣﻌﻨﻰ واﺣﺪ ﻓﻘﻂ
11
Characteristics of an algorithm ?
● Well-Defined Inputs ﻣﺪﺧﻼت ﻣﺤﺪدة ﺟﯿﺪًا
Algorithm’s inputs should be well-defined
ﯾﺠﺐ أن ﺗﻜﻮن ﻣﺪﺧﻼت اﻟﺨﻮارزﻣﯿﺔ ﻣﺤﺪدة ﺟﯿﺪًا
12
Characteristics of an algorithm ?
● Well-Defined Outputs ﻣﺨﺮﺟﺎت ﻣﺤﺪدة ﺟﯿﺪًا
The algorithm must clearly define what output will be yielded and it should be well-defined
as well
.ﯾﺠﺐ أن ﺗﺤﺪد اﻟﺨﻮارزﻣﯿﺔ ﺑﻮﺿﻮح اﻟﻤﺨﺮﺟﺎت اﻟﺘﻲ ﺳﯿﺘﻢ ﺗﺤﻘﯿﻘﮭﺎ وﯾﺠﺐ أن ﺗﻜﻮن ﻣﺤﺪدة ﺟﯿﺪًا أﯾﻀًﺎ
13
Characteristics of an algorithm ?
● Finiteness اﻻﻧﺘﮭﺎء
The algorithm must be finite, i.e. it should terminate after a finite time
أي ﯾﺠﺐ أن ﺗﻨﺘﮭﻲ ﺑﻌﺪ وﻗﺖ ﻣﺤﺪود،ﯾﺠﺐ أن ﺗﻜﻮن اﻟﺨﻮارزﻣﯿﺔ ﻣﺤﺪودة
14
Characteristics of an algorithm ?
● Feasible ﻗﺎﺑﻞ ﻟﻠﺘﻨﻔﯿﺬ
The algorithm must be simple, generic, and practical, such that it can be executed with the
available resources
ﯾﺠﺐ أن ﺗﻜﻮن اﻟﺨﻮارزﻣﯿﺔ ﺑﺴﯿﻄﺔ وﻋﺎﻣﺔ وﻋﻤﻠﯿﺔ ﺑﺤﯿﺚ ﯾﻤﻜﻦ ﺗﻨﻔﯿﺬھﺎ ﺑﺎﻟﻤﻮارد اﻟﻤﺘﺎﺣﺔ
15
Characteristics of an algorithm ?
● Language Independent ﻟﻐﺔ ﻣﺴﺘﻘﻠﺔ
The Algorithm must be just plain instructions that can be implemented in any language, and
yet the output will be the same
وﻣﻊ ذﻟﻚ ﺳﯿﻜﻮن اﻟﻤﺨﺮج ھﻮ ﻧﻔﺴﮫ،ﯾﺠﺐ أن ﺗﻜﻮن اﻟﺨﻮارزﻣﯿﺔ ﻣﺠﺮد ﺗﻌﻠﯿﻤﺎت واﺿﺤﺔ ﯾﻤﻜﻦ ﺗﻨﻔﯿﺬھﺎ ﺑﺄي ﻟﻐﺔ
16