SlideShare une entreprise Scribd logo
1  sur  224
Télécharger pour lire hors ligne
ALGORITHMS AND
DATA STRUCTURE
‫المعطيات‬ ‫وبنى‬ ‫الخوارزميات‬ ‫محور‬
By Eng. Joud Khattab2020
Content
■ OOP. (‫التوجه‬ ‫غرضية‬ ‫)البرمجة‬
■ Complexity. (‫)التعقيد‬
■ Recursive Functions. ( ‫التوابع‬‫العودية‬ )
■ Data Structure: (‫المعطيات‬ ‫)بنى‬
– Sequential: Linked List, Stacks, Queue.
– Non Sequential: Tree, Graph.
■ Sort & Search Algorithms. (‫والترتيب‬ ‫البحث‬ ‫)خوارزميات‬
■ Advance Algorithms Methods (‫متقدمة‬ ‫)خوارزميات‬
– Greedy, Backtracking, Dynamic, Divide & Conquer.
■ Hashing Function. (‫التقطيع‬ ‫)توابع‬
■ MCQ. (‫)اختبارات‬
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
■‫مسألة‬ ‫حل‬ ‫خوارزمية‬
–‫البسي‬ ‫العمليات‬ ‫من‬ ‫منتهية‬ ‫متتالية‬ ‫شكل‬ ‫على‬ ‫الحل‬ ‫لطريقة‬ ‫صوري‬ ‫توصيف‬ ‫هي‬‫تنفذ‬ ،‫طة‬
‫محدد‬ ‫تسلسل‬ ‫حسب‬.
■‫البرنامج‬
‫الحاسوب‬ ‫يقبلها‬ ‫التي‬ ‫البرمجة‬ ‫لغات‬ ‫بإحدى‬ ‫معينة‬ ‫مسألة‬ ‫حل‬ ‫لخوارزمية‬ ‫توصيف‬ ‫هو‬.
■‫البرمجة‬ ‫لغة‬
–‫يمك‬ ‫برنامج‬ ‫بكتابة‬ ‫تسمح‬ ‫التي‬ ‫المعرفة‬ ‫والدالالت‬ ‫والقواعد‬ ‫المفردات‬ ‫من‬ ‫مجموعة‬ ‫هي‬‫ن‬
‫الحاسوب‬ ‫على‬ ‫تنفيذه‬.
■‫المترجم‬
–‫م‬ ‫مكافئ‬ ‫برنامج‬ ‫إلى‬ ‫ويحوله‬ ،‫معينة‬ ‫برمجة‬ ‫بلغة‬ ‫المكتوب‬ ‫البرنامج‬ ‫يفهم‬ ‫برنامج‬ ‫هو‬‫كتوب‬
‫بالمعالج‬ ‫الخاصة‬ ‫المجمع‬ ‫بلغة‬‫الصغري‬‫للحاسوب‬.
2020 By Eng. Joud Khattab
OBJECT ORIENTED
PROGRAMMING (OOP)
‫التوجه‬ ‫غرضية‬ ‫البرمجة‬
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
■‫الفئة‬ ‫أو‬ ‫الصف‬(class)
–‫ودوال‬ ‫متغيرات‬ ‫من‬ ‫الكود‬ ‫كل‬ ‫تحتوي‬ ‫أن‬ ‫تستطيع‬ ‫كبيرة‬ ‫حاوية‬ ‫عن‬ ‫عبارة‬ ‫الصف‬
‫إلخ‬ ‫وكائنات‬...
■‫الغرض‬ ‫أو‬ ‫الكائن‬(object)
–‫معين‬ ‫لصف‬ ‫مطابقة‬ ‫نسخة‬ ‫عن‬ ‫عبارة‬ ‫الكائن‬.
–‫صف‬ ‫هناك‬ ‫يكن‬ ‫لم‬ ‫إذا‬ ‫كائن‬ ‫إنشاء‬ ‫يمكن‬ ‫ال‬ ‫إنه‬ ‫القول‬ ‫يمكننا‬.
–‫يسمونه‬ ‫معين‬ ‫صف‬ ‫بإنشاء‬ ‫نقوم‬ ‫الكائنات‬ ‫برمجة‬ ‫مفهوم‬ ‫في‬(blue print)‫أي‬
(‫األصلية‬ ‫النسخة‬ ‫أو‬ ‫الخام‬ ‫النسخة‬)‫الصف‬ ‫هذا‬ ‫من‬ ‫أكثر‬ ‫أو‬ ‫نسخة‬ ‫ننشئ‬ ‫وبعدها‬ ،.
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
■‫الخصائص‬(instance variables)
–‫ه‬ ‫في‬ ‫الموجودة‬ ‫المتغيرات‬ ‫من‬ ‫به‬ ‫خاصة‬ ‫نسخة‬ ‫يملك‬ ‫معين‬ ‫صف‬ ‫من‬ ‫ننشئه‬ ‫كائن‬ ‫كل‬‫ذا‬
‫الصف‬.
–‫بالخصائ‬ ‫تسمى‬ ‫ما‬ ‫هي‬ ‫الصف‬ ‫من‬ ‫كائن‬ ‫لكل‬ ‫منها‬ ‫نسخة‬ ‫إعطاء‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬‫ص‬.
■‫الدوال‬(methods)
–‫باستدعائه‬ ‫تقوم‬ ‫عندما‬ ‫فقط‬ ‫يتنفذ‬ ‫جاهز‬ ‫كود‬ ‫عن‬ ‫عبارة‬ ‫الدالة‬.
■‫نوعين‬ ‫البيانات‬:
–‫البدائية‬ ‫البيانات‬(primitive data types:)‫كال‬byte – short – int – long – float – bool
–‫المرجعية‬ ‫البيانات‬(reference/object data types:)‫الكلمة‬ ‫له‬ ‫نضع‬ ‫نوع‬ ‫وأي‬ ‫كالكائنات‬
new‫تعريفه‬ ‫عند‬.
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
■‫البناء‬ ‫أو‬ ‫المشيد‬ ‫التابع‬(constructor)
–‫ا‬ ‫للخصائص‬ ‫أولية‬ ‫قيم‬ ‫لتوليد‬ ‫كائن‬ ‫إنشاء‬ ‫أثناء‬ ‫استدعائها‬ ‫يتم‬ ،‫خاص‬ ‫نوع‬ ‫لها‬ ‫دالة‬ ‫عن‬ ‫عبارة‬‫لموجودة‬
‫فيه‬.
■‫ال‬ ‫حول‬ ‫مهمة‬ ‫نقاط‬constructor
–‫على‬ ‫يحتوي‬ ،‫إنشاءه‬ ‫يتم‬ ‫صف‬ ‫كل‬constructor‫األقل‬ ‫على‬ ‫واحد‬.‫أي‬ ‫بتعريف‬ ‫تقم‬ ‫لم‬ ‫إن‬ ‫وحتى‬
constructor‫عنك‬ ‫افتراضي‬ ‫واحد‬ ‫بإنشاء‬ ‫المترجم‬ ‫سيقوم‬.
–‫استدعاء‬ ‫يجب‬ ،‫جديد‬ ‫كائن‬ ‫إنشاء‬ ‫يتم‬ ‫مرة‬ ‫كل‬ ‫في‬constructor‫الكائن‬ ‫هذا‬ ‫إنشاء‬ ‫يتم‬ ‫حتى‬.
–‫تعريف‬ ‫عند‬ ‫األساسية‬ ‫القاعدة‬constructor‫نوعه‬ ‫ويكون‬ ‫الصف‬ ‫اسم‬ ‫نفس‬ ‫يحمل‬ ‫أن‬ ‫يجب‬ ‫أنه‬ ‫هي‬
public
–‫بتعريف‬ ‫قمت‬ ‫حال‬ ‫في‬constructor‫هناك‬ ‫يعود‬ ‫لن‬ ‫أي‬ ،‫افتراضي‬ ‫واحد‬ ‫بإنشاء‬ ‫المترجم‬ ‫يقوم‬ ‫لن‬
default constructor
–‫من‬ ‫أكثر‬ ‫تعريف‬ ‫يمكنك‬constructor.‫إنشاء‬ ‫دائما‬ ‫ويمكنك‬constructor‫إن‬ ‫تستخدمه‬ ‫حتى‬ ،‫فارغ‬
‫كائن‬ ‫إنشاء‬ ‫عند‬ ‫للخصائص‬ ‫محددة‬ ‫أولية‬ ‫قيم‬ ‫إعطاء‬ ‫تريد‬ ‫ال‬ ‫كنت‬.
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
■‫أساسية‬ ‫فئات‬ ‫ثالث‬ ‫إلى‬ ‫تقسم‬ ‫الصف‬ ‫في‬ ‫وضعها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬:
–Local variables:‫دالة‬ ‫أي‬ ‫بداخل‬ ‫تعريفها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬ ‫هي‬.
–Instance variables:‫حدود‬ ‫وخارج‬ ‫الكالس‬ ‫بداخل‬ ‫تعريفها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬ ‫هي‬
‫دالة‬ ‫أي‬.
–Class variables:‫ك‬ ‫تعريفها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬ ‫هي‬static‫الكالس‬ ‫بداخل‬.‫وخارج‬
‫دالة‬ ‫أي‬ ‫حدود‬.
2020 By Eng. Joud Khattab
Definitions (‫)تعاريف‬
■‫مفهوم‬superclass‫و‬subclass
–‫يسمى‬ ‫أخر‬ ‫صف‬ ‫من‬ ‫يرث‬ ‫الذي‬ ‫الصف‬subclass‫أيضا‬ ‫ويسمى‬(derived class‫او‬
extended class‫او‬child class)
–‫يسمى‬ ‫أخر‬ ‫لصف‬ ‫محتوياته‬ ‫يورث‬ ‫الذي‬ ‫الصف‬superclass‫أيضا‬ ‫ويسمى‬(base class
‫او‬parent class)
■‫مفهوم‬super
–‫ال‬ ‫في‬ ‫الموجودة‬ ‫والدوال‬ ‫المتغيرات‬ ‫بين‬ ‫للتمييز‬ ‫تستخدم‬superclass‫و‬subclass
‫الصفين‬ ‫كال‬ ‫في‬ ‫مستخدمة‬ ‫األسماء‬ ‫كانت‬ ‫حال‬ ‫في‬.
–‫ال‬ ‫في‬ ‫الموجود‬ ‫المشيد‬ ‫الستدعاء‬ ‫تستخدم‬superclass
2020 By Eng. Joud Khattab
Question 1
■‫الصفوف‬ ‫استخدام‬ ‫بدون‬ ‫البرامج‬ ‫في‬ ‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫مفهوم‬ ‫تطبيق‬ ‫يمكن‬
.A‫صح‬
.B‫خطأ‬
2020 By Eng. Joud Khattab
Question 1
■‫الصفوف‬ ‫استخدام‬ ‫بدون‬ ‫البرامج‬ ‫في‬ ‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫مفهوم‬ ‫تطبيق‬ ‫يمكن‬
.A‫صح‬
.B‫خطأ‬
2020 By Eng. Joud Khattab
Question 2
■‫الصفوف‬ ‫في‬ ‫الموجودة‬ ‫اإلضافية‬ ‫الخاصية‬ ‫هي‬ ‫ما‬(classes)‫البنية‬ ‫في‬ ‫موجودة‬ ‫وليست‬
(struct)
A. Data members
B. Member functions
C. Static data allowed
D. Public access specifier
2020 By Eng. Joud Khattab
Question 2
■‫الصفوف‬ ‫في‬ ‫الموجودة‬ ‫اإلضافية‬ ‫الخاصية‬ ‫هي‬ ‫ما‬(classes)‫البنية‬ ‫في‬ ‫موجودة‬ ‫وليست‬
(struct)
A. Data members
B. Member functions
C. Static data allowed
D. Public access specifier
2020 By Eng. Joud Khattab
Question 3
■‫للصفوف‬ ‫األفضل‬ ‫التعريف‬ ‫هو‬ ‫ما‬(class)
A. Parent of an object
B. Instance of an object
C. Blueprint of an object
D. Scope of an object
2020 By Eng. Joud Khattab
Question 3
■‫للصفوف‬ ‫األفضل‬ ‫التعريف‬ ‫هو‬ ‫ما‬(class)
A. Parent of an object
B. Instance of an object
C. Blueprint of an object
D. Scope of an object
2020 By Eng. Joud Khattab
Note
What Is a Class? (‫الصف‬ ‫هو‬ ‫)ما‬
■ In the real world, you'll often find many individual objects all of the same kind.
■ There may be thousands of other bicycles in existence, all of the same make and
model.
■ Each bicycle was built from the same set of blueprints and therefore contains the
same components.
■ In object-oriented terms, we say that your bicycle is an instance of the class of
objects known as bicycles.
■ A class is the blueprint from which individual objects are created.
2020 By Eng. Joud Khattab
Question 4
■‫مفهوم‬ ‫على‬ ‫وتركز‬ ‫توضح‬ ‫التي‬ ‫التوجه‬ ‫غرضيه‬ ‫البرمجة‬ ‫في‬ ‫الموجودة‬ ‫الخاصية‬ ‫هي‬ ‫ما‬
‫البرمجة‬ ‫في‬ ‫االستخدام‬ ‫إعادة‬(reusability)
A. Polymorphism
B. Abstraction
C. Encapsulation
D. Inheritance
2020 By Eng. Joud Khattab
Question 4
■‫مفهوم‬ ‫على‬ ‫وتركز‬ ‫توضح‬ ‫التي‬ ‫التوجه‬ ‫غرضيه‬ ‫البرمجة‬ ‫في‬ ‫الموجودة‬ ‫الخاصية‬ ‫هي‬ ‫ما‬
‫البرمجة‬ ‫في‬ ‫االستخدام‬ ‫إعادة‬(reusability)
A. Polymorphism
B. Abstraction
C. Encapsulation
D. Inheritance
2020 By Eng. Joud Khattab
Question 6
■‫التغليف‬ ‫مفهوم‬ ‫لشرح‬ ‫المناسب‬ ‫التعريف‬ ‫هو‬ ‫ما‬(Encapsulation)
A. It is a way of combining various data members into a single unit
B. It is a way of combining various member functions into a single unit
C. It is a way of combining various data members and member functions into a
single unit which can operate on any data
D. It is a way of combining various data members and member functions that
operate on those data members into a single unit
2020 By Eng. Joud Khattab
Question 6
■‫التغليف‬ ‫مفهوم‬ ‫لشرح‬ ‫المناسب‬ ‫التعريف‬ ‫هو‬ ‫ما‬(Encapsulation)
A. It is a way of combining various data members into a single unit
B. It is a way of combining various member functions into a single unit
C. It is a way of combining various data members and member functions into a
single unit which can operate on any data
D. It is a way of combining various data members and member functions that
operate on those data members into a single unit
2020 By Eng. Joud Khattab
Question 7
■‫البعض؟‬ ‫بعضها‬ ‫مع‬ ‫تتناسب‬ ‫التالية‬ ‫الميزات‬ ‫من‬ ‫أي‬
A. Inheritance and Encapsulation
B. Encapsulation and Polymorphism
C. Encapsulation and Abstraction
D. Abstraction and Polymorphism
2020 By Eng. Joud Khattab
Question 7
■‫البعض؟‬ ‫بعضها‬ ‫مع‬ ‫تتناسب‬ ‫التالية‬ ‫الميزات‬ ‫من‬ ‫أي‬
A. Inheritance and Encapsulation
B. Encapsulation and Polymorphism
C. Encapsulation and Abstraction
D. Abstraction and Polymorphism
2020 By Eng. Joud Khattab
Note
OOP Features (‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫)خصائص‬
■ Abstraction (‫)التجريد‬
– Abstraction is a process where you show only “relevant” data and “hide”
unnecessary details of an object from the user.
■ Encapsulation (‫)التغليف‬
– Encapsulation is binding the data with the code that manipulates it. It keeps the
data and the code safe from external interference.
■ Inheritance (‫)الوراثة‬
– Inheritance is the mechanism by which an object acquires the some/all properties
of another object. It supports the concept of hierarchical classification.
■ Polymorphism ( ‫تعدد‬‫األوجه‬ )
– Polymorphism means to process objects differently based on their data type.
2020 By Eng. Joud Khattab
Note
OOP Features (‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫)خصائص‬
■‫التجريد‬ ‫مفهوم‬(abstraction)
–‫ت‬ ‫على‬ ‫قادرا‬ ‫يجعلك‬ ‫فهو‬ ،‫المبرمجين‬ ‫على‬ ‫األوامر‬ ‫كتابة‬ ‫لتسهيل‬ ‫يستخدم‬ ‫أسلوب‬ ‫هو‬‫نفيذ‬
‫ذلك‬ ‫تنفيذ‬ ‫فيها‬ ‫تم‬ ‫التي‬ ‫التفاصيل‬ ‫كافة‬ ‫معرفة‬ ‫إلى‬ ‫الحاجة‬ ‫دون‬ ‫تريد‬ ‫ما‬.
–‫ال‬ ‫اذا‬abstraction‫تفاص‬ ‫معرفة‬ ‫في‬ ‫تغوص‬ ‫أن‬ ‫بدل‬ ‫بسطحية‬ ‫األشياء‬ ‫مع‬ ‫تتعامل‬ ‫يجعلك‬‫يل‬
‫المعقدة‬ ‫الكودات‬.
■‫التغليف‬ ‫مفهوم‬(encapsulation)
–‫الخصائص‬ ‫إلخفاء‬ ‫أي‬ ،‫الصف‬ ‫في‬ ‫األساسية‬ ‫البيانات‬ ‫إلخفاء‬ ‫اتباعه‬ ‫يمكن‬ ‫أسلوب‬ ‫هو‬
‫فيه‬ ‫الموجودة‬(global variables)‫هذه‬ ‫مع‬ ‫التعامل‬ ‫على‬ ‫قادرة‬ ‫األخرى‬ ‫الصفوف‬ ‫وجعل‬ ،
‫للصف‬ ‫األساسي‬ ‫المبرمج‬ ‫بإنشائها‬ ‫يقوم‬ ‫دوال‬ ‫خالل‬ ‫من‬ ‫فقط‬ ‫الخصائص‬.
–‫ك‬ ‫الخصائص‬ ‫تعريف‬ ‫عليك‬ ،‫التغليف‬ ‫مبدأ‬ ‫لتحقيق‬private‫تستخدم‬ ‫التي‬ ‫الدوال‬ ‫وتعريف‬
‫ك‬ ‫اليهم‬ ‫للوصول‬public
–‫التغليف‬ ‫على‬ ‫مثال‬:setter and getter
2020 By Eng. Joud Khattab
Note
OOP Features (‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫)خصائص‬
■‫ال‬ ‫مفهوم‬polymorphism
–‫ك‬ ‫لها‬ ‫يمرر‬ ‫الذي‬ ‫الكائن‬ ‫حسب‬ ‫على‬ ‫مختلفة‬ ‫أوامر‬ ‫تنفذ‬ ‫دالة‬ ‫بناء‬ ‫منه‬ ‫المقصود‬
argument
–‫نو‬ ‫إلى‬ ‫التحول‬ ‫على‬ ‫الكائن‬ ‫قدرة‬ ‫تحديدا‬ ،‫اشكال‬ ‫عدة‬ ‫أخذ‬ ‫على‬ ‫الكائن‬ ‫قدرة‬ ‫تعني‬‫ع‬
‫منه‬ ‫مشتق‬.
2020 By Eng. Joud Khattab
Note
Polymorphism
■ Overloading (Static Polymorphism)
– Overloading in simple words means more than one method having the same
method name that behaves differently based on the arguments passed while
calling the method.
■ Overriding (Dynamic Polymorphism)
– Overriding means a derived class is implementing a method of its super class.
The call to overridden method is resolved at runtime, thus called runtime
polymorphism.
2020 By Eng. Joud Khattab
Note
Overriding
■ Overriding:
–‫ال‬ ‫ورثها‬ ‫التي‬ ‫الدالة‬ ‫تعريف‬ ‫تعني‬subclass‫ال‬ ‫من‬superclass‫جديد‬ ‫من‬.
–‫فقط‬ ‫الشكل‬ ‫حيث‬ ‫من‬ ‫الموروثة‬ ‫للدالة‬ ‫مشابهة‬ ‫تكون‬ ‫الجديدة‬ ‫الدالة‬ ‫هذه‬.‫لها‬ ‫أي‬
‫وعدد‬ ‫والنوع‬ ‫االسم‬ ‫نفس‬‫الباراميترات‬‫مختلف‬ ‫محتواها‬ ‫لكن‬.
–‫الفرصة‬ ‫اتاحة‬ ‫هو‬ ‫الهدف‬‫لل‬subclass‫حاجته‬ ‫حسب‬ ‫الدوال‬ ‫ليعرف‬
2020 By Eng. Joud Khattab
Note
Overriding
■‫ال‬ ‫شروط‬overriding:
–‫ال‬ ‫يكون‬ ‫أن‬ ‫يجب‬modifier‫للدالة‬ ‫المستخدم‬ ‫نفسه‬ ‫هو‬ ‫الجديدة‬ ‫للدالة‬ ‫المستخدم‬
‫نوعه‬ ‫يكون‬ ‫أن‬ ‫ويجب‬ ،‫القديمة‬public‫او‬protected.
–‫ك‬ ‫المعرفة‬ ‫الدالة‬final‫لها‬ ‫نفعل‬ ‫أن‬ ‫يمكن‬ ‫ال‬override‫كلمة‬ ‫ألن‬ ،final‫تغير‬ ‫تمنع‬
‫تعريفها‬ ‫بعد‬ ‫الدالة‬ ‫محتوى‬.
2020 By Eng. Joud Khattab
Question 8
■‫الصفوف‬ ‫تدعم‬ ‫التي‬ ‫اللغة‬ ‫تسمي‬ ‫ماذا‬(classes)‫االشكال‬ ‫تعدد‬ ‫تدعم‬ ‫وال‬
(polymorphism)‫؟‬
A. Class based language
B. Procedure oriented language
C. Object based language
D. If classes are supported, polymorphism will always be supported
2020 By Eng. Joud Khattab
Question 8
■‫الصفوف‬ ‫تدعم‬ ‫التي‬ ‫اللغة‬ ‫تسمي‬ ‫ماذا‬(classes)‫االشكال‬ ‫تعدد‬ ‫تدعم‬ ‫وال‬
(polymorphism)‫؟‬
A. Class based language
B. Procedure oriented language
C. Object based language
D. If classes are supported, polymorphism will always be supported
2020 By Eng. Joud Khattab
Note
Programming Paradigm
■ The main programming paradigms:
1. Imperative
■ Cobol, Fortran, C, Ada, Perl
2. Object-oriented
■ Smalltalk, Java, C++, C#, Python
3. Functional
■ Lisp, Scheme, ML, Haskell
4. Logic
■ Prolog
5. Declarative
■ SQL, HTML
2020 By Eng. Joud Khattab
Question 9
■ If data members are private, what can we do to access them from the class object?
A. Create public member functions to access those data members
B. Create private member functions to access those data members
C. Create protected member functions to access those data members
D. Private data members can never be accessed from outside the class
2020 By Eng. Joud Khattab
Question 9
■ If data members are private, what can we do to access them from the class object?
A. Create public member functions to access those data members
B. Create private member functions to access those data members
C. Create protected member functions to access those data members
D. Private data members can never be accessed from outside the class
2020 By Eng. Joud Khattab
Question 10
■‫التغليف‬ ‫مفهوم‬ ‫ينتهك‬ ‫التالية‬ ‫الخيارات‬ ‫من‬ ‫أي‬(encapsulation)‫دائما؟‬
A. Local variables
B. Global variables
C. Public variables
D. Array variables
2020 By Eng. Joud Khattab
Question 10
■‫التغليف‬ ‫مفهوم‬ ‫ينتهك‬ ‫التالية‬ ‫الخيارات‬ ‫من‬ ‫أي‬(encapsulation)‫دائما؟‬
A. Local variables
B. Global variables
C. Public variables
D. Array variables
2020 By Eng. Joud Khattab
Question 11
■‫للبناة‬ ‫ضروريا‬ ‫شرطا‬ ‫ليس‬ ‫يلي‬ ‫مما‬ ‫أي‬(constructor)‫؟‬
A. Its name must be same as that of class
B. It must not have any return type
C. It must contain a definition body
D. It can contains arguments
2020 By Eng. Joud Khattab
Question 11
■‫للبناة‬ ‫ضروريا‬ ‫شرطا‬ ‫ليس‬ ‫يلي‬ ‫مما‬ ‫أي‬(constructor)‫؟‬
A. Its name must be same as that of class
B. It must not have any return type
C. It must contain a definition body
D. It can contains arguments
2020 By Eng. Joud Khattab
Question 12
■ How many types of constructors are available for use in general (with respect to
parameters)?
A. 2
B. 3
C. 4
D. 5
2020 By Eng. Joud Khattab
Question 12
■ How many types of constructors are available for use in general (with respect to
parameters)?
A. 2
B. 3
C. 4
D. 5
2020 By Eng. Joud Khattab
Question 13
■ Default constructor must be defined, if parameterized constructor is defined and the
object is to be created without arguments.
A. True
B. False
2020 By Eng. Joud Khattab
Question 13
■ Default constructor must be defined, if parameterized constructor is defined and the
object is to be created without arguments.
A. True
B. False
2020 By Eng. Joud Khattab
Question 14
■ If class C inherits class B. And B has inherited class A. Then while creating the object
of class C, what will be the sequence of constructors getting called?
A. Constructor of C then B, finally of A
B. Constructor of A then C, finally of B
C. Constructor of C then A, finally B
D. Constructor of A then B, finally C
2020 By Eng. Joud Khattab
Question 14
■ If class C inherits class B. And B has inherited class A. Then while creating the object
of class C, what will be the sequence of constructors getting called?
A. Constructor of C then B, finally of A
B. Constructor of A then C, finally of B
C. Constructor of C then A, finally B
D. Constructor of A then B, finally C
2020 By Eng. Joud Khattab
COMPLEXITY
‫الخوارزميات‬ ‫تعقيد‬
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫اساسيين‬ ‫بعاملين‬ ‫يرتبط‬:
–‫الذاكرة‬ ‫حجم‬:
■‫يعالجها‬ ‫التي‬ ‫والمعطيات‬ ‫البرنامج‬ ‫لتخزين‬ ‫الالزمة‬.
–‫التنفيذ‬ ‫زمن‬:
■‫كافة‬ ‫تعليماتها‬ ‫إنجاز‬ ‫من‬ ‫الخوارزمية‬ ‫لتنتهي‬ ‫الالزم‬ ‫الزمن‬.
■‫تعليمة‬ ‫كل‬ ‫لتنفيذ‬ ‫الالزم‬ ‫والزمن‬ ‫التعليمات‬ ‫عدد‬ ‫بحساب‬ ‫التنفيذ‬ ‫زمن‬ ‫يقاس‬.
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫منها‬ ‫عديدة‬ ‫عوامل‬ ‫على‬ ‫حاسب‬ ‫على‬ ‫البرنامج‬ ‫تنفيذ‬ ‫زمن‬ ‫يعتمد‬:
–‫ما‬ ‫بتجربة‬ ‫الخاصة‬ ‫المسألة‬ ‫معطيات‬.
–‫جودة‬‫الرماز‬‫التنفيذي‬ ‫الملف‬ ‫بناء‬ ‫أجل‬ ‫من‬ ‫المترجم‬ ‫يولده‬ ‫الذي‬.
–‫الحاسوب‬ ‫في‬ ‫المتوفرة‬ ‫التعليمات‬ ‫وسرعة‬ ‫طبيعة‬(‫المعالج‬ ‫في‬‫الصغري‬.)
–‫الخوارزمية‬ ‫فعالية‬.(‫المبرمج‬ ‫قدرة‬ ‫على‬ ‫تعتمد‬)
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫بعد‬ ‫تحديد‬ ‫يجب‬ ‫خوارزمية‬ ‫تنفيذ‬ ‫زمن‬ ‫لحساب‬(‫حجم‬ ‫او‬ ‫طول‬ ‫او‬)‫درجة‬ ‫كتابة‬ ‫أجل‬ ‫من‬ ‫المسألة‬ ‫معطيات‬
‫البعد‬ ‫هذا‬ ‫بداللة‬ ‫التعقيد‬.
■‫أمثلة‬:
–‫الحدود‬ ‫كثيرات‬ ‫مسائل‬:
■‫يكون‬‫الحدود‬ ‫كثيرات‬ ‫درجة‬ ‫هو‬ ‫البعد‬.
–‫المصفوفات‬ ‫مسائل‬:
■‫يكون‬‫المصفوفة‬ ‫أبعاد‬ ‫بداللة‬ ‫البعد‬.
–‫البيانات‬ ‫مسائل‬:
■‫يكون‬‫األسهم‬ ‫أو‬ ‫العقد‬ ‫عدد‬ ‫بداللة‬ ‫البعد‬‫مجموعها‬ ‫أو‬.
–‫الفرز‬ ‫مسائل‬:
■‫يكون‬‫ترتيبها‬ ‫نريد‬ ‫التي‬ ‫العناصر‬ ‫عدد‬ ‫بداللة‬ ‫البعد‬.
–‫القواعدي‬ ‫التحليل‬ ‫مسائل‬:
■‫يكون‬‫الكلمة‬ ‫طول‬ ‫بداللة‬ ‫البعد‬.
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫الرياضية‬ ‫القوانين‬ ‫ببعض‬ ‫تذكرة‬:
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫الرياضية‬ ‫القوانين‬ ‫ببعض‬ ‫تذكرة‬:
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
T(n)
n n n log n n2
n3
n4
n10
2n
10 .01s .03s .1s 1s 10s 10s 1s
20 .02s .09s .4s 8s 160s 2.84h 1ms
30 .03s .15s .9s s 810s 6.83d 1s
40 .04s .21s 1.6s s 2.56ms 121d 18m
50 .05s .28s s s 6.25ms 3.1y 13d
100 .1s .66s 10s 1ms 100ms 3171y 41013
y
103
1s 9.96s 1ms 1s 16.67m 3.171013
y 3210283
y
104
s 130s 100ms 16.67m 115.7d 3.171023
y
105
s 1.66ms 10s 11.57d 3171y 3.171033
y
106
ms 19.92ms 16.67m 31.71y 3.17107
y 3.171043
y
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Exercise
// a simple loop to calculate the sum of numbers in an array
int i , sum;
for (i = sum = 0; i<n ; i++)
sum += a[i];
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Rule
If a loop iterates for i = initial value to final value in step of 1
then:
Number of iterations of the loop = final value – initial value + 1
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Exercise
int i = 0;
int sum = 0;
while (i < n)
{
sum = sum + a[i];
i = i + 1;
}
The body of this loop is
executed for i = 0, 1, 2, … n-1.
Hence, it is executed
((n-1) – 0) + 1 = n times
Therefore, these 2
assignments are
executed n times
Answer: Number of Assignment Operations =
2 + n + n = 2n + 2
2
assignments
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 1
■‫السؤال‬:‫تصاعديا‬ ‫التالية‬ ‫التعقيدات‬ ‫رتب‬
–n
–n*n
–n*logn
–logn
■‫اإلجابة‬:
.1logn
.2n
.3n*logn
.4n*n
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 2
■‫السؤال‬:‫لقوة‬ ‫الرفع‬ ‫لخوارزمية‬ ‫تعقيد‬ ‫أصغر‬
–n
–n*n
–n*logn
–logn
■‫اإلجابة‬:
–logn
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 2
int power (int x, int y) {
int p = 1;
for (int i = 1; i<=y; i++) {
p = p*x; }
return p; }
int power2 (int x, int y) {
int res = 1;
int factor = x;
while (y>0) {
if (y%2==1)
res = res*factor;
factor = factor*factor;
y = y / 2; }
return res; }
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫التنفيذ‬ ‫زمن‬ ‫حسب‬ ‫المسائل‬ ‫تصنيف‬:
–O(1):‫التقطيع‬ ‫جداول‬ ‫في‬ ‫البحث‬ ‫خوارزميات‬( .Hash Tables)
–Log n:‫الثنائي‬ ‫البحث‬ ‫خوارزميات‬( .Binary Search)
–n:‫التسلسلي‬ ‫البحث‬ ‫خوارزميات‬( .Search)
–n * Log n:‫الجيدة‬ ‫الفرز‬ ‫خوارزميات‬( .Sort)
–n*n:‫المصفوفات‬ ‫ضرب‬(‫الحجم‬ ‫متوسطة‬ ‫معطيات‬ ‫تعالج‬.)
–2 𝑛:‫محدود‬ ‫حجم‬ ‫ذات‬ ‫معطيات‬ ‫حالة‬ ‫في‬ ‫إال‬ ‫تستخدم‬ ‫ال‬ ‫أسي‬.
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
■‫تنفيذ‬ ‫زمن‬ ‫يكون‬ ‫التي‬ ‫هي‬ ‫معينة‬ ‫مسألة‬ ‫لحل‬ ‫الجيدة‬ ‫الخوارزميات‬ ‫إن‬ ‫نقول‬ ‫ان‬ ‫يمكن‬‫ها‬:
–‫المعطيات‬ ‫حجم‬ ‫كان‬ ‫مهما‬ ‫ثابتا‬:‫التقطيع‬ ‫جداول‬ ‫في‬ ‫البحث‬ ‫خوارزميات‬ ‫مثل‬.
–‫لوغاريتميا‬:‫الثنائي‬ ‫البحث‬ ‫خوارزميات‬ ‫مثل‬.
–‫خطيا‬:‫التسلسلي‬ ‫البحث‬ ‫خوارزمية‬ ‫مثل‬.
–‫مرتبة‬ ‫من‬n*log(n):‫الجيدة‬ ‫الفرز‬ ‫خوارزميات‬ ‫مثل‬.
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 3
void Main()
{
for (int i=1; i<=n; i++)
{
m=m+1;
p=p*2;
l=l+3;
}
}
■‫السؤال‬:
–‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬
‫التالية‬:
■‫اإلجابة‬:
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 4
void Main()
{
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++){
m=m+1;
p=p*2;
l=l+3; } }
}
■‫السؤال‬:
–‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬
‫التالية‬:
■‫اإلجابة‬:
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 5
void Main()
{
for (int i=1; i<=n; i++) {
for (int j=1; j<=i; j++){
m=m+1;
p=p*2;
l=l+3; } }
}
■‫السؤال‬:
–‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬
‫التالية‬:
■‫اإلجابة‬:
2020 By Eng. Joud Khattab
Complexity (‫الخوارزميات‬ ‫)تعقيد‬
Question 6
void Main()
{
for (int cnt=5,i=1; i<=n; i++)
for (int j=1; j<=n; j=j*2)
cnt++;
}
■‫السؤال‬:
–‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬
‫التالية‬:
■‫اإلجابة‬:
–n * log n
2020 By Eng. Joud Khattab
RECURSIVE FUNCTIONS
‫الخوارزميات‬‫العودية‬
2020 By Eng. Joud Khattab
Recursive Functions
( ‫الخوارزميات‬‫العودية‬ )
■‫للتوقف‬ ‫شرط‬ ‫بتحقق‬ ‫االستدعاء‬ ‫وينتهي‬ ‫نفسها‬ ‫تستدعي‬ ‫خوارزمية‬ ‫هي‬.
■‫أمثلة‬:
–‫فيبوناتشي‬ ‫اعداد‬ ‫حساب‬.
–‫أكريمان‬ ‫سلسلة‬.
–‫هانوي‬ ‫أبراج‬.
–‫المنحنيات‬ ‫رسم‬.
–‫الثمانية‬ ‫الوزراء‬ ‫مسألة‬.
–‫هلبرت‬ ‫منحنيات‬.
■‫الخوارزمية‬ ‫تعقيد‬ ‫حساب‬ ‫يؤول‬‫العودية‬‫تراجعية‬ ‫معادلة‬ ‫حل‬ ‫إلى‬.
2020 By Eng. Joud Khattab
Recursive Functions
( ‫الخوارزميات‬‫العودية‬ )
■‫اإلجرائيات‬ ‫من‬ ‫نوعين‬ ‫بين‬ ‫التمييز‬ ‫يمكن‬‫العودية‬:
–‫ذات‬ ‫اإلجرائيات‬‫العودية‬‫المباشرة‬:
■‫إجرائية‬ ‫عن‬ ‫نقول‬P‫إنها‬‫عودية‬‫لنفسها‬ ‫صريح‬ ‫استدعاء‬ ‫تحوي‬ ‫كانت‬ ‫إذا‬ ‫مباشرة‬.
–‫ذات‬ ‫اإلجرائيات‬‫العودية‬‫المباشرة‬ ‫غير‬:
■‫إجرائية‬ ‫عن‬ ‫نقول‬P‫إنها‬‫عودية‬‫أخرى‬ ‫إجرائية‬ ‫تستدعي‬ ‫كانت‬ ‫إذا‬ ‫مباشرة‬ ‫غير‬Q
‫تستدعي‬P.
2020 By Eng. Joud Khattab
Recursive Functions
( ‫الخوارزميات‬‫العودية‬ )
■‫االستدعاء‬ ‫عملية‬‫العودي‬‫المطلوبة‬ ‫الذاكرة‬ ‫وحجم‬ ‫التنفيذ‬ ‫الزمن‬ ‫حيث‬ ‫من‬ ‫مكلفة‬.
■‫خوارزمية‬ ‫تحويل‬ ‫يمكن‬‫عودية‬‫مكدس‬ ‫باستخدام‬ ‫تكرارية‬ ‫إلى‬
–‫ث‬ ‫فيه‬ ‫عودي‬ ‫استدعاء‬ ‫لكل‬ ‫المحلية‬ ‫والمتحوالت‬ ‫الدخل‬ ‫معامالت‬ ‫تخزين‬ ‫يتم‬ ‫حيث‬‫م‬
‫االستدعاء‬ ‫بعد‬ ‫التعليمات‬ ‫بقية‬ ‫لتنفيذ‬ ‫المكدس‬ ‫عناصر‬ ‫حذف‬ ‫يتم‬‫العودي‬‫عل‬‫هذه‬ ‫ى‬
‫األول‬ ‫إلى‬ ‫األخير‬ ‫االستدعاء‬ ‫من‬ ‫التنفيذ‬ ‫يتم‬ ‫حيث‬ ‫العناصر‬.
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 1
■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(33,33)
int f(int x, int y) {
if (x==1) return y;
else if (y==1) return x;
else if (x%2==0) return y+f(x/2,y);
else return x+f(x,y/2); }
■‫اإلجابة‬:
198
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 1
■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(22,22)
int f(int x, int y) {
if (x==1) return y;
else if (y==1) return x;
else if (x%2==0) return y+f(x/2,y);
else return x+f(x,y/2); }
■‫اإلجابة‬:
77
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 2
■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(1024*1024)
Public int f(int n) {
int x=0;
for (int i=2; i<=n ; i*=2) {
x++; }
return x; }
■‫اإلجابة‬:
f(210*210)=20
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 3
■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(33)
Int f(int n) {
for (int i=1;i<=n;i++) {
i=i+1;
n=n-1; }
return n; }
■‫اإلجابة‬:
22
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 3
■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(10)
Int f(int n) {
for (int i=1;i<=n;i++) {
i=i+1;
n=n-1; }
return n; }
■‫اإلجابة‬:
6
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 4
int fun(int n) {
if (n == 4)
return n;
else return 2*fun(n+1); }
int main() {
printf("%d ", fun(2));
return 0; }
1. 4
2. 8
3. 16
4. Runtime error.
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 4
int fun(int n) {
if (n == 4)
return n;
else return 2*fun(n+1); }
int main() {
printf("%d ", fun(2));
return 0; }
1. 4
2. 8
3. 16
4. Runtime error.
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 4
int fun(int n) {
if (n == 4)
return n;
else return 2*fun(n+1); }
int main() {
printf("%d ", fun(6));
return 0; }
1. 4
2. 8
3. 16
4. Runtime error.
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 4
int fun(int n) {
if (n == 4)
return n;
else return 2*fun(n+1); }
int main() {
printf("%d ", fun(6));
return 0; }
1. 4
2. 8
3. 16
4. Runtime error.
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 5
int fun(int x, int y) {
if (x == 0)
return y;
return fun(x - 1, x + y); }
int main() {
printf("%d ", fun(4,3));
return 0; }
1. 13
2. 12
3. 9
4. 10
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 5
int fun(int x, int y) {
if (x == 0)
return y;
return fun(x - 1, x + y); }
int main() {
printf("%d ", fun(4,3));
return 0; }
1. 13
2. 12
3. 9
4. 10
The rule: x(x+1)/2 + y
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 6
n = 25
void fun(int n) {
if (n == 0)
return;
printf("%d", n%2);
fun(n/2); }
1. 11001
2. 10011
3. 11111
4. 00000
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 6
n = 25
void fun(int n) {
if (n == 0)
return;
printf("%d", n%2);
fun(n/2); }
1. 11001
2. 10011
3. 11111
4. 00000
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 7
n = 25
void fun(int n) {
if (n == 0)
return;
fun(n/2);
printf("%d", n%2); }
1. 11001
2. 10011
3. 11111
4. 00000
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 7
n = 25
void fun(int n) {
if (n == 0)
return;
fun(n/2);
printf("%d", n%2); }
1. 11001
2. 10011
3. 11111
4. 00000
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 8
What does the following function do?
int fun(int x, int y)
{
if (y == 0) return 0;
return (x + fun(x, y-1));
}
1. x+y
2. x+x*y
3. x*y
4. x^y
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 8
What does the following function do?
int fun(int x, int y)
{
if (y == 0) return 0;
return (x + fun(x, y-1));
}
1. x+y
2. x+x*y
3. x*y
4. x^y
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 9
int f(int n) {
if(n <= 1)
return 1;
if(n%2 == 0)
return f(n/2);
return f(n/2) + f(n/2+1); }
int main() {
printf("%d", f(11));
return 0; }
1. Stack overflow
2. 3
3. 4
4. 5
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 9
int f(int n) {
if(n <= 1)
return 1;
if(n%2 == 0)
return f(n/2);
return f(n/2) + f(n/2+1); }
int main() {
printf("%d", f(11));
return 0; }
1. Stack overflow
2. 3
3. 4
4. 5
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 10
Consider the following: f(5)
int fun (int n)
{
int x=1, k;
if (n==1) return x;
for (k=1; k<n; ++k)
x = x + fun(k) * fun(n – k);
return x;
}
1. 0
2. 26
3. 51
4. 71
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 10
Consider the following: f(5)
int fun (int n)
{
int x=1, k;
if (n==1) return x;
for (k=1; k<n; ++k)
x = x + fun(k) * fun(n – k);
return x;
}
1. 0
2. 26
3. 51
4. 71
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 11
If get(6) function is being called. how
many times will the get() function be
invoked?
void get (int n) {
if (n < 1) return;
get(n-1);
get(n-3);
printf("%d", n); }
1. 15
2. 25
3. 35
4. 45
2020 By Eng. Joud Khattab
Recursive Functions ( ‫الخوارزميات‬‫العودية‬ )
Question 11
If get(6) function is being called. how
many times will the get() function be
invoked?
void get (int n) {
if (n < 1) return;
get(n-1);
get(n-3);
printf("%d", n); }
1. 15
2. 25
3. 35
4. 45
get(6) [25 Calls]
/ 
[17 Calls] get(5) get(3) [7 Calls]
/ 
get(4) get(2) [5 Calls]
/ 
[7 Calls] get(3) get(1) [3 Calls]
/ 
get(2) get(0)
/ 
[3 Calls] get(1) get(-1)
/ 
get(0) get(-2)
2020 By Eng. Joud Khattab
SEQUENTIAL
DATA STRUCTURE
‫التسلسلية‬ ‫المعطيات‬ ‫بنى‬
2020 By Eng. Joud Khattab
Linked List (‫الخطية‬ ‫)السالسل‬
■‫النمط‬ ‫نفس‬ ‫من‬ ‫عناصر‬ ‫تخزين‬ ‫من‬ ‫تمكن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬.
■‫السالسل‬ ‫ميزات‬:
–‫مسبقا‬ ‫طولها‬ ‫لتحديد‬ ‫ضرورة‬ ‫ال‬.
–‫واالضافة‬ ‫الحذف‬ ‫عند‬ ‫السلسلة‬ ‫عناصر‬ ‫ازاحة‬ ‫إلى‬ ‫نحتاج‬ ‫ال‬.
■‫سيئاتها‬:
–‫عنصر‬ ‫إلى‬ ‫المباشر‬ ‫النفاذ‬ ‫يمكن‬ ‫ال‬,‫إلى‬ ‫تحتاج‬ ‫وبالتالي‬n‫االحوال‬ ‫أسوأ‬ ‫في‬ ‫مقارنة‬ ‫عملية‬
‫العنصر‬ ‫إلى‬ ‫للوصول‬.
–‫المؤشرات‬ ‫لتخزين‬ ‫إضافي‬ ‫تخزين‬ ‫حجم‬ ‫إلى‬ ‫نحتاج‬.
■‫مثل‬ ‫للسالسل‬ ‫أخرى‬ ‫أنواع‬ ‫يوجد‬:
–‫الدائرية‬ ‫السالسل‬circular linked list.
–‫االرتباط‬ ‫المضاعفة‬ ‫السالسل‬doubly linked list.
2020 By Eng. Joud Khattab
Linked List (‫الخطية‬ ‫)السالسل‬
A B C
Head
A
data pointer
node
2020 By Eng. Joud Khattab
Linked List (‫الخطية‬ ‫)السالسل‬
V.S. Ordinary and Dynamic Arrays
Ordinary Arrays
■‫الميزات‬:
–‫واستخدام‬ ‫إنشاء‬ ‫جدا‬ ‫السهل‬ ‫من‬.
–‫عنصر‬ ‫أي‬ ‫إلى‬ ‫المباشر‬ ‫الوصول‬.
■‫السيئات‬:
–‫في‬ ‫ا‬ً‫معروف‬ ‫حجمها‬ ‫يكون‬ ‫أن‬ ‫يجب‬
‫يمكن‬ ‫وال‬ ،‫البرمجي‬ ‫التحويل‬ ‫وقت‬
‫التشغيل‬ ‫وقت‬ ‫في‬ ‫تغييره‬.
–‫نقل‬ ‫حذفه‬ ‫أو‬ ‫عنصر‬ ‫إدراج‬ ‫يتطلب‬
‫األخرى‬ ‫العناصر‬ ‫كل‬.
Dynamic Arrays
■‫الميزات‬:
–‫إنشائها‬ ‫جدا‬ ‫السهل‬ ‫من‬.
–‫عنصر‬ ‫أي‬ ‫إلى‬ ‫المباشر‬ ‫الوصول‬.
–‫التشغيل‬ ‫وقت‬ ‫في‬ ‫الحجم‬ ‫تحديد‬ ‫يمكن‬.
■‫السيئات‬:
–‫كل‬ ‫نقل‬ ‫حذفه‬ ‫أو‬ ‫عنصر‬ ‫إدراج‬ ‫يتطلب‬
‫األخرى‬ ‫العناصر‬.
–‫تتخطى‬ ‫أن‬ ‫المصفوفة‬ ‫على‬ ‫كان‬ ‫إذا‬
‫تشكيل‬ ‫إعادة‬ ‫فيجب‬ ، ‫األولي‬ ‫الحجم‬
‫جديد‬ ‫موقع‬ ‫إلى‬ ‫بأكملها‬ ‫المصفوفة‬.
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
■‫ندع‬ ‫واحدة‬ ‫جهة‬ ‫من‬ ‫تتم‬ ‫والحذف‬ ‫اإلضافة‬ ‫عمليات‬ ‫إن‬ ‫غير‬ ،‫السلسلة‬ ‫تشبه‬ ‫خطية‬ ‫بنية‬ ‫هي‬‫وها‬
‫المكدس‬ ‫قمة‬.
■‫النمط‬ ‫نفس‬ ‫من‬ ‫عناصر‬ ‫تخزين‬ ‫من‬ ‫تمكن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬.
■‫مبدأ‬ ‫تتبع‬:
–First In last Out (FILO)
–Last In First Out (LIFO)
■‫عليه‬ ‫االساسية‬ ‫العمليات‬:
–‫قمته‬ ‫خالل‬ ‫من‬ ‫العناصر‬ ‫إلى‬ ‫الوصول‬ ‫يمكن‬head))
–‫القمة‬ ‫إلى‬ ‫عنصر‬ ‫إضافة‬push))
–‫القمة‬ ‫من‬ ‫عنصر‬ ‫حذف‬pop))
■‫الخطية‬ ‫السالسل‬ ‫أو‬ ‫المصفوفات‬ ‫باستخدام‬ ‫المكدس‬ ‫تمثيل‬ ‫يمكن‬.
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
■‫المكدسات‬ ‫تطبيقات‬:
–‫الصفحات‬ ‫سجل‬‫المزارة‬‫االنترنت‬ ‫متصفح‬ ‫في‬.
–‫النصوص‬ ‫محررات‬ ‫في‬ ‫التراجع‬ ‫عمليات‬.
–‫الرياضية‬ ‫التعابير‬ ‫في‬ ‫األقواس‬ ‫أزواج‬ ‫ربط‬.
–‫قيم‬ ‫وحساب‬ ‫الملحقة‬ ‫التعابير‬ ‫إلى‬ ‫النظامية‬ ‫الرياضية‬ ‫التعابير‬ ‫من‬ ‫التحويل‬‫هذه‬ ‫ة‬
‫التعابير‬.
–‫تابع‬ ‫جسم‬ ‫في‬ ‫تابع‬ ‫استدعاء‬.
–‫أوال‬ ‫العمق‬ ‫بطريقة‬ ‫والبيانات‬ ‫األشجار‬ ‫في‬ ‫التجول‬.
–‫المترجمات‬ ‫في‬ ‫األخطاء‬ ‫مكدس‬.
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
Infix (‫)نظامي‬ Prefix (‫)مصدر‬ Postfix (‫)ملحق‬
A+B +AB AB+
A+B*C +A*BC ABC*+
A*(B+C) *A+BC ABC+*
A*B+C +*ABC AB*C+
A+B*C+D-E*F -++A*BCD*EF ABC*+D+EF*-
(A+B)*(C+D-E)*F **+AB-+CDEF AB+CD+E-*F*
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
■ Infix to Postfix:
1. Scan the infix expression from left to right.
2. If the scanned character is an operand, output it.
3. Else,
1. If the precedence of the scanned operator is greater or equal than the precedence of the operator
in the stack (or the stack is empty), push it.
2. Else, pop the operator from the stack until the precedence of the scanned operator is less-equal to
the precedence of the operator residing on the top of the stack. Then push the scanned operator to
the stack.
4. If the scanned character is an ‘(‘, push it to the stack.
5. If the scanned character is an ‘)’, pop and output from the stack until an ‘(‘ is encountered.
6. Repeat steps 2 to 6 until infix expression is scanned.
7. Pop and output from the stack until it is not empty.
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
■ Infix to Prefix:
1. Reverse the infix expression i.e A+B*C will become C*B+A.
■ Note while reversing each ‘(‘ will become ‘)’ and each ‘)’ becomes ‘(‘.
2. Obtain the postfix expression of the modified expression i.e CB*A+.
3. Reverse the postfix expression. Hence in our example prefix is +A*BC.
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
■ Postfix Calculation:
1. Create a stack to store operands (values).
2. Scan the given expression and do following for every scanned element:
1. If the element is a number, push it into the stack.
2. If the element is a operator, pop operands for the operator from stack. Evaluate
the operator and push the result back to the stack.
3. When the expression is ended, the number in the stack is the final answer.
2020 By Eng. Joud Khattab
Stack (‫)المكدس‬
■ Prefix Calculation:
1. Put a pointer P at the end of the end.
2. If character at P is a number push it to Stack.
3. If the character at P is an operator pop two elements from the Stack. Operate
on these elements according to the operator, and push the result back to the
Stack.
4. Decrement P by 1 and go to Step 2 as long as there are characters left to be
scanned in the expression.
5. The Result is stored at the top of the Stack.
2020 By Eng. Joud Khattab
Queue (‫)األرتال‬
■‫الرت‬ ‫ذيل‬ ‫ندعوها‬ ‫جهة‬ ‫في‬ ‫تجري‬ ‫اإلضافة‬ ‫عمليات‬ ‫أن‬ ‫غير‬ ‫السلسلة‬ ‫تشبه‬ ‫خطية‬ ‫بنية‬ ‫هي‬‫ل‬.
‫الرتل‬ ‫بداية‬ ‫نسميها‬ ‫التي‬ ‫المعاكسة‬ ‫الجهة‬ ‫في‬ ‫الحذف‬ ‫ويجري‬.
■‫النمط‬ ‫نفس‬ ‫من‬ ‫عناصر‬ ‫تخزين‬ ‫من‬ ‫تمكن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬.
■‫مبدأ‬ ‫تتبع‬:
–First In First Out (FIFO)
–Last In Last Out (LILO)
■‫عليه‬ ‫االساسية‬ ‫العمليات‬:
–‫بدايته‬ ‫خالل‬ ‫من‬ ‫العناصر‬ ‫إلى‬ ‫الوصول‬ ‫يمكن‬(head)‫نهايته‬ ‫أو‬(tail.)
–‫النهاية‬ ‫إلى‬ ‫عنصر‬ ‫إضافة‬(enqueue.)
–‫البداية‬ ‫من‬ ‫عنصر‬ ‫حذف‬(dequeue.)
■‫الخطية‬ ‫السالسل‬ ‫أو‬ ‫المصفوفات‬ ‫باستخدام‬ ‫االرتال‬ ‫تمثيل‬ ‫يمكن‬.
2020 By Eng. Joud Khattab
Queue (‫)األرتال‬
2020 By Eng. Joud Khattab
Queue (‫)األرتال‬
■‫األرتال‬ ‫تطبيقات‬:
–‫الكمبيوتر‬ ‫في‬ ‫والمخرجات‬ ‫المدخالت‬ ‫مخازن‬(‫والطابعة‬ ‫المفاتيح‬ ‫لوحة‬.)
–‫في‬ ‫أوال‬ ‫بالعرض‬ ‫التجول‬ ‫خوارزميات‬ ‫مثل‬ ‫الخوارزميات‬ ‫في‬ ‫مساعدة‬ ‫معطيات‬ ‫بنية‬
‫والبيانات‬ ‫األشجار‬.
–‫اليومية‬ ‫الحياة‬ ‫أرتال‬ ‫محاكاة‬.
2020 By Eng. Joud Khattab
Queue (‫)األرتال‬
■‫االولويات‬ ‫رتل‬:
–‫الرتل‬ ‫إلى‬ ‫األولوية‬ ‫عامل‬ ‫يضاف‬.
–‫اوال‬ ‫األعلى‬ ‫األولوية‬ ‫ذو‬ ‫العنصر‬ ‫تخديم‬ ‫يتم‬.
–‫مثال‬:
■‫للحاالت‬ ‫األولوية‬ ‫تكون‬ ‫حيث‬ ‫الطبيب‬ ‫عيادة‬ ‫في‬ ‫االنتظار‬ ‫أرتال‬‫اإلسعافية‬.
2020 By Eng. Joud Khattab
NON SEQUENTIAL
DATA STRUCTURES
‫التسلسلية‬ ‫غير‬ ‫المعطيات‬ ‫بنى‬
2020 By Eng. Joud Khattab
Trees (‫)االشجار‬
■‫الشجرة‬ ‫نعرف‬:
–‫عقد‬ ‫نسميها‬ ‫العناصر‬ ‫من‬ ‫مجموعة‬ ‫بأنها‬nodes))،
–‫بروابط‬ ‫بعضها‬ ‫بين‬ ‫مرتبطة‬(Links)،
–‫هرميا‬ ‫تنظيما‬ ‫ومنظمة‬(Hierarchical)،
–‫حلقات‬ ‫يحتوي‬ ‫ال‬(Cycles)،‫مغلقة‬
–‫جذر‬ ‫نسميها‬ ‫ووحيدة‬ ‫مميزة‬ ‫عقدة‬ ‫توجد‬ ‫إنه‬ ‫أي‬(Root.)
■‫أمثلة‬:
–‫مجلدات‬ ‫في‬ ‫الملفات‬ ‫تنظيم‬.
–‫حسابية‬ ‫عبارة‬ ‫تمثيل‬.
2020 By Eng. Joud Khattab
Binary Trees (‫الثنائية‬ ‫)األشجار‬
■‫األكثر‬ ‫علي‬ ‫ابنان‬ ‫عقدة‬ ‫لكل‬ ‫فيها‬ ‫يكون‬ ‫األشجار‬ ‫من‬ ‫خاصة‬ ‫حالة‬:
–‫داخلية‬ ‫عقد‬ ‫األقل‬ ‫على‬ ‫ولد‬ ‫لها‬ ‫التي‬ ‫العقد‬ ‫نسمي‬.
–‫أوراق‬ ‫أو‬ ‫خارجية‬ ‫عقد‬ ‫ولد‬ ‫أي‬ ‫لها‬ ‫ليس‬ ‫التي‬ ‫العقد‬ ‫نسمي‬(Leaf.)
–‫طريقا‬ ‫نسمي‬(Path)‫العقد‬ ‫من‬ ‫متتالية‬ ‫كل‬.
–‫األوراق‬ ‫وإحدى‬ ‫الجذر‬ ‫بين‬ ‫يصل‬ ‫طريق‬ ‫كل‬ ‫فرعا‬ ‫نسمي‬.
2020 By Eng. Joud Khattab
Binary Trees (‫الثنائية‬ ‫)األشجار‬
■‫مهمة‬ ‫تعاريف‬:
–‫الشجرة‬ ‫درجة‬:‫عقدة‬ ‫ألوالد‬ ‫األعظمي‬ ‫العدد‬( .‫هي‬ ‫ثنائية‬ ‫شجرة‬ ‫درجة‬2)
–‫الشجرة‬ ‫حجم‬:‫عقدها‬ ‫عدد‬.
–‫عقدة‬ ‫ارتفاع‬:‫الجذر‬ ‫الى‬ ‫العقدة‬ ‫من‬ ‫الواصل‬ ‫الطريق‬ ‫في‬ ‫االتصاالت‬ ‫عدد‬.
–‫الشجرة‬ ‫ارتفاع‬:‫فيها‬ ‫عقدة‬ ‫ارتفاع‬ ‫أطول‬.
–‫الشجرة‬ ‫عرض‬:‫ما‬ ‫مستوى‬ ‫في‬ ‫للعقد‬ ‫األعظم‬ ‫العدد‬.
–‫التجول‬ ‫مسافة‬:‫عقدها‬ ‫ارتفاعات‬ ‫مجموع‬.
–‫الخارجي‬ ‫التجول‬ ‫مسافة‬:‫أوراقها‬ ‫ارتفاعات‬ ‫مجموع‬.
–‫الداخلي‬ ‫التجول‬ ‫مسافة‬:‫الداخلية‬ ‫عقدها‬ ‫ارتفاعات‬ ‫مجموع‬.
2020 By Eng. Joud Khattab
Binary Trees (‫الثنائية‬ ‫)األشجار‬
Exercise
■‫الشجرة‬ ‫جذر‬:n1
■‫االيسر‬ ‫االبن‬:n2
■‫األيمن‬ ‫االبن‬:n4
■‫األوراق‬:n8 – n10 – n5 – n9
■‫الداخلية‬ ‫العقد‬:n1 – n2 – n3 – n4 – n6 – n7
■‫عقدة‬ ‫ارتفاع‬:
n1=0 , n2=n4=1 , n3=n5=n7=2
■‫الشجرة‬ ‫ارتفاع‬:4
■‫التجول‬ ‫مسافة‬:22
■‫الخارجي‬ ‫التجول‬ ‫مسافة‬:13
■‫الداخلي‬ ‫التجول‬ ‫مسافة‬:9
2020 By Eng. Joud Khattab
Binary Trees (‫الثنائية‬ ‫)األشجار‬
■‫الخاصة‬ ‫الثنائية‬ ‫األشجار‬ ‫بعض‬:
–‫الخطية‬ ‫الثنائية‬ ‫الشجرة‬:‫األ‬ ‫على‬ ‫واحد‬ ‫ولد‬ ‫منها‬ ‫عقدة‬ ‫لكل‬ ‫يكون‬ ‫ثنائية‬ ‫شجرة‬‫كثر‬.
–‫التامة‬ ‫الثنائية‬ ‫الشجرة‬:‫المستوى‬ ‫في‬ ‫واحدة‬ ‫عقدة‬ ‫تحوي‬ ‫شجرة‬ ‫كل‬0‫في‬ ‫وعقدتين‬
‫المستوى‬1‫المستوى‬ ‫في‬ ‫عقد‬ ‫وأربع‬2‫و‬2 𝑘‫المستوى‬ ‫في‬ ‫عقدة‬k.
■(‫ارتفاعها‬ ‫تامة‬ ‫بشجرة‬ ‫العقد‬ ‫عدد‬h‫هو‬2ℎ+1
− 1)
–‫الكاملة‬ ‫الثنائية‬ ‫الشجرة‬:‫بال‬ ‫مليئة‬ ‫مستوياتها‬ ‫كل‬ ‫تكون‬ ‫ثنائية‬ ‫شجرة‬ ‫كل‬‫ماعدا‬ ‫عقد‬
‫فراغات‬ ‫على‬ ‫يحوي‬ ‫أن‬ ‫يمكن‬ ‫األخير‬ ‫المستوى‬.
2020 By Eng. Joud Khattab
Binary Trees (‫الثنائية‬ ‫)األشجار‬
Question 1
■‫السؤال‬:‫عقدها‬ ‫عدد‬ ‫خطية‬ ‫شجرة‬ ‫ارتفاع‬ ‫هو‬ ‫ما‬n‫؟‬
■‫اإلجابة‬:n-1
■‫السؤال‬:‫تامة‬ ‫ثنائية‬ ‫شجرة‬ ‫أوراق‬ ‫عدد‬ ‫كم‬‫؟‬
■‫اإلجابة‬:2h‫حيث‬h‫الشجرة‬ ‫ارتفاع‬ ‫هو‬
■‫السؤال‬:‫؟‬ ‫تامة‬ ‫ثنائية‬ ‫لشجرة‬ ‫العقد‬ ‫عدد‬ ‫كم‬
■‫اإلجابة‬:
෍
𝒊=𝟎
𝒊=𝒉
𝟐𝒊 = 𝟐 𝒉+𝟏 − 𝟏
2020 By Eng. Joud Khattab
Binary Trees (‫الثنائية‬ ‫)األشجار‬
Question 2
■‫السؤال‬:‫ثنائية؟‬ ‫بحث‬ ‫شجرة‬ ‫ضمن‬ ‫للبحث‬ ‫حالة‬ ‫أسوأ‬ ‫ماهي‬
■‫اإلجابة‬:‫أعظمية‬ ‫التجول‬ ‫مسافة‬ ‫تكون‬ ‫حيث‬ ‫خطية‬ ‫الشجرة‬ ‫تكون‬ ‫عندما‬.
■‫السؤال‬:‫ثنائية؟‬ ‫بحث‬ ‫شجرة‬ ‫ضمن‬ ‫للبحث‬ ‫حالة‬ ‫أفضل‬ ‫ماهي‬
■‫اإلجابة‬:‫التجول‬ ‫مسافة‬ ‫تكون‬ ‫متوازنة‬ ‫او‬ ‫كاملة‬ ‫الشجرة‬ ‫تكون‬ ‫عندما‬‫أصغرية‬.
2020 By Eng. Joud Khattab
Binary Search Trees
(‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
■‫التالية‬ ‫الخواص‬ ‫تحقق‬ ‫ثنائية‬ ‫شجرة‬ ‫هي‬:
–‫محددة‬ ‫عقدة‬ ‫أجل‬ ‫من‬n‫أصغر‬ ‫هي‬ ‫اليسارية‬ ‫الجزئية‬ ‫الشجرة‬ ‫في‬ ‫المخزنة‬ ‫القيم‬ ‫كل‬
‫العقدة‬ ‫في‬ ‫المخزنة‬ ‫القيمة‬ ‫من‬n.
–‫محددة‬ ‫عقدة‬ ‫أجل‬ ‫من‬n‫أكب‬ ‫هي‬ ‫اليمينية‬ ‫الجزئية‬ ‫الشجرة‬ ‫في‬ ‫المخزنة‬ ‫القيم‬ ‫كل‬‫ر‬
‫العقدة‬ ‫في‬ ‫المخزنة‬ ‫القيمة‬ ‫من‬n.
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫)األشجار‬
Binary search tree Not a binary search tree
5
10
30
2 25 45
5
10
45
2 25 30
5
10
30
2
25
45
Binary search tree
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
Inserting Method
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
Representation Methods
■‫الثنائية‬ ‫األشجار‬ ‫تمثيل‬ ‫طرق‬:
–‫المؤشرات‬ ‫طريق‬ ‫عن‬.
–‫أعمدتها‬ ‫وعدد‬ ‫العقد‬ ‫بعدد‬ ‫أسطرها‬ ‫عدد‬ ‫يكون‬ ‫حيث‬ ‫المصفوفات‬ ‫طريق‬ ‫عن‬3‫حيث‬
‫االبن‬ ‫رقم‬ ‫الثالث‬ ‫وفي‬ ‫االيمن‬ ‫االبن‬ ‫رقم‬ ‫والثاني‬ ‫العقدة‬ ‫رقم‬ ‫األول‬ ‫العمود‬ ‫يحوي‬
‫االيسر‬.
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
Question 3
■‫السؤال‬:‫تعتبر‬ ‫التالية‬ ‫الشجر‬ ‫من‬ ‫أي‬"‫ثنائية‬ ‫بحث‬ ‫شجرة‬"‫؟‬
■‫اإلجابة‬:b‫و‬c
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
Question 4
■‫السؤال‬:‫المصفوفات؟؟‬ ‫طريقة‬ ‫سيئة‬ ‫ماهي‬
■‫اإلجابة‬:‫الكاملة‬ ‫أو‬ ‫التامة‬ ‫غير‬ ‫األشجار‬ ‫حالة‬ ‫في‬ ‫للذاكرة‬ ‫كبير‬ ‫هدر‬ ‫فيها‬.
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
AVL (Height-balanced Trees)
■ An AVL tree (or height-balanced tree) is a binary search tree such that:
– The height of the left and right subtrees of the root differ by at most 1
– The left and right subtrees of the root are AVL trees
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
DFS
■‫الشجرة‬ ‫في‬ ‫التجول‬ ‫طرق‬:
–‫أوال‬ ‫بالعمق‬ ‫التجول‬(depth first search)
33
-1
6
22
16
8
7
45
start
‫التجول‬ ‫في‬ ‫العقد‬ ‫زيارة‬ ‫ترتيب‬VLR:
22,6,-1,8,7,16,33,45
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
DFS
■‫الشجرة‬ ‫في‬ ‫التجول‬ ‫طرق‬:‫أوال‬ ‫بالعمق‬ ‫التجول‬(depth first search)
–VLR‫الترتي‬ ‫ويدعى‬ ،‫اليمينية‬ ‫ثم‬ ‫اليسارية‬ ‫الجزئية‬ ‫الشجرة‬ ‫ثم‬ ‫العقدة‬ ‫يزور‬‫المصدر‬ ‫ب‬
(preorder.)
–VRL‫اليسارية‬ ‫ثم‬ ‫اليمينية‬ ‫الجزئية‬ ‫الشجرة‬ ‫ثم‬ ‫العقدة‬ ‫يزور‬.
–LVR‫الترتي‬ ‫ويدعى‬ ‫اليمينية‬ ‫ثم‬ ‫العقدة‬ ‫ثم‬ ‫اليسارية‬ ‫الجزئية‬ ‫الشجرة‬ ‫يزور‬‫المتناظر‬ ‫ب‬
(inorder.)
–RVL
–LRV‫الملحق‬ ‫الترتيب‬ ‫ويدعى‬(postorder.)
–RLV
2020 By Eng. Joud Khattab
Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬
BFS
■‫الشجرة‬ ‫في‬ ‫التجول‬ ‫طرق‬:
–‫أوال‬ ‫بالعرض‬ ‫التجول‬(breadth first search.)
33
-1
6
22
16
8
7
45
‫التجول‬ ‫في‬ ‫العقد‬ ‫زيارة‬ ‫ترتيب‬VLR:
22,6,33,-1,8,45,7,16
2020 By Eng. Joud Khattab
GRAPHS
‫البيانات‬
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
■‫كعقد‬ ‫العناصر‬ ‫تخزن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬vertex‫العق‬ ‫بين‬ ‫العالقات‬ ‫تمثل‬ ‫وصالت‬ ‫بينها‬ ‫ويوجد‬‫د‬
edges.
■‫النظ‬ ‫الناحية‬ ‫من‬ ‫التسلسلية‬ ‫غير‬ ‫الهرمية‬ ‫للبنى‬ ‫تعميما‬ ‫البيانات‬ ‫اعتبار‬ ‫يمكن‬‫فاألشجار‬ ،‫رية‬
‫البيانات‬ ‫من‬ ‫خاصة‬ ‫حالة‬ ‫هي‬(‫حلقات‬ ‫تحوي‬ ‫ال‬ ‫بيانات‬.)
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
■‫مكان‬ ‫كل‬ ‫في‬ ‫البيانات‬ ‫تتواجد‬:
–‫الحواسيب‬ ‫شبكات‬ ،‫الجوية‬ ‫الخطوط‬ ،‫الطرق‬ ‫شبكات‬.
■‫الصنعي‬ ‫الذكاء‬ ‫في‬ ‫المسائل‬ ‫حل‬ ‫منهجيات‬ ‫أهم‬ ‫من‬:
–‫بيان‬ ‫في‬ ‫بحث‬ ‫مسألة‬ ‫إلى‬ ‫المسألة‬ ‫تحويل‬.
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
■‫العقدة‬ ‫درجة‬Deg(v)‫إليها‬ ‫والواردة‬ ‫العقدة‬ ‫من‬ ‫الصادرة‬ ‫األسهم‬ ‫عدد‬ ‫هي‬
–‫حيث‬Deg-(v)‫الواردة‬ ‫الدرجة‬ ‫هي‬.
–‫و‬Deg+(v)‫الصادرة‬ ‫الدرجة‬ ‫هي‬.
■‫عقدتين‬ ‫كل‬ ‫حالة‬ ‫في‬ ‫كان‬ ‫إذا‬ ‫بشدة‬ ‫متصل‬ ‫البيان‬ ‫يكون‬v,w‫من‬ ‫طريق‬ ‫يوجد‬v‫إلى‬w‫و‬
‫من‬w‫إلى‬v
■‫يحوي‬ ‫موجه‬ ‫غير‬ ‫بيان‬ ‫في‬ ‫األعظمي‬ ‫الروابط‬ ‫عدد‬n‫يساوي‬ ‫عقدة‬
𝑛(𝑛−1)
2
‫هذه‬ ‫وفي‬
‫تام‬ ‫إنه‬ ‫البيان‬ ‫عن‬ ‫نقول‬ ‫الحالة‬(Complete.)
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
■‫التجاور‬ ‫مصفوفة‬ ‫باستخدام‬ ‫البيان‬ ‫تمثيل‬(adjacency matrix.)
The Graph
The Adjacency Matrix
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
■‫التجاور‬ ‫قائمة‬ ‫باستخدام‬ ‫البيان‬ ‫تمثيل‬(adjacency list.)
The Adjacency List
The Graph
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
Question 1
■‫السؤال‬:‫التجاور؟‬ ‫قائمة‬ ‫بطريقة‬ ‫ممثلة‬ ‫لعقدة‬ ‫مجاورة‬ ‫عقد‬ ‫عن‬ ‫البحث‬ ‫كلفة‬ ‫ماهي‬
■‫الجواب‬:O(deg(v))
■‫السؤال‬:‫التج‬ ‫قائمة‬ ‫بطريقة‬ ‫ممثل‬ ‫بيان‬ ‫في‬ ‫لعقدة‬ ‫الواردة‬ ‫الروابط‬ ‫مسح‬ ‫كلفة‬ ‫ماهي‬‫اور؟‬
■‫الجواب‬:O(V+E)‫جدا‬ ‫مكلف‬
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
■‫البيان‬ ‫في‬ ‫التجول‬ ‫طرق‬:
–‫أوال‬ ‫العمق‬(DFS.)
–‫أوال‬ ‫العرض‬(BFS:)‫الوصول‬ ‫ألن‬ ‫موزون‬ ‫غير‬ ‫بيان‬ ‫في‬ ‫طريق‬ ‫أقصر‬ ‫إليجاد‬ ‫طريقة‬ ‫هي‬
‫للروابط‬ ‫عدد‬ ‫أقل‬ ‫بمسح‬ ‫يتم‬ ‫للعقد‬.
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
DFS V.S BFS
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
Dijkstra
■‫خوارزمية‬Dijkstra‫موزون‬ ‫بيان‬ ‫في‬ ‫طريق‬ ‫أقصر‬ ‫إليجاد‬.
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
Dijkstra 1
6
2
5
4
3
8
9
7
4
7
12
3
4
5
11
8
6
9
2
1 2 3 4 5 6 7 8 9
0 ? ? ? ? ? ? ? ?
-1 -1 -1 -1 -1 -1 -1 -1 -1
Processed
distance
predecessor
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
Topological Sort
■‫الفرز‬‫الطبولوجي‬‫األسهم‬ ‫كل‬ ‫تكون‬ ‫حيث‬ ‫ورودها‬ ‫درجات‬ ‫حسب‬ ‫العقد‬ ‫ترتيب‬ ‫على‬ ‫يعتمد‬‫او‬
‫اليمين‬ ‫هي‬ ‫واحدة‬ ‫جهة‬ ‫إلى‬ ‫تؤشر‬ ‫الوصالت‬.
■‫حلقات‬ ‫على‬ ‫يحتوي‬ ‫الذي‬ ‫البيان‬ ‫على‬ ‫تطبيقها‬ ‫يمكن‬ ‫ال‬.
■‫مثال‬:
–‫لجامعة‬ ‫السنوي‬ ‫المنهاج‬.
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
Topological Sort 1
2
4
5 3
6
7
8
next 0
1 2 3 4 5 6 7 8
2 2 3 2 1 1 0 2
Node
Indegree
LIST
7
2020 By Eng. Joud Khattab
Graphs (‫)البيانات‬
Minimum Spanning Tree
■‫االرتباط‬ ‫شجرة‬‫األصغرية‬:‫الروابط‬ ‫من‬ ‫ممكنة‬ ‫كلفة‬ ‫بأقل‬ ‫البيان‬ ‫تربط‬ ‫شجرة‬ ‫هي‬.
■‫فقط‬ ‫المترابط‬ ‫البيان‬ ‫حالة‬ ‫في‬ ‫الشجرة‬ ‫هذه‬ ‫تتواجد‬.
■Prim’s algorithm
a
c
e
d
b
2
45
9
6
4
5
5
a
c
e
d
b
2
45
9
6
4
5
5
2020 By Eng. Joud Khattab
SORTING ALGORITHMS
‫الترتيب‬ ‫خوارزميات‬
2020 By Eng. Joud Khattab
Bubble Sort Algorithm
( ‫الفرز‬ ‫خوارزمية‬‫الفقاعي‬ )
■‫الفرز‬ ‫خوارزمية‬ ‫تعقيد‬‫الفقاعي‬:
–‫األحوال‬ ‫أحسن‬:‫حيث‬ ‫مفروزة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬‫اليوجد‬‫اسناد‬ ‫عمليات‬.
–‫األحوال‬ ‫أسوأ‬:‫المصفوفة‬ ‫تكون‬ ‫عندما‬‫مرتية‬‫عمليات‬ ‫عدد‬ ‫يكون‬ ‫عكسي‬ ‫ترتيب‬
‫مرتبة‬ ‫من‬ ‫االسناد‬O(n*n).
–‫الوسطية‬ ‫الحالة‬:ً‫عشوائيا‬ ‫مرتبة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬O(n*n).
2020 By Eng. Joud Khattab
Selection Sort Algorithm
(‫باالختيار‬ ‫الفرز‬ ‫)خوارزمية‬
■‫الخوارزمية‬ ‫تعقيد‬:
–‫المقارنة‬ ‫عمليات‬ ‫عدد‬O(n*n)
–‫التبديل‬ ‫عمليات‬ ‫عدد‬O(n)
■‫مكل‬ ‫غير‬ ‫المقارنة‬ ‫وعملية‬ ‫مكلفة‬ ‫التبديل‬ ‫عملية‬ ‫كانت‬ ‫حالة‬ ‫وفي‬ ‫صغير‬ ‫لحجم‬ ‫جيدة‬‫فة‬.
2020 By Eng. Joud Khattab
Insertion Sort Algorithm
(‫باإلضافة‬ ‫الفرز‬ ‫)خوارزمية‬
■‫باإلضافة‬ ‫الفرز‬ ‫خوارزمية‬ ‫تعقيد‬:
–‫األحوال‬ ‫أحسن‬:‫اسناد‬ ‫عمليات‬ ‫يوجد‬ ‫ال‬ ‫حيث‬ ‫مفروزة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬O(1)
‫المقارنة‬ ‫وعمليات‬O(n).
–‫األحوال‬ ‫أسوأ‬:‫المصفوفة‬ ‫تكون‬ ‫عندما‬‫مرتية‬‫عمليات‬ ‫عدد‬ ‫يكون‬ ‫عكسي‬ ‫ترتيب‬
‫مرتبة‬ ‫من‬ ‫االسناد‬O(n*n).
–‫الوسطية‬ ‫الحالة‬:ً‫عشوائيا‬ ‫مرتبة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬O(n*n).
2020 By Eng. Joud Khattab
Merge Sort Algorithm
(‫بالدمج‬ ‫الفرز‬ ‫)خوارزمية‬
■‫تسد‬ ‫فرق‬ ‫مبدأ‬ ‫تعتمد‬.
■‫يلي‬ ‫بما‬ ‫تقوم‬ ‫عوديه‬ ‫خوارزمية‬ ‫هي‬:
–،‫جزئين‬ ‫إلى‬ ‫المصفوفة‬ ‫تقسم‬
–،‫حدا‬ ‫على‬ ‫جزء‬ ‫كل‬ ‫تفرز‬
–‫المفروزين‬ ‫الجزئيين‬ ‫تدمج‬
‫مفروزة‬ ‫واحدة‬ ‫مصفوفة‬ ‫في‬.
■‫الخوارزمية‬ ‫تعقيد‬:
–O(nlog(n))‫دوما‬
2020 By Eng. Joud Khattab
Quick Sort Algorithm
(‫السريع‬ ‫الفرز‬ ‫)خوارزمية‬
■‫الخوارزمية‬ ‫تعقيد‬:
–O(nlog(n))‫الوسطية‬ ‫والحالة‬ ‫األحوال‬ ‫أحسن‬ ‫في‬.
–O(n*n)‫األحوال‬ ‫أسوأ‬ ‫في‬.
2020 By Eng. Joud Khattab
Sorting Algorithms
2020 By Eng. Joud Khattab
SEARCH ALGORITHMS
‫مصفوفة‬ ‫في‬ ‫البحث‬ ‫خوارزميات‬
2020 By Eng. Joud Khattab
Search Algorithms
Binary V.S. Sequential
■‫التسلسلي‬ ‫البحث‬:‫تعقيده‬O(n)
■‫الثنائي‬ ‫البحث‬:‫تعقيده‬O(log(n))
2020 By Eng. Joud Khattab
ADVANCE ALGORITHMS
‫متقدمة‬ ‫خوارزميات‬
2020 By Eng. Joud Khattab
Backtracking Algorithms
(‫التراجعية‬ ‫)الخوارزميات‬
■‫خوارزميات‬ ‫هي‬‫عودية‬‫المشاكل‬ ‫حل‬ ‫في‬ ‫والخطأ‬ ‫التجريب‬ ‫طريقة‬ ‫تعتمد‬.
■‫الخطوات‬ ‫من‬ ‫مجموعة‬ ‫طريق‬ ‫عن‬ ‫للمسألة‬ ‫النهائي‬ ‫الحل‬ ‫ببناء‬ ‫الطريقة‬ ‫هذه‬ ‫تتلخص‬:
–،‫التالية‬ ‫للخطوة‬ ‫المتاحة‬ ‫اإلمكانيات‬ ‫نحدد‬ ‫الخطوة‬ ‫في‬
–،‫أحدها‬ ‫ننتقي‬ ‫بأن‬ ‫اإلمكانيات‬ ‫هذه‬ ‫ندرس‬ ‫ثم‬
–،‫النهائي‬ ‫الحل‬ ‫في‬ ‫التالية‬ ‫الخطوة‬ ‫أنها‬ ‫على‬ ‫نسجلها‬ ‫و‬
–‫الخطوة‬ ‫هذه‬ ‫على‬ ً‫اعتمادا‬ ‫الخوارزمية‬ ‫نتابع‬ ‫و‬.
–‫مسدو‬ ‫طريق‬ ‫إلى‬ ‫يؤدي‬ ‫أو‬ ،‫النهائي‬ ‫الحل‬ ‫إلى‬ ‫يقود‬ ‫ال‬ ‫اختيارنا‬ ‫أن‬ ‫لنا‬ ‫يظهر‬ ‫عندما‬،‫د‬
–‫الخطوة‬ ‫هذه‬ ‫عن‬ ‫نعدل‬.
■‫مرتين‬ ‫الخطأ‬ ‫في‬ ‫الوقوع‬ ‫تجنب‬ ‫في‬ ‫يفيد‬ ‫أخطاء‬ ‫سجل‬ ‫بناء‬ ‫العملية‬ ‫هذه‬ ‫تشبه‬.
2020 By Eng. Joud Khattab
Backtracking Algorithms
(‫التراجعية‬ ‫)الخوارزميات‬
■‫مثال‬:
–‫الشطرنج‬ ‫حصان‬ ‫جولة‬ ‫مسألة‬:
■‫باست‬ ‫وذلك‬ ‫الحصان‬ ‫فيه‬ ‫يقف‬ ‫معين‬ ‫موقع‬ ‫من‬ ‫الشطرنج‬ ‫رقعة‬ ‫لتغطية‬ ‫طريقة‬ ‫إيجاد‬‫خدام‬
‫واحدة‬ ‫مرة‬ ‫مربع‬ ‫بكل‬ ‫المرور‬ ‫وبشرط‬ ‫الشطرنج‬ ‫في‬ ‫المعروفة‬ ‫الحصان‬ ‫حركات‬.
–‫الثمانية‬ ‫الوزراء‬ ‫مسألة‬:
■‫لألخر‬ ‫مهدد‬ ‫واحد‬ ‫اي‬ ‫فيها‬ ‫يكون‬ ‫ال‬ ‫بحيث‬ ‫الشطرنج‬ ‫رقعة‬ ‫على‬ ‫وزراء‬ ‫ثمانية‬ ‫توزيع‬.
–‫األمثل‬ ‫الخيار‬ ‫مسألة‬:
■‫معاي‬ ‫وفق‬ ‫األمثل‬ ‫بالحل‬ ‫واالحتفاظ‬ ‫معينة‬ ‫لمسألة‬ ‫ايجادها‬ ‫يمكن‬ ‫التي‬ ‫الحلول‬ ‫مقارنة‬‫ير‬
‫للمسألة‬ ‫محددة‬.
2020 By Eng. Joud Khattab
Greedy Algorithms
(‫الجشعة‬ ‫)الخوارزميات‬
■‫هي‬‫خوارزمية‬‫على‬ ‫تستند‬ ‫التي‬‫المهني‬ ‫الحدس‬‫اإلمكاني‬ ‫اختيار‬ ‫طريقه‬ ‫عن‬ ‫يتم‬ ‫الذي‬‫ة‬
‫الحالية‬ ‫المرحلة‬ ‫في‬ ‫المرئية‬ ‫األفضل‬(‫الحالية‬ ‫المرحلة‬ ‫في‬ ‫األمثل‬ ‫الحل‬),‫األ‬ ‫دون‬ ‫من‬‫خذ‬
‫الحل‬ ‫تكملة‬ ‫على‬ ‫الخطوة‬ ‫هذه‬ ‫تأثير‬ ‫بالحسبان‬.
■‫للمسألة‬ ‫األمثل‬ ‫الحل‬ ‫إلى‬ ‫المرحلي‬ ‫األمثل‬ ‫الحل‬ ‫يقودنا‬ ‫ال‬ ‫قد‬.
■‫خياراتها‬ ‫عن‬ ‫تتراجع‬ ‫ان‬ ‫يكن‬ ‫ال‬ ‫الجشع‬ ‫خوارزمية‬.‫بينها‬ ‫الرئيسي‬ ‫الفرق‬ ‫هو‬ ‫هذا‬
‫وبين‬‫الديناميكية‬ ‫البرمجة‬.
■‫وأشجار‬ ‫برايم‬ ‫خوارزمية‬ ‫مثل‬‫هوفمان‬.
2020 By Eng. Joud Khattab
Divide and Conquer
(‫تسد‬ ‫فرق‬ ‫)خوارزميات‬
■‫عمل‬‫خوارزمية‬‫مسألتين‬ ‫إلى‬ ‫عودي‬ ‫بشكل‬ ‫المسألة‬ ‫تقسيم‬ ‫طريق‬ ‫عن‬ ‫تسد‬ ‫فرق‬
‫فيه‬ ‫بما‬ ‫بسيطة‬ ‫الجزئية‬ ‫المسائل‬ ‫تصبح‬ ‫حتى‬ ،‫النوع‬ ‫نفس‬ ‫من‬ ‫أكثر‬ ‫أو‬ ‫جزئيتين‬‫الكفاية‬
‫مباشر‬ ‫بشكل‬ ‫لتحل‬.‫ا‬ ‫للمسألة‬ ً‫حال‬ ‫لتعطي‬ ‫الجزئية‬ ‫المسائل‬ ‫حلول‬ ‫تدمج‬ ‫ثم‬ ‫ومن‬‫لجزئية‬.
■‫امثلة‬:
–‫الثنائي‬ ‫البحث‬ ‫خوارزميات‬.
–‫بالدمج‬ ‫الفرز‬ ‫خوارزميات‬.
–‫السريع‬ ‫الفرز‬ ‫خوارزميات‬.
–‫هانوي‬ ‫ابراج‬ ‫خوارزمية‬.
2020 By Eng. Joud Khattab
Dynamic Programming
(‫الديناميكية‬ ‫)البرمجة‬
■‫المسألة‬ ‫من‬ ‫مختلفة‬ ‫أجزاء‬ ‫حل‬ ‫إلى‬ ‫بحاجة‬ ‫نحن‬ ،‫ما‬ ‫مسألة‬ ‫لحل‬(‫فرعية‬ ‫مسائل‬)‫ومن‬ ،
‫شامل‬ ‫حل‬ ‫على‬ ‫للحصول‬ ‫الفرعية‬ ‫المسائل‬ ‫حلول‬ ‫جمع‬ ‫ثم‬.
■‫الديناميكية‬ ‫البرمجة‬ ‫نهج‬:
–،‫فقط‬ ‫واحدة‬ ‫مرة‬ ‫فرعية‬ ‫مسألة‬ ‫كل‬ ‫حل‬ ‫عن‬ ‫البحث‬
–‫الحسابات‬ ‫عدد‬ ‫تقليل‬ ‫وبالتالي‬:‫حف‬ ‫يتم‬ ،‫ما‬ ‫فرعية‬ ‫مسألة‬ ‫حل‬ ‫حساب‬ ‫تم‬ ‫حالما‬،‫ظه‬
‫استرجاعه‬ ‫ببساطة‬ ‫يتم‬ ،‫نفسه‬ ‫للحل‬ ‫الحاجة‬ ‫عند‬ ‫القادمة‬ ‫المرة‬ ‫وفي‬.
■‫وتق‬ ‫الثانوية‬ ‫للمسائل‬ ‫السابقة‬ ‫الحلول‬ ‫ستدرس‬ ‫الديناميكية‬ ‫البرمجة‬ ‫خوارزميات‬‫بدمجها‬ ‫وم‬
‫حله‬ ‫المراد‬ ‫للمسائلة‬ ‫حل‬ ‫افضل‬ ‫علي‬ ‫للحصول‬.
2020 By Eng. Joud Khattab
HASHING FUNCTION
(‫التقطيع‬ ‫)جداول‬
2020 By Eng. Joud Khattab
Hashing Tables
(‫التقطيع‬ ‫)جداول‬
■‫موقعه‬ ‫إلى‬ ‫المباشر‬ ‫النفاذ‬ ‫خالل‬ ‫من‬ ‫بحث‬ ‫خوارزمية‬ ‫إلى‬ ‫الحاجة‬ ‫دون‬ ‫مباشرة‬ ‫عنصر‬ ‫لإليجاد‬ ‫طريقة‬ ‫هي‬.
■‫التالية‬ ‫التطبيقات‬ ‫برمجة‬ ‫في‬ ‫فعالة‬ ‫بنية‬ ‫هي‬:
–‫معجم‬ ‫عمليات‬ ‫إلى‬ ‫تحتاج‬ ‫التي‬.
–‫بالترتيب‬ ‫تهتم‬ ‫ال‬ ‫التي‬ ‫االمثلة‬.
■‫المفتاح‬ ‫ذو‬ ‫العنصر‬ ‫يخزن‬k‫الخانة‬ ‫في‬h(k)‫حيث‬h‫الخانة‬ ‫دليل‬ ‫لحساب‬ ‫يستخدم‬ ‫الذي‬ ‫التقطيع‬ ‫تابع‬ ‫هو‬
‫المفتاح‬ ‫من‬k.
■‫التقطيع‬ ‫تابع‬ ‫قيمة‬ ‫نفس‬ ‫لهما‬ ‫مفتاحين‬ ‫وجود‬ ‫حال‬ ‫في‬ ‫تصادم‬ ‫يحدث‬ ‫قد‬.
■‫من‬ ‫ازواج‬ ‫شكل‬ ‫على‬ ‫القيم‬ ‫تخزن‬(key, value)
■‫القيم‬ ‫من‬ ‫سلسلة‬ ‫حول‬ ‫للتجول‬ ‫جيدة‬ ‫بنية‬ ‫ليست‬ ‫التقطيع‬ ‫جداول‬( .Iteration)
■‫مناسبة‬ ‫فرضيات‬ ‫ضمن‬ ‫تقطيع‬ ‫جدول‬ ‫في‬ ‫عنصر‬ ‫عن‬ ‫والبحث‬ ‫إلضافة‬ ‫المتوقع‬ ‫الزمن‬O(1)( .‫الوسطية‬ ‫الحالة‬)
2020 By Eng. Joud Khattab
Hashing Tables V.S.
Other Data Structures
■ We want to implement the dictionary operations Insert(), Delete() and Search()/Find() efficiently.
■ Arrays:
– can accomplish in O(n) time
– but are not space efficient (assumes we leave empty space for keys not currently in
dictionary)
■ Binary search trees
– can accomplish in O(log n) time
– are space efficient.
■ Hash Tables:
– A generalization of an array that under some reasonable assumptions is O(1) for
Insert/Delete/Search of a key
2020 By Eng. Joud Khattab
Hashing Tables
(‫التقطيع‬ ‫)جداول‬
■‫المباشرة‬ ‫العنونة‬ ‫باستخدام‬ ‫المعلومات‬ ‫تخزين‬ ‫عن‬ ‫مثال‬:
■‫مفتاح‬ ‫لكل‬ ‫الجدول‬ ‫من‬ ‫موقع‬ ‫منح‬ ‫نستطيع‬ ‫عندما‬ ‫تستخدم‬(‫ت‬ ‫المتوقع‬ ‫العناصر‬ ‫عدد‬‫خزينها‬
‫للعناصر‬ ‫الكلي‬ ‫العدد‬ ‫من‬ ‫قريب‬.
Anas - Mazzah
0000001
6131467
6131468
6131469
6131470
9999997
9999998
9999999
Each phone number
uniquely determines an
array element
0000000
Record for phone
number 6131496
For technical or
commercial reasons,
certain numbers may not
be assigned to any
subscriber
2020 By Eng. Joud Khattab
Hashing Tables
(‫التقطيع‬ ‫)جداول‬
■ For example, if we hash keys 0…1000 into a hash table with 5 entries and use
h(key) = key mod 5 , we get the following sequence of events:
0
1
2
3
4
key data
Insert 2
2 …
0
1
2
3
4
key data
Insert 21
2 …
21 …
0
1
2
3
4
key data
Insert 34
2 …
21 …
34 …
Insert 54
There is a
collision at
array entry
#4
???
2020 By Eng. Joud Khattab
Hashing Tables
(‫التقطيع‬ ‫)جداول‬
■‫التصادم‬ ‫لحل‬ ‫الربط‬ ‫تقنية‬:
–‫خطية‬ ‫سلسلة‬ ‫في‬ ‫التقطيع‬ ‫تابع‬ ‫قيمة‬ ‫نفس‬ ‫لها‬ ‫التي‬ ‫العناصر‬ ‫جميع‬ ‫توضع‬.
(Hashing with Chaining)
–‫المتصادمة‬ ‫العناصر‬ ‫سلسلة‬ ‫بداية‬ ‫إلى‬ ‫مؤشر‬ ‫الجدول‬ ‫خانة‬ ‫تصبح‬.
2020 By Eng. Joud Khattab
Hashing Tables (‫التقطيع‬ ‫)جداول‬
Hashing with Chaining
0
1
2
3
4
other
key key data
Insert 54
2
21
54 34
CHAIN
0
1
2
3
4
Insert 101
2
21
54 34
101
2020 By Eng. Joud Khattab
Hashing Tables (‫التقطيع‬ ‫)جداول‬
Hashing with Chaining
■ What is the running time to insert/search/delete?
– Insert: It takes O(1) time to compute the hash function and insert at head of
linked list
– Search: It is proportional to max linked list length
– Delete: Same as search
2020 By Eng. Joud Khattab
Hashing Tables (‫التقطيع‬ ‫)جداول‬
Question 1
■‫السؤال‬:‫عنصر؟‬ ‫إضافة‬ ‫عملية‬ ‫كلفة‬ ‫ماهي‬
■‫الجواب‬:O(1)‫السلسلة‬ ‫رأس‬ ‫في‬ ‫المتصادمة‬ ‫للعناصر‬ ‫اإلضافة‬ ‫تتم‬ ‫حيث‬.
■‫السؤال‬:‫األحوال؟‬ ‫أسوأ‬ ‫في‬ ‫والحذف‬ ‫البحث‬ ‫عملية‬ ‫كلفة‬ ‫ماهي‬
■‫الجواب‬:‫االحوال‬ ‫أسوأ‬ ‫في‬ ‫وهي‬ ‫المتصادمة‬ ‫للعناصر‬ ‫الخطية‬ ‫السلسلة‬ ‫بطول‬ ‫تتعلق‬O(n)‫عند‬
‫سيء‬ ‫تقطيع‬ ‫تابع‬ ‫اختيار‬.
■‫السؤال‬:‫واالضافة؟‬ ‫للحذف‬ ‫الوسطية‬ ‫الكلفة‬ ‫ماهي‬
■‫الجواب‬:‫م‬ ‫توزع‬ ‫يحقق‬ ‫تقطيع‬ ‫تابع‬ ‫استخدام‬ ‫عند‬ ‫السلسلة‬ ‫في‬ ‫الوسطي‬ ‫العناصر‬ ‫عدد‬ ‫هو‬‫نتظم‬
‫وهو‬n/m‫حيث‬n‫و‬ ‫الكلي‬ ‫العناصر‬ ‫عدد‬m‫الجدول‬ ‫في‬ ‫الخانات‬ ‫عدد‬.
2020 By Eng. Joud Khattab
Hashing Function (‫التقطيع‬ ‫)توابع‬
■‫التقسيم‬ ‫طريقة‬:
–‫المفتاح‬ ‫بربط‬k‫قسمة‬ ‫باقي‬ ‫تساوي‬ ‫التي‬ ‫بالخانة‬k‫على‬m.
–h(k)=k%m
–‫قيم‬ ‫تجنب‬ ‫يجب‬m‫قوى‬ ‫من‬2‫عنها‬ ‫بعيدة‬ ‫أولية‬ ‫أعداد‬ ‫واختيار‬.
■‫الضرب‬ ‫طريقة‬:
–‫المفتاح‬ ‫نضرب‬k‫بثابت‬A‫حيث‬0<A<1‫القيمة‬ ‫هذه‬ ‫نضرب‬ ‫ثم‬ ‫الكسري‬ ‫الجزء‬ ‫ونأخذ‬
‫ب‬m‫الناتج‬ ‫العدد‬ ‫من‬ ‫الطبيعي‬ ‫الجزء‬ ‫ونأخذ‬.
–‫للعدد‬ ‫قيمة‬ ‫أي‬ ‫اختيار‬ ‫يمكن‬m.
2020 By Eng. Joud Khattab
MCQ
2020 By Eng. Joud Khattab
Question 1
■ For a binary search algorithm to work, it is necessary that the array (list) must be?
A. sorted
B. unsorted
C. in a heap
D. popped out of stack
2020 By Eng. Joud Khattab
Question 1
■ For a binary search algorithm to work, it is necessary that the array (list) must be?
A. sorted
B. unsorted
C. in a heap
D. popped out of stack
2020 By Eng. Joud Khattab
Question 2
■ Which one of the below mentioned is linear data structure?
A. Queue
B. Stack
C. Arrays
D. All of the above
2020 By Eng. Joud Khattab
Question 2
■ Which one of the below mentioned is linear data structure?
A. Queue
B. Stack
C. Arrays
D. All of the above
2020 By Eng. Joud Khattab
Question 3
■ Binary search tree has best case run-time complexity of Ο(log n). What could the
worst case?
A. Ο(n)
B. Ο(n2)
C. Ο(n3)
D. None of the above
2020 By Eng. Joud Khattab
Question 3
■ Binary search tree has best case run-time complexity of Ο(log n). What could the
worst case?
A. Ο(n)
B. Ο(n2)
C. Ο(n3)
D. None of the above
2020 By Eng. Joud Khattab
Question 4
■ An algorithm is?
A. a piece of code to be executed.
B. a loosely written code to make final code.
C. a step by step procedure to solve problem.
D. all of the above.
2020 By Eng. Joud Khattab
Question 4
■ An algorithm is?
A. a piece of code to be executed.
B. a loosely written code to make final code.
C. a step by step procedure to solve problem.
D. all of the above.
2020 By Eng. Joud Khattab
Question 5
■ Quick sort running time depends on the selection of?
A. size of array
B. pivot element
C. sequence of values
D. none of the above!
2020 By Eng. Joud Khattab
Question 5
■ Quick sort running time depends on the selection of?
A. size of array
B. pivot element
C. sequence of values
D. none of the above!
2020 By Eng. Joud Khattab
Question 6
■ A queue data-structure can be used for?
A. expression parsing
B. recursion
C. resource allocation
D. all of the above
2020 By Eng. Joud Khattab
Question 6
■ A queue data-structure can be used for?
A. expression parsing
B. recursion
C. resource allocation
D. all of the above
2020 By Eng. Joud Khattab
Question 7
■ Program with highest run-time complexity is?
A. Tower of Hanoi
B. Fibonacci Series
C. Prime Number Series
D. None of the above
2020 By Eng. Joud Khattab
Question 7
■ Program with highest run-time complexity is?
A. Tower of Hanoi
B. Fibonacci Series
C. Prime Number Series
D. None of the above
2020 By Eng. Joud Khattab
Question 8
■ From a complete graph, by removing maximum _______________ edges, we can
construct a spanning tree?
A. e-n+1
B. n-e+1
C. n+e-1
D. e-n-1
2020 By Eng. Joud Khattab
Question 8
■ From a complete graph, by removing maximum _______________ edges, we can
construct a spanning tree?
A. e-n+1
B. n-e+1
C. n+e-1
D. e-n-1
2020 By Eng. Joud Khattab
Question 9
■ The worst case complexity of binary search matches with?
A. interpolation search
B. linear search
C. merge sort
D. none of the above
2020 By Eng. Joud Khattab
Question 9
■ The worst case complexity of binary search matches with?
A. interpolation search
B. linear search
C. merge sort
D. none of the above
2020 By Eng. Joud Khattab
Question 10
■ What is a hash table?
A. A structure that maps values to keys.
B. A structure that maps keys to values.
C. A structure used for storage.
D. A structure used to implement stack and queue.
2020 By Eng. Joud Khattab
Question 10
■ What is a hash table?
A. A structure that maps values to keys.
B. A structure that maps keys to values.
C. A structure used for storage.
D. A structure used to implement stack and queue.
2020 By Eng. Joud Khattab
Question 11
■ The recurrence relation capturing the optimal time of the Tower of Hanoi problem
with n discs is
A. T(n) = 2T(n – 2) + 2
B. T(n) = 2T(n – 1) + n
C. T(n) = 2T(n/2) + 1
D. T(n) = 2T(n – 1) + 1
2020 By Eng. Joud Khattab
Question 11
■ The recurrence relation capturing the optimal time of the Tower of Hanoi problem
with n discs is
A. T(n) = 2T(n – 2) + 2
B. T(n) = 2T(n – 1) + n
C. T(n) = 2T(n/2) + 1
D. T(n) = 2T(n – 1) + 1
2020 By Eng. Joud Khattab
Question 12
■ What does the following function do for a given Linked List with first node as head?
void fun1(struct node* head) {
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data); }
A. Prints all nodes of linked lists
B. Prints all nodes of linked list in reverse order
C. Prints alternate nodes of Linked List
D. Prints alternate nodes in reverse order
2020 By Eng. Joud Khattab
Question 12
■ What does the following function do for a given Linked List with first node as head?
void fun1(struct node* head) {
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data); }
A. Prints all nodes of linked lists
B. Prints all nodes of linked list in reverse order
C. Prints alternate nodes of Linked List
D. Prints alternate nodes in reverse order
2020 By Eng. Joud Khattab
Question 13
■ Which of the following points is/are true about Linked List data structure when it is
compared with array
A. Arrays have better cache locality that can make them better in terms of
performance
B. It is easy to insert and delete elements in Linked List
C. Random access is not allowed in a typical implementation of Linked Lists
D. All of the above
2020 By Eng. Joud Khattab
Question 13
■ Which of the following points is/are true about Linked List data structure when it is
compared with array
A. Arrays have better cache locality that can make them better in terms of
performance
B. It is easy to insert and delete elements in Linked List
C. Random access is not allowed in a typical implementation of Linked Lists
D. All of the above
2020 By Eng. Joud Khattab
Question 14
■ Which of the following sorting algorithms can be used to sort a random linked list
with minimum time complexity?
A. Insertion Sort
B. Quick Sort
C. Heap Sort
D. Merge Sort
2020 By Eng. Joud Khattab
Question 14
■ Which of the following sorting algorithms can be used to sort a random linked list
with minimum time complexity?
A. Insertion Sort
B. Quick Sort
C. Heap Sort
D. Merge Sort
2020 By Eng. Joud Khattab
Question 15
■ In the worst case, the number of comparisons needed to search a singly linked list
of length n for a given element is
A. log 2 n
B. n/2
C. log 2 n – 1
D. n
2020 By Eng. Joud Khattab
Question 15
■ In the worst case, the number of comparisons needed to search a singly linked list
of length n for a given element is
A. log 2 n
B. n/2
C. log 2 n – 1
D. n
2020 By Eng. Joud Khattab
Question 16
■ Which one of the following is an application of Stack Data Structure?
A. Managing function calls
B. The stock span problem
C. Arithmetic expression evaluation
D. All of the above
2020 By Eng. Joud Khattab
Question 16
■ Which one of the following is an application of Stack Data Structure?
A. Managing function calls
B. The stock span problem
C. Arithmetic expression evaluation
D. All of the above
2020 By Eng. Joud Khattab
Question 17
■ The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is
A. 284
B. 213
C. 142
D. 71
2020 By Eng. Joud Khattab
Question 17
■ The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is
A. 284
B. 213
C. 142
D. 71
2020 By Eng. Joud Khattab
Question 18
■ How many stacks are needed to implement a queue. Consider the situation where
no other data structure like arrays, linked list is available to you.
A. 1
B. 2
C. 3
D. 4
2020 By Eng. Joud Khattab
Question 18
■ How many stacks are needed to implement a queue. Consider the situation where
no other data structure like arrays, linked list is available to you.
A. 1
B. 2
C. 3
D. 4
2020 By Eng. Joud Khattab
Question 19
■ The most appropriate matching for the following pairs
X: depth first search 1: heap
Y: breadth-first search 2: queue
Z: sorting 3: stack
A. X—1, Y—2 ,Z –3
B. X—3, Y—1, Z –2
C. X—3, Y—2, Z—1
D. X—2 ,Y—3 , Z--1
2020 By Eng. Joud Khattab
Question 19
■ The most appropriate matching for the following pairs
X: depth first search 1: heap
Y: breadth-first search 2: queue
Z: sorting 3: stack
A. X—1, Y—2 ,Z –3
B. X—3, Y—1, Z –2
C. X—3, Y—2, Z—1
D. X—2 ,Y—3 , Z--1
2020 By Eng. Joud Khattab
Question 20
■ Aliasing in the context of programming languages refers to
A. multiple variables having the same memory location
B. multiple variables having the same value
C. multiple variables having the same identifier
D. multiple uses of the same variable
2020 By Eng. Joud Khattab
Question 20
■ Aliasing in the context of programming languages refers to
A. multiple variables having the same memory location
B. multiple variables having the same value
C. multiple variables having the same identifier
D. multiple uses of the same variable
2020 By Eng. Joud Khattab
Question 21
■ Randomized quicksort is an extension of quicksort where the pivot is chosen
randomly. What is the worst case complexity of sorting n numbers using randomized
quicksort?
A. O(n)
B. O(n Log n)
C. O(n^2)
D. O(n!)
2020 By Eng. Joud Khattab
Question 21
■ Randomized quicksort is an extension of quicksort where the pivot is chosen
randomly. What is the worst case complexity of sorting n numbers using randomized
quicksort?
A. O(n)
B. O(n Log n)
C. O(n^2)
D. O(n!)
2020 By Eng. Joud Khattab
Question 22
■ The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3
children is:
A. n/2
B. (n - 1)/3
C. (n - 1)/2
D. (2n + 1)/3
2020 By Eng. Joud Khattab
Question 22
■ The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3
children is:
A. n/2
B. (n - 1)/3
C. (n - 1)/2
D. (2n + 1)/3
2020 By Eng. Joud Khattab
Question 23
■ Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an
initially empty binary search tree. The binary search tree uses the usual ordering on
natural numbers. What is the in-order traversal sequence of the resultant tree ?
A. 7 5 1 0 3 2 4 6 8 9
B. 0 2 4 3 1 6 5 9 8 7
C. 0 1 2 3 4 5 6 7 8 9
D. 9 8 6 4 2 3 0 1 5 7
2020 By Eng. Joud Khattab
Question 23
■ Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an
initially empty binary search tree. The binary search tree uses the usual ordering on
natural numbers. What is the in-order traversal sequence of the resultant tree ?
A. 7 5 1 0 3 2 4 6 8 9
B. 0 2 4 3 1 6 5 9 8 7
C. 0 1 2 3 4 5 6 7 8 9
D. 9 8 6 4 2 3 0 1 5 7
2020 By Eng. Joud Khattab
Question 24
■ Consider the following graph. Among the following sequences, Which are depth first
traversals of the graph?
I) a b e g h f
II) a b f e h g
III) a b f h g e
IV) a f g h b e
A. I, II and IV only
B. I and IV only
C. II, III and IV only
D. I, III and IV only
2020 By Eng. Joud Khattab
Question 24
■ Consider the following graph. Among the following sequences, Which are depth first
traversals of the graph?
I) a b e g h f
II) a b f e h g
III) a b f h g e
IV) a f g h b e
A. I, II and IV only
B. I and IV only
C. II, III and IV only
D. I, III and IV only
2020 By Eng. Joud Khattab
Question 25
■ What is the weight of a minimum spanning tree of the following graph ?
A. 29
B. 31
C. 38
D. 41
2020 By Eng. Joud Khattab
Question 25
■ What is the weight of a minimum spanning tree of the following graph ?
A. 29
B. 31
C. 38
D. 41
2020 By Eng. Joud Khattab
Question 26
■ The best data structure to check whether an arithmetic expression has balanced
parentheses is a
A. Queue
B. Stack
C. Tree
D. List
2020 By Eng. Joud Khattab
Question 26
■ The best data structure to check whether an arithmetic expression has balanced
parentheses is a
A. Queue
B. Stack
C. Tree
D. List
2020 By Eng. Joud Khattab
Question 27
■ The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order
into a Max Heap. The resultant Max Heap is.
A. A
B. B
C. C
D. D
2020 By Eng. Joud Khattab
Question 27
■ The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order
into a Max Heap. The resultant Max Heap is.
A. A
B. B
C. C
D. D
2020 By Eng. Joud Khattab
Algorithms and Data Structure 2020
Algorithms and Data Structure 2020
Algorithms and Data Structure 2020
Algorithms and Data Structure 2020
Algorithms and Data Structure 2020

Contenu connexe

Tendances

مقدمة في قواعد البيانات
مقدمة في قواعد البياناتمقدمة في قواعد البيانات
مقدمة في قواعد البياناتDrMohammed Qassim
 
قواعد البيانات
قواعد البياناتقواعد البيانات
قواعد البياناتImpossible Love
 
Databases قواعد البيانات
Databases قواعد البيانات  Databases قواعد البيانات
Databases قواعد البيانات Mohamed Reda
 
استخدام برنامج SPSS
استخدام برنامج SPSSاستخدام برنامج SPSS
استخدام برنامج SPSSalqadi2002
 
مقدمة عن بايثون / جانقو
مقدمة عن بايثون / جانقومقدمة عن بايثون / جانقو
مقدمة عن بايثون / جانقوlunarhalo
 
تصميم المواقع الالكترونية عرض
تصميم المواقع الالكترونية عرضتصميم المواقع الالكترونية عرض
تصميم المواقع الالكترونية عرضAlnoor26
 
تصميم المقررات الالكترونية
تصميم المقررات الالكترونيةتصميم المقررات الالكترونية
تصميم المقررات الالكترونيةmalhelo
 
أنواع التقويم التربوي
أنواع التقويم التربويأنواع التقويم التربوي
أنواع التقويم التربويsaraalsulaiman
 
هندسة البرمجيات 1
هندسة البرمجيات 1هندسة البرمجيات 1
هندسة البرمجيات 1alaa_ward
 
نظرية الترميز الثنائي بحث
نظرية الترميز الثنائي بحثنظرية الترميز الثنائي بحث
نظرية الترميز الثنائي بحثJOHARAHALOTAIBI
 
أخلاقيات المهنة
أخلاقيات المهنةأخلاقيات المهنة
أخلاقيات المهنةguestbfd7302
 
تشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيتشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيمحمد الجمل
 
مراحل بناء قاعدة البيانات
مراحل بناء قاعدة البياناتمراحل بناء قاعدة البيانات
مراحل بناء قاعدة البياناتgueste5de3d
 
الدرس الثاني - الخوارزم
الدرس الثاني - الخوارزمالدرس الثاني - الخوارزم
الدرس الثاني - الخوارزمia7lam
 
software engineering هندسة البرمجيات
software engineering هندسة البرمجياتsoftware engineering هندسة البرمجيات
software engineering هندسة البرمجياتHacen Dadda
 
نظرية أوزبل (1)
نظرية أوزبل (1)نظرية أوزبل (1)
نظرية أوزبل (1)maromgd
 
عناصر او كائنات التعلم -ومعايير سكورم
عناصر او كائنات التعلم -ومعايير سكورمعناصر او كائنات التعلم -ومعايير سكورم
عناصر او كائنات التعلم -ومعايير سكورمnaglaa fares
 

Tendances (20)

مقدمة في قواعد البيانات
مقدمة في قواعد البياناتمقدمة في قواعد البيانات
مقدمة في قواعد البيانات
 
المحاضرة الثالثة لغات البرمجة
المحاضرة الثالثة  لغات البرمجةالمحاضرة الثالثة  لغات البرمجة
المحاضرة الثالثة لغات البرمجة
 
قواعد البيانات
قواعد البياناتقواعد البيانات
قواعد البيانات
 
Databases قواعد البيانات
Databases قواعد البيانات  Databases قواعد البيانات
Databases قواعد البيانات
 
استخدام برنامج SPSS
استخدام برنامج SPSSاستخدام برنامج SPSS
استخدام برنامج SPSS
 
مقدمة عن بايثون / جانقو
مقدمة عن بايثون / جانقومقدمة عن بايثون / جانقو
مقدمة عن بايثون / جانقو
 
تصميم المواقع الالكترونية عرض
تصميم المواقع الالكترونية عرضتصميم المواقع الالكترونية عرض
تصميم المواقع الالكترونية عرض
 
تصميم المقررات الالكترونية
تصميم المقررات الالكترونيةتصميم المقررات الالكترونية
تصميم المقررات الالكترونية
 
أنواع التقويم التربوي
أنواع التقويم التربويأنواع التقويم التربوي
أنواع التقويم التربوي
 
هندسة البرمجيات 1
هندسة البرمجيات 1هندسة البرمجيات 1
هندسة البرمجيات 1
 
نظرية الترميز الثنائي بحث
نظرية الترميز الثنائي بحثنظرية الترميز الثنائي بحث
نظرية الترميز الثنائي بحث
 
أخلاقيات المهنة
أخلاقيات المهنةأخلاقيات المهنة
أخلاقيات المهنة
 
تشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيتشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائي
 
المحاضرة الخامسةالبرمجيات التعليمية
المحاضرة الخامسةالبرمجيات التعليميةالمحاضرة الخامسةالبرمجيات التعليمية
المحاضرة الخامسةالبرمجيات التعليمية
 
مراحل بناء قاعدة البيانات
مراحل بناء قاعدة البياناتمراحل بناء قاعدة البيانات
مراحل بناء قاعدة البيانات
 
مبادئ نظم المعلومات
مبادئ نظم المعلوماتمبادئ نظم المعلومات
مبادئ نظم المعلومات
 
الدرس الثاني - الخوارزم
الدرس الثاني - الخوارزمالدرس الثاني - الخوارزم
الدرس الثاني - الخوارزم
 
software engineering هندسة البرمجيات
software engineering هندسة البرمجياتsoftware engineering هندسة البرمجيات
software engineering هندسة البرمجيات
 
نظرية أوزبل (1)
نظرية أوزبل (1)نظرية أوزبل (1)
نظرية أوزبل (1)
 
عناصر او كائنات التعلم -ومعايير سكورم
عناصر او كائنات التعلم -ومعايير سكورمعناصر او كائنات التعلم -ومعايير سكورم
عناصر او كائنات التعلم -ومعايير سكورم
 

Similaire à Algorithms and Data Structure 2020

Algorithms and Data Structure 2018
Algorithms and Data Structure 2018Algorithms and Data Structure 2018
Algorithms and Data Structure 2018Joud Khattab
 
Software Engineering 2020
Software Engineering 2020Software Engineering 2020
Software Engineering 2020Joud Khattab
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingOmar Albelbaisy
 
Enter to jess مدخل الى قواقع جيس
Enter to jess مدخل الى قواقع جيسEnter to jess مدخل الى قواقع جيس
Enter to jess مدخل الى قواقع جيسHasan Edrees
 
الاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسية
الاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسيةالاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسية
الاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسيةHemat Abo Hamer
 
8 memory managment & pointers
8 memory managment & pointers8 memory managment & pointers
8 memory managment & pointersMohammad Alyan
 
1 first lesson -assemblies
1  first lesson -assemblies1  first lesson -assemblies
1 first lesson -assembliesMohammad Alyan
 
الدرس الثاني في تقنيات وبرمجة الاجهزة الذكية
الدرس الثاني في تقنيات وبرمجة الاجهزة الذكيةالدرس الثاني في تقنيات وبرمجة الاجهزة الذكية
الدرس الثاني في تقنيات وبرمجة الاجهزة الذكيةMo7amm8d
 
1366136913.9485 نظم ادارة قواعد البيانات 2
1366136913.9485 نظم ادارة  قواعد البيانات 21366136913.9485 نظم ادارة  قواعد البيانات 2
1366136913.9485 نظم ادارة قواعد البيانات 2mh ED
 
اوراق العمل
اوراق العملاوراق العمل
اوراق العملmahaa6789
 
البرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptx
البرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptxالبرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptx
البرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptxSultanAlAnazi42
 
Software Engineering 2018
Software Engineering 2018Software Engineering 2018
Software Engineering 2018Joud Khattab
 

Similaire à Algorithms and Data Structure 2020 (20)

Algorithms and Data Structure 2018
Algorithms and Data Structure 2018Algorithms and Data Structure 2018
Algorithms and Data Structure 2018
 
Software Engineering 2020
Software Engineering 2020Software Engineering 2020
Software Engineering 2020
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
computer exam2
computer exam2computer exam2
computer exam2
 
الحل
الحلالحل
الحل
 
Enter to jess مدخل الى قواقع جيس
Enter to jess مدخل الى قواقع جيسEnter to jess مدخل الى قواقع جيس
Enter to jess مدخل الى قواقع جيس
 
1 prep
1 prep1 prep
1 prep
 
الاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسية
الاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسيةالاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسية
الاتصال بقواعد البيانات في الفيجوال بيسك دوت نت - مفاهيم أساسية
 
8 memory managment & pointers
8 memory managment & pointers8 memory managment & pointers
8 memory managment & pointers
 
Attach1 sec
Attach1 secAttach1 sec
Attach1 sec
 
1 first lesson -assemblies
1  first lesson -assemblies1  first lesson -assemblies
1 first lesson -assemblies
 
الدرس الثاني في تقنيات وبرمجة الاجهزة الذكية
الدرس الثاني في تقنيات وبرمجة الاجهزة الذكيةالدرس الثاني في تقنيات وبرمجة الاجهزة الذكية
الدرس الثاني في تقنيات وبرمجة الاجهزة الذكية
 
1366136913.9485 نظم ادارة قواعد البيانات 2
1366136913.9485 نظم ادارة  قواعد البيانات 21366136913.9485 نظم ادارة  قواعد البيانات 2
1366136913.9485 نظم ادارة قواعد البيانات 2
 
1prep win8.1
1prep win8.11prep win8.1
1prep win8.1
 
Sd2 areej
Sd2 areejSd2 areej
Sd2 areej
 
اوراق العمل
اوراق العملاوراق العمل
اوراق العمل
 
البرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptx
البرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptxالبرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptx
البرمجة بلغة سي ++ المحاضرة الأولى (2) copy.pptx
 
9 networking
9 networking9 networking
9 networking
 
Software Engineering 2018
Software Engineering 2018Software Engineering 2018
Software Engineering 2018
 
البرمجة
البرمجةالبرمجة
البرمجة
 

Plus de Joud Khattab

Customer Engagement Management
Customer Engagement ManagementCustomer Engagement Management
Customer Engagement ManagementJoud Khattab
 
Design thinking and Role Playing
Design thinking and Role PlayingDesign thinking and Role Playing
Design thinking and Role PlayingJoud Khattab
 
Artificial Intelligence 2020
Artificial Intelligence 2020Artificial Intelligence 2020
Artificial Intelligence 2020Joud Khattab
 
Automata and Compiler 2020
Automata and Compiler 2020Automata and Compiler 2020
Automata and Compiler 2020Joud Khattab
 
Automate and Compiler 2018
Automate and Compiler 2018Automate and Compiler 2018
Automate and Compiler 2018Joud Khattab
 
Artificial Intelligence 2018
Artificial Intelligence 2018Artificial Intelligence 2018
Artificial Intelligence 2018Joud Khattab
 
Geospatial Information Management
Geospatial Information ManagementGeospatial Information Management
Geospatial Information ManagementJoud Khattab
 
Big Data for Development
Big Data for DevelopmentBig Data for Development
Big Data for DevelopmentJoud Khattab
 
Personality Detection via MBTI Test
Personality Detection via MBTI TestPersonality Detection via MBTI Test
Personality Detection via MBTI TestJoud Khattab
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization TechniquesJoud Khattab
 
Network Address Translation (NAT)
Network Address Translation (NAT)Network Address Translation (NAT)
Network Address Translation (NAT)Joud Khattab
 
From Image Processing To Computer Vision
From Image Processing To Computer VisionFrom Image Processing To Computer Vision
From Image Processing To Computer VisionJoud Khattab
 
Social Networks Analysis
Social Networks AnalysisSocial Networks Analysis
Social Networks AnalysisJoud Khattab
 

Plus de Joud Khattab (20)

Customer Engagement Management
Customer Engagement ManagementCustomer Engagement Management
Customer Engagement Management
 
Design thinking and Role Playing
Design thinking and Role PlayingDesign thinking and Role Playing
Design thinking and Role Playing
 
Artificial Intelligence 2020
Artificial Intelligence 2020Artificial Intelligence 2020
Artificial Intelligence 2020
 
Automata and Compiler 2020
Automata and Compiler 2020Automata and Compiler 2020
Automata and Compiler 2020
 
Database 2020
Database 2020Database 2020
Database 2020
 
Database 2018
Database 2018Database 2018
Database 2018
 
Automate and Compiler 2018
Automate and Compiler 2018Automate and Compiler 2018
Automate and Compiler 2018
 
Artificial Intelligence 2018
Artificial Intelligence 2018Artificial Intelligence 2018
Artificial Intelligence 2018
 
Data Storytelling
Data StorytellingData Storytelling
Data Storytelling
 
Geospatial Information Management
Geospatial Information ManagementGeospatial Information Management
Geospatial Information Management
 
Big Data for Development
Big Data for DevelopmentBig Data for Development
Big Data for Development
 
Personality Detection via MBTI Test
Personality Detection via MBTI TestPersonality Detection via MBTI Test
Personality Detection via MBTI Test
 
Fog Computing
Fog ComputingFog Computing
Fog Computing
 
Seasonal ARIMA
Seasonal ARIMASeasonal ARIMA
Seasonal ARIMA
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
 
Network Address Translation (NAT)
Network Address Translation (NAT)Network Address Translation (NAT)
Network Address Translation (NAT)
 
From Image Processing To Computer Vision
From Image Processing To Computer VisionFrom Image Processing To Computer Vision
From Image Processing To Computer Vision
 
Spark SQL
Spark SQLSpark SQL
Spark SQL
 
Social Networks Analysis
Social Networks AnalysisSocial Networks Analysis
Social Networks Analysis
 
Smart City Era
Smart City EraSmart City Era
Smart City Era
 

Algorithms and Data Structure 2020

  • 1. ALGORITHMS AND DATA STRUCTURE ‫المعطيات‬ ‫وبنى‬ ‫الخوارزميات‬ ‫محور‬ By Eng. Joud Khattab2020
  • 2. Content ■ OOP. (‫التوجه‬ ‫غرضية‬ ‫)البرمجة‬ ■ Complexity. (‫)التعقيد‬ ■ Recursive Functions. ( ‫التوابع‬‫العودية‬ ) ■ Data Structure: (‫المعطيات‬ ‫)بنى‬ – Sequential: Linked List, Stacks, Queue. – Non Sequential: Tree, Graph. ■ Sort & Search Algorithms. (‫والترتيب‬ ‫البحث‬ ‫)خوارزميات‬ ■ Advance Algorithms Methods (‫متقدمة‬ ‫)خوارزميات‬ – Greedy, Backtracking, Dynamic, Divide & Conquer. ■ Hashing Function. (‫التقطيع‬ ‫)توابع‬ ■ MCQ. (‫)اختبارات‬ 2020 By Eng. Joud Khattab
  • 3. Definitions (‫)تعاريف‬ ■‫مسألة‬ ‫حل‬ ‫خوارزمية‬ –‫البسي‬ ‫العمليات‬ ‫من‬ ‫منتهية‬ ‫متتالية‬ ‫شكل‬ ‫على‬ ‫الحل‬ ‫لطريقة‬ ‫صوري‬ ‫توصيف‬ ‫هي‬‫تنفذ‬ ،‫طة‬ ‫محدد‬ ‫تسلسل‬ ‫حسب‬. ■‫البرنامج‬ ‫الحاسوب‬ ‫يقبلها‬ ‫التي‬ ‫البرمجة‬ ‫لغات‬ ‫بإحدى‬ ‫معينة‬ ‫مسألة‬ ‫حل‬ ‫لخوارزمية‬ ‫توصيف‬ ‫هو‬. ■‫البرمجة‬ ‫لغة‬ –‫يمك‬ ‫برنامج‬ ‫بكتابة‬ ‫تسمح‬ ‫التي‬ ‫المعرفة‬ ‫والدالالت‬ ‫والقواعد‬ ‫المفردات‬ ‫من‬ ‫مجموعة‬ ‫هي‬‫ن‬ ‫الحاسوب‬ ‫على‬ ‫تنفيذه‬. ■‫المترجم‬ –‫م‬ ‫مكافئ‬ ‫برنامج‬ ‫إلى‬ ‫ويحوله‬ ،‫معينة‬ ‫برمجة‬ ‫بلغة‬ ‫المكتوب‬ ‫البرنامج‬ ‫يفهم‬ ‫برنامج‬ ‫هو‬‫كتوب‬ ‫بالمعالج‬ ‫الخاصة‬ ‫المجمع‬ ‫بلغة‬‫الصغري‬‫للحاسوب‬. 2020 By Eng. Joud Khattab
  • 4. OBJECT ORIENTED PROGRAMMING (OOP) ‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ 2020 By Eng. Joud Khattab
  • 5. Definitions (‫)تعاريف‬ ■‫الفئة‬ ‫أو‬ ‫الصف‬(class) –‫ودوال‬ ‫متغيرات‬ ‫من‬ ‫الكود‬ ‫كل‬ ‫تحتوي‬ ‫أن‬ ‫تستطيع‬ ‫كبيرة‬ ‫حاوية‬ ‫عن‬ ‫عبارة‬ ‫الصف‬ ‫إلخ‬ ‫وكائنات‬... ■‫الغرض‬ ‫أو‬ ‫الكائن‬(object) –‫معين‬ ‫لصف‬ ‫مطابقة‬ ‫نسخة‬ ‫عن‬ ‫عبارة‬ ‫الكائن‬. –‫صف‬ ‫هناك‬ ‫يكن‬ ‫لم‬ ‫إذا‬ ‫كائن‬ ‫إنشاء‬ ‫يمكن‬ ‫ال‬ ‫إنه‬ ‫القول‬ ‫يمكننا‬. –‫يسمونه‬ ‫معين‬ ‫صف‬ ‫بإنشاء‬ ‫نقوم‬ ‫الكائنات‬ ‫برمجة‬ ‫مفهوم‬ ‫في‬(blue print)‫أي‬ (‫األصلية‬ ‫النسخة‬ ‫أو‬ ‫الخام‬ ‫النسخة‬)‫الصف‬ ‫هذا‬ ‫من‬ ‫أكثر‬ ‫أو‬ ‫نسخة‬ ‫ننشئ‬ ‫وبعدها‬ ،. 2020 By Eng. Joud Khattab
  • 7. Definitions (‫)تعاريف‬ ■‫الخصائص‬(instance variables) –‫ه‬ ‫في‬ ‫الموجودة‬ ‫المتغيرات‬ ‫من‬ ‫به‬ ‫خاصة‬ ‫نسخة‬ ‫يملك‬ ‫معين‬ ‫صف‬ ‫من‬ ‫ننشئه‬ ‫كائن‬ ‫كل‬‫ذا‬ ‫الصف‬. –‫بالخصائ‬ ‫تسمى‬ ‫ما‬ ‫هي‬ ‫الصف‬ ‫من‬ ‫كائن‬ ‫لكل‬ ‫منها‬ ‫نسخة‬ ‫إعطاء‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬‫ص‬. ■‫الدوال‬(methods) –‫باستدعائه‬ ‫تقوم‬ ‫عندما‬ ‫فقط‬ ‫يتنفذ‬ ‫جاهز‬ ‫كود‬ ‫عن‬ ‫عبارة‬ ‫الدالة‬. ■‫نوعين‬ ‫البيانات‬: –‫البدائية‬ ‫البيانات‬(primitive data types:)‫كال‬byte – short – int – long – float – bool –‫المرجعية‬ ‫البيانات‬(reference/object data types:)‫الكلمة‬ ‫له‬ ‫نضع‬ ‫نوع‬ ‫وأي‬ ‫كالكائنات‬ new‫تعريفه‬ ‫عند‬. 2020 By Eng. Joud Khattab
  • 8. Definitions (‫)تعاريف‬ ■‫البناء‬ ‫أو‬ ‫المشيد‬ ‫التابع‬(constructor) –‫ا‬ ‫للخصائص‬ ‫أولية‬ ‫قيم‬ ‫لتوليد‬ ‫كائن‬ ‫إنشاء‬ ‫أثناء‬ ‫استدعائها‬ ‫يتم‬ ،‫خاص‬ ‫نوع‬ ‫لها‬ ‫دالة‬ ‫عن‬ ‫عبارة‬‫لموجودة‬ ‫فيه‬. ■‫ال‬ ‫حول‬ ‫مهمة‬ ‫نقاط‬constructor –‫على‬ ‫يحتوي‬ ،‫إنشاءه‬ ‫يتم‬ ‫صف‬ ‫كل‬constructor‫األقل‬ ‫على‬ ‫واحد‬.‫أي‬ ‫بتعريف‬ ‫تقم‬ ‫لم‬ ‫إن‬ ‫وحتى‬ constructor‫عنك‬ ‫افتراضي‬ ‫واحد‬ ‫بإنشاء‬ ‫المترجم‬ ‫سيقوم‬. –‫استدعاء‬ ‫يجب‬ ،‫جديد‬ ‫كائن‬ ‫إنشاء‬ ‫يتم‬ ‫مرة‬ ‫كل‬ ‫في‬constructor‫الكائن‬ ‫هذا‬ ‫إنشاء‬ ‫يتم‬ ‫حتى‬. –‫تعريف‬ ‫عند‬ ‫األساسية‬ ‫القاعدة‬constructor‫نوعه‬ ‫ويكون‬ ‫الصف‬ ‫اسم‬ ‫نفس‬ ‫يحمل‬ ‫أن‬ ‫يجب‬ ‫أنه‬ ‫هي‬ public –‫بتعريف‬ ‫قمت‬ ‫حال‬ ‫في‬constructor‫هناك‬ ‫يعود‬ ‫لن‬ ‫أي‬ ،‫افتراضي‬ ‫واحد‬ ‫بإنشاء‬ ‫المترجم‬ ‫يقوم‬ ‫لن‬ default constructor –‫من‬ ‫أكثر‬ ‫تعريف‬ ‫يمكنك‬constructor.‫إنشاء‬ ‫دائما‬ ‫ويمكنك‬constructor‫إن‬ ‫تستخدمه‬ ‫حتى‬ ،‫فارغ‬ ‫كائن‬ ‫إنشاء‬ ‫عند‬ ‫للخصائص‬ ‫محددة‬ ‫أولية‬ ‫قيم‬ ‫إعطاء‬ ‫تريد‬ ‫ال‬ ‫كنت‬. 2020 By Eng. Joud Khattab
  • 9. Definitions (‫)تعاريف‬ ■‫أساسية‬ ‫فئات‬ ‫ثالث‬ ‫إلى‬ ‫تقسم‬ ‫الصف‬ ‫في‬ ‫وضعها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬: –Local variables:‫دالة‬ ‫أي‬ ‫بداخل‬ ‫تعريفها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬ ‫هي‬. –Instance variables:‫حدود‬ ‫وخارج‬ ‫الكالس‬ ‫بداخل‬ ‫تعريفها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬ ‫هي‬ ‫دالة‬ ‫أي‬. –Class variables:‫ك‬ ‫تعريفها‬ ‫يتم‬ ‫التي‬ ‫المتغيرات‬ ‫هي‬static‫الكالس‬ ‫بداخل‬.‫وخارج‬ ‫دالة‬ ‫أي‬ ‫حدود‬. 2020 By Eng. Joud Khattab
  • 10. Definitions (‫)تعاريف‬ ■‫مفهوم‬superclass‫و‬subclass –‫يسمى‬ ‫أخر‬ ‫صف‬ ‫من‬ ‫يرث‬ ‫الذي‬ ‫الصف‬subclass‫أيضا‬ ‫ويسمى‬(derived class‫او‬ extended class‫او‬child class) –‫يسمى‬ ‫أخر‬ ‫لصف‬ ‫محتوياته‬ ‫يورث‬ ‫الذي‬ ‫الصف‬superclass‫أيضا‬ ‫ويسمى‬(base class ‫او‬parent class) ■‫مفهوم‬super –‫ال‬ ‫في‬ ‫الموجودة‬ ‫والدوال‬ ‫المتغيرات‬ ‫بين‬ ‫للتمييز‬ ‫تستخدم‬superclass‫و‬subclass ‫الصفين‬ ‫كال‬ ‫في‬ ‫مستخدمة‬ ‫األسماء‬ ‫كانت‬ ‫حال‬ ‫في‬. –‫ال‬ ‫في‬ ‫الموجود‬ ‫المشيد‬ ‫الستدعاء‬ ‫تستخدم‬superclass 2020 By Eng. Joud Khattab
  • 11. Question 1 ■‫الصفوف‬ ‫استخدام‬ ‫بدون‬ ‫البرامج‬ ‫في‬ ‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫مفهوم‬ ‫تطبيق‬ ‫يمكن‬ .A‫صح‬ .B‫خطأ‬ 2020 By Eng. Joud Khattab
  • 12. Question 1 ■‫الصفوف‬ ‫استخدام‬ ‫بدون‬ ‫البرامج‬ ‫في‬ ‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫مفهوم‬ ‫تطبيق‬ ‫يمكن‬ .A‫صح‬ .B‫خطأ‬ 2020 By Eng. Joud Khattab
  • 13. Question 2 ■‫الصفوف‬ ‫في‬ ‫الموجودة‬ ‫اإلضافية‬ ‫الخاصية‬ ‫هي‬ ‫ما‬(classes)‫البنية‬ ‫في‬ ‫موجودة‬ ‫وليست‬ (struct) A. Data members B. Member functions C. Static data allowed D. Public access specifier 2020 By Eng. Joud Khattab
  • 14. Question 2 ■‫الصفوف‬ ‫في‬ ‫الموجودة‬ ‫اإلضافية‬ ‫الخاصية‬ ‫هي‬ ‫ما‬(classes)‫البنية‬ ‫في‬ ‫موجودة‬ ‫وليست‬ (struct) A. Data members B. Member functions C. Static data allowed D. Public access specifier 2020 By Eng. Joud Khattab
  • 15. Question 3 ■‫للصفوف‬ ‫األفضل‬ ‫التعريف‬ ‫هو‬ ‫ما‬(class) A. Parent of an object B. Instance of an object C. Blueprint of an object D. Scope of an object 2020 By Eng. Joud Khattab
  • 16. Question 3 ■‫للصفوف‬ ‫األفضل‬ ‫التعريف‬ ‫هو‬ ‫ما‬(class) A. Parent of an object B. Instance of an object C. Blueprint of an object D. Scope of an object 2020 By Eng. Joud Khattab
  • 17. Note What Is a Class? (‫الصف‬ ‫هو‬ ‫)ما‬ ■ In the real world, you'll often find many individual objects all of the same kind. ■ There may be thousands of other bicycles in existence, all of the same make and model. ■ Each bicycle was built from the same set of blueprints and therefore contains the same components. ■ In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. ■ A class is the blueprint from which individual objects are created. 2020 By Eng. Joud Khattab
  • 18. Question 4 ■‫مفهوم‬ ‫على‬ ‫وتركز‬ ‫توضح‬ ‫التي‬ ‫التوجه‬ ‫غرضيه‬ ‫البرمجة‬ ‫في‬ ‫الموجودة‬ ‫الخاصية‬ ‫هي‬ ‫ما‬ ‫البرمجة‬ ‫في‬ ‫االستخدام‬ ‫إعادة‬(reusability) A. Polymorphism B. Abstraction C. Encapsulation D. Inheritance 2020 By Eng. Joud Khattab
  • 19. Question 4 ■‫مفهوم‬ ‫على‬ ‫وتركز‬ ‫توضح‬ ‫التي‬ ‫التوجه‬ ‫غرضيه‬ ‫البرمجة‬ ‫في‬ ‫الموجودة‬ ‫الخاصية‬ ‫هي‬ ‫ما‬ ‫البرمجة‬ ‫في‬ ‫االستخدام‬ ‫إعادة‬(reusability) A. Polymorphism B. Abstraction C. Encapsulation D. Inheritance 2020 By Eng. Joud Khattab
  • 20. Question 6 ■‫التغليف‬ ‫مفهوم‬ ‫لشرح‬ ‫المناسب‬ ‫التعريف‬ ‫هو‬ ‫ما‬(Encapsulation) A. It is a way of combining various data members into a single unit B. It is a way of combining various member functions into a single unit C. It is a way of combining various data members and member functions into a single unit which can operate on any data D. It is a way of combining various data members and member functions that operate on those data members into a single unit 2020 By Eng. Joud Khattab
  • 21. Question 6 ■‫التغليف‬ ‫مفهوم‬ ‫لشرح‬ ‫المناسب‬ ‫التعريف‬ ‫هو‬ ‫ما‬(Encapsulation) A. It is a way of combining various data members into a single unit B. It is a way of combining various member functions into a single unit C. It is a way of combining various data members and member functions into a single unit which can operate on any data D. It is a way of combining various data members and member functions that operate on those data members into a single unit 2020 By Eng. Joud Khattab
  • 22. Question 7 ■‫البعض؟‬ ‫بعضها‬ ‫مع‬ ‫تتناسب‬ ‫التالية‬ ‫الميزات‬ ‫من‬ ‫أي‬ A. Inheritance and Encapsulation B. Encapsulation and Polymorphism C. Encapsulation and Abstraction D. Abstraction and Polymorphism 2020 By Eng. Joud Khattab
  • 23. Question 7 ■‫البعض؟‬ ‫بعضها‬ ‫مع‬ ‫تتناسب‬ ‫التالية‬ ‫الميزات‬ ‫من‬ ‫أي‬ A. Inheritance and Encapsulation B. Encapsulation and Polymorphism C. Encapsulation and Abstraction D. Abstraction and Polymorphism 2020 By Eng. Joud Khattab
  • 24. Note OOP Features (‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫)خصائص‬ ■ Abstraction (‫)التجريد‬ – Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. ■ Encapsulation (‫)التغليف‬ – Encapsulation is binding the data with the code that manipulates it. It keeps the data and the code safe from external interference. ■ Inheritance (‫)الوراثة‬ – Inheritance is the mechanism by which an object acquires the some/all properties of another object. It supports the concept of hierarchical classification. ■ Polymorphism ( ‫تعدد‬‫األوجه‬ ) – Polymorphism means to process objects differently based on their data type. 2020 By Eng. Joud Khattab
  • 25. Note OOP Features (‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫)خصائص‬ ■‫التجريد‬ ‫مفهوم‬(abstraction) –‫ت‬ ‫على‬ ‫قادرا‬ ‫يجعلك‬ ‫فهو‬ ،‫المبرمجين‬ ‫على‬ ‫األوامر‬ ‫كتابة‬ ‫لتسهيل‬ ‫يستخدم‬ ‫أسلوب‬ ‫هو‬‫نفيذ‬ ‫ذلك‬ ‫تنفيذ‬ ‫فيها‬ ‫تم‬ ‫التي‬ ‫التفاصيل‬ ‫كافة‬ ‫معرفة‬ ‫إلى‬ ‫الحاجة‬ ‫دون‬ ‫تريد‬ ‫ما‬. –‫ال‬ ‫اذا‬abstraction‫تفاص‬ ‫معرفة‬ ‫في‬ ‫تغوص‬ ‫أن‬ ‫بدل‬ ‫بسطحية‬ ‫األشياء‬ ‫مع‬ ‫تتعامل‬ ‫يجعلك‬‫يل‬ ‫المعقدة‬ ‫الكودات‬. ■‫التغليف‬ ‫مفهوم‬(encapsulation) –‫الخصائص‬ ‫إلخفاء‬ ‫أي‬ ،‫الصف‬ ‫في‬ ‫األساسية‬ ‫البيانات‬ ‫إلخفاء‬ ‫اتباعه‬ ‫يمكن‬ ‫أسلوب‬ ‫هو‬ ‫فيه‬ ‫الموجودة‬(global variables)‫هذه‬ ‫مع‬ ‫التعامل‬ ‫على‬ ‫قادرة‬ ‫األخرى‬ ‫الصفوف‬ ‫وجعل‬ ، ‫للصف‬ ‫األساسي‬ ‫المبرمج‬ ‫بإنشائها‬ ‫يقوم‬ ‫دوال‬ ‫خالل‬ ‫من‬ ‫فقط‬ ‫الخصائص‬. –‫ك‬ ‫الخصائص‬ ‫تعريف‬ ‫عليك‬ ،‫التغليف‬ ‫مبدأ‬ ‫لتحقيق‬private‫تستخدم‬ ‫التي‬ ‫الدوال‬ ‫وتعريف‬ ‫ك‬ ‫اليهم‬ ‫للوصول‬public –‫التغليف‬ ‫على‬ ‫مثال‬:setter and getter 2020 By Eng. Joud Khattab
  • 26. Note OOP Features (‫التوجه‬ ‫غرضية‬ ‫البرمجة‬ ‫)خصائص‬ ■‫ال‬ ‫مفهوم‬polymorphism –‫ك‬ ‫لها‬ ‫يمرر‬ ‫الذي‬ ‫الكائن‬ ‫حسب‬ ‫على‬ ‫مختلفة‬ ‫أوامر‬ ‫تنفذ‬ ‫دالة‬ ‫بناء‬ ‫منه‬ ‫المقصود‬ argument –‫نو‬ ‫إلى‬ ‫التحول‬ ‫على‬ ‫الكائن‬ ‫قدرة‬ ‫تحديدا‬ ،‫اشكال‬ ‫عدة‬ ‫أخذ‬ ‫على‬ ‫الكائن‬ ‫قدرة‬ ‫تعني‬‫ع‬ ‫منه‬ ‫مشتق‬. 2020 By Eng. Joud Khattab
  • 27. Note Polymorphism ■ Overloading (Static Polymorphism) – Overloading in simple words means more than one method having the same method name that behaves differently based on the arguments passed while calling the method. ■ Overriding (Dynamic Polymorphism) – Overriding means a derived class is implementing a method of its super class. The call to overridden method is resolved at runtime, thus called runtime polymorphism. 2020 By Eng. Joud Khattab
  • 28. Note Overriding ■ Overriding: –‫ال‬ ‫ورثها‬ ‫التي‬ ‫الدالة‬ ‫تعريف‬ ‫تعني‬subclass‫ال‬ ‫من‬superclass‫جديد‬ ‫من‬. –‫فقط‬ ‫الشكل‬ ‫حيث‬ ‫من‬ ‫الموروثة‬ ‫للدالة‬ ‫مشابهة‬ ‫تكون‬ ‫الجديدة‬ ‫الدالة‬ ‫هذه‬.‫لها‬ ‫أي‬ ‫وعدد‬ ‫والنوع‬ ‫االسم‬ ‫نفس‬‫الباراميترات‬‫مختلف‬ ‫محتواها‬ ‫لكن‬. –‫الفرصة‬ ‫اتاحة‬ ‫هو‬ ‫الهدف‬‫لل‬subclass‫حاجته‬ ‫حسب‬ ‫الدوال‬ ‫ليعرف‬ 2020 By Eng. Joud Khattab
  • 29. Note Overriding ■‫ال‬ ‫شروط‬overriding: –‫ال‬ ‫يكون‬ ‫أن‬ ‫يجب‬modifier‫للدالة‬ ‫المستخدم‬ ‫نفسه‬ ‫هو‬ ‫الجديدة‬ ‫للدالة‬ ‫المستخدم‬ ‫نوعه‬ ‫يكون‬ ‫أن‬ ‫ويجب‬ ،‫القديمة‬public‫او‬protected. –‫ك‬ ‫المعرفة‬ ‫الدالة‬final‫لها‬ ‫نفعل‬ ‫أن‬ ‫يمكن‬ ‫ال‬override‫كلمة‬ ‫ألن‬ ،final‫تغير‬ ‫تمنع‬ ‫تعريفها‬ ‫بعد‬ ‫الدالة‬ ‫محتوى‬. 2020 By Eng. Joud Khattab
  • 30. Question 8 ■‫الصفوف‬ ‫تدعم‬ ‫التي‬ ‫اللغة‬ ‫تسمي‬ ‫ماذا‬(classes)‫االشكال‬ ‫تعدد‬ ‫تدعم‬ ‫وال‬ (polymorphism)‫؟‬ A. Class based language B. Procedure oriented language C. Object based language D. If classes are supported, polymorphism will always be supported 2020 By Eng. Joud Khattab
  • 31. Question 8 ■‫الصفوف‬ ‫تدعم‬ ‫التي‬ ‫اللغة‬ ‫تسمي‬ ‫ماذا‬(classes)‫االشكال‬ ‫تعدد‬ ‫تدعم‬ ‫وال‬ (polymorphism)‫؟‬ A. Class based language B. Procedure oriented language C. Object based language D. If classes are supported, polymorphism will always be supported 2020 By Eng. Joud Khattab
  • 32. Note Programming Paradigm ■ The main programming paradigms: 1. Imperative ■ Cobol, Fortran, C, Ada, Perl 2. Object-oriented ■ Smalltalk, Java, C++, C#, Python 3. Functional ■ Lisp, Scheme, ML, Haskell 4. Logic ■ Prolog 5. Declarative ■ SQL, HTML 2020 By Eng. Joud Khattab
  • 33. Question 9 ■ If data members are private, what can we do to access them from the class object? A. Create public member functions to access those data members B. Create private member functions to access those data members C. Create protected member functions to access those data members D. Private data members can never be accessed from outside the class 2020 By Eng. Joud Khattab
  • 34. Question 9 ■ If data members are private, what can we do to access them from the class object? A. Create public member functions to access those data members B. Create private member functions to access those data members C. Create protected member functions to access those data members D. Private data members can never be accessed from outside the class 2020 By Eng. Joud Khattab
  • 35. Question 10 ■‫التغليف‬ ‫مفهوم‬ ‫ينتهك‬ ‫التالية‬ ‫الخيارات‬ ‫من‬ ‫أي‬(encapsulation)‫دائما؟‬ A. Local variables B. Global variables C. Public variables D. Array variables 2020 By Eng. Joud Khattab
  • 36. Question 10 ■‫التغليف‬ ‫مفهوم‬ ‫ينتهك‬ ‫التالية‬ ‫الخيارات‬ ‫من‬ ‫أي‬(encapsulation)‫دائما؟‬ A. Local variables B. Global variables C. Public variables D. Array variables 2020 By Eng. Joud Khattab
  • 37. Question 11 ■‫للبناة‬ ‫ضروريا‬ ‫شرطا‬ ‫ليس‬ ‫يلي‬ ‫مما‬ ‫أي‬(constructor)‫؟‬ A. Its name must be same as that of class B. It must not have any return type C. It must contain a definition body D. It can contains arguments 2020 By Eng. Joud Khattab
  • 38. Question 11 ■‫للبناة‬ ‫ضروريا‬ ‫شرطا‬ ‫ليس‬ ‫يلي‬ ‫مما‬ ‫أي‬(constructor)‫؟‬ A. Its name must be same as that of class B. It must not have any return type C. It must contain a definition body D. It can contains arguments 2020 By Eng. Joud Khattab
  • 39. Question 12 ■ How many types of constructors are available for use in general (with respect to parameters)? A. 2 B. 3 C. 4 D. 5 2020 By Eng. Joud Khattab
  • 40. Question 12 ■ How many types of constructors are available for use in general (with respect to parameters)? A. 2 B. 3 C. 4 D. 5 2020 By Eng. Joud Khattab
  • 41. Question 13 ■ Default constructor must be defined, if parameterized constructor is defined and the object is to be created without arguments. A. True B. False 2020 By Eng. Joud Khattab
  • 42. Question 13 ■ Default constructor must be defined, if parameterized constructor is defined and the object is to be created without arguments. A. True B. False 2020 By Eng. Joud Khattab
  • 43. Question 14 ■ If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called? A. Constructor of C then B, finally of A B. Constructor of A then C, finally of B C. Constructor of C then A, finally B D. Constructor of A then B, finally C 2020 By Eng. Joud Khattab
  • 44. Question 14 ■ If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called? A. Constructor of C then B, finally of A B. Constructor of A then C, finally of B C. Constructor of C then A, finally B D. Constructor of A then B, finally C 2020 By Eng. Joud Khattab
  • 46. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫اساسيين‬ ‫بعاملين‬ ‫يرتبط‬: –‫الذاكرة‬ ‫حجم‬: ■‫يعالجها‬ ‫التي‬ ‫والمعطيات‬ ‫البرنامج‬ ‫لتخزين‬ ‫الالزمة‬. –‫التنفيذ‬ ‫زمن‬: ■‫كافة‬ ‫تعليماتها‬ ‫إنجاز‬ ‫من‬ ‫الخوارزمية‬ ‫لتنتهي‬ ‫الالزم‬ ‫الزمن‬. ■‫تعليمة‬ ‫كل‬ ‫لتنفيذ‬ ‫الالزم‬ ‫والزمن‬ ‫التعليمات‬ ‫عدد‬ ‫بحساب‬ ‫التنفيذ‬ ‫زمن‬ ‫يقاس‬. 2020 By Eng. Joud Khattab
  • 47. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫منها‬ ‫عديدة‬ ‫عوامل‬ ‫على‬ ‫حاسب‬ ‫على‬ ‫البرنامج‬ ‫تنفيذ‬ ‫زمن‬ ‫يعتمد‬: –‫ما‬ ‫بتجربة‬ ‫الخاصة‬ ‫المسألة‬ ‫معطيات‬. –‫جودة‬‫الرماز‬‫التنفيذي‬ ‫الملف‬ ‫بناء‬ ‫أجل‬ ‫من‬ ‫المترجم‬ ‫يولده‬ ‫الذي‬. –‫الحاسوب‬ ‫في‬ ‫المتوفرة‬ ‫التعليمات‬ ‫وسرعة‬ ‫طبيعة‬(‫المعالج‬ ‫في‬‫الصغري‬.) –‫الخوارزمية‬ ‫فعالية‬.(‫المبرمج‬ ‫قدرة‬ ‫على‬ ‫تعتمد‬) 2020 By Eng. Joud Khattab
  • 48. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫بعد‬ ‫تحديد‬ ‫يجب‬ ‫خوارزمية‬ ‫تنفيذ‬ ‫زمن‬ ‫لحساب‬(‫حجم‬ ‫او‬ ‫طول‬ ‫او‬)‫درجة‬ ‫كتابة‬ ‫أجل‬ ‫من‬ ‫المسألة‬ ‫معطيات‬ ‫البعد‬ ‫هذا‬ ‫بداللة‬ ‫التعقيد‬. ■‫أمثلة‬: –‫الحدود‬ ‫كثيرات‬ ‫مسائل‬: ■‫يكون‬‫الحدود‬ ‫كثيرات‬ ‫درجة‬ ‫هو‬ ‫البعد‬. –‫المصفوفات‬ ‫مسائل‬: ■‫يكون‬‫المصفوفة‬ ‫أبعاد‬ ‫بداللة‬ ‫البعد‬. –‫البيانات‬ ‫مسائل‬: ■‫يكون‬‫األسهم‬ ‫أو‬ ‫العقد‬ ‫عدد‬ ‫بداللة‬ ‫البعد‬‫مجموعها‬ ‫أو‬. –‫الفرز‬ ‫مسائل‬: ■‫يكون‬‫ترتيبها‬ ‫نريد‬ ‫التي‬ ‫العناصر‬ ‫عدد‬ ‫بداللة‬ ‫البعد‬. –‫القواعدي‬ ‫التحليل‬ ‫مسائل‬: ■‫يكون‬‫الكلمة‬ ‫طول‬ ‫بداللة‬ ‫البعد‬. 2020 By Eng. Joud Khattab
  • 49. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫الرياضية‬ ‫القوانين‬ ‫ببعض‬ ‫تذكرة‬: 2020 By Eng. Joud Khattab
  • 50. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫الرياضية‬ ‫القوانين‬ ‫ببعض‬ ‫تذكرة‬: 2020 By Eng. Joud Khattab
  • 52. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ T(n) n n n log n n2 n3 n4 n10 2n 10 .01s .03s .1s 1s 10s 10s 1s 20 .02s .09s .4s 8s 160s 2.84h 1ms 30 .03s .15s .9s s 810s 6.83d 1s 40 .04s .21s 1.6s s 2.56ms 121d 18m 50 .05s .28s s s 6.25ms 3.1y 13d 100 .1s .66s 10s 1ms 100ms 3171y 41013 y 103 1s 9.96s 1ms 1s 16.67m 3.171013 y 3210283 y 104 s 130s 100ms 16.67m 115.7d 3.171023 y 105 s 1.66ms 10s 11.57d 3171y 3.171033 y 106 ms 19.92ms 16.67m 31.71y 3.17107 y 3.171043 y 2020 By Eng. Joud Khattab
  • 53. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Exercise // a simple loop to calculate the sum of numbers in an array int i , sum; for (i = sum = 0; i<n ; i++) sum += a[i]; 2020 By Eng. Joud Khattab
  • 54. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Rule If a loop iterates for i = initial value to final value in step of 1 then: Number of iterations of the loop = final value – initial value + 1 2020 By Eng. Joud Khattab
  • 55. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Exercise int i = 0; int sum = 0; while (i < n) { sum = sum + a[i]; i = i + 1; } The body of this loop is executed for i = 0, 1, 2, … n-1. Hence, it is executed ((n-1) – 0) + 1 = n times Therefore, these 2 assignments are executed n times Answer: Number of Assignment Operations = 2 + n + n = 2n + 2 2 assignments 2020 By Eng. Joud Khattab
  • 56. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 1 ■‫السؤال‬:‫تصاعديا‬ ‫التالية‬ ‫التعقيدات‬ ‫رتب‬ –n –n*n –n*logn –logn ■‫اإلجابة‬: .1logn .2n .3n*logn .4n*n 2020 By Eng. Joud Khattab
  • 57. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 2 ■‫السؤال‬:‫لقوة‬ ‫الرفع‬ ‫لخوارزمية‬ ‫تعقيد‬ ‫أصغر‬ –n –n*n –n*logn –logn ■‫اإلجابة‬: –logn 2020 By Eng. Joud Khattab
  • 58. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 2 int power (int x, int y) { int p = 1; for (int i = 1; i<=y; i++) { p = p*x; } return p; } int power2 (int x, int y) { int res = 1; int factor = x; while (y>0) { if (y%2==1) res = res*factor; factor = factor*factor; y = y / 2; } return res; } 2020 By Eng. Joud Khattab
  • 59. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫التنفيذ‬ ‫زمن‬ ‫حسب‬ ‫المسائل‬ ‫تصنيف‬: –O(1):‫التقطيع‬ ‫جداول‬ ‫في‬ ‫البحث‬ ‫خوارزميات‬( .Hash Tables) –Log n:‫الثنائي‬ ‫البحث‬ ‫خوارزميات‬( .Binary Search) –n:‫التسلسلي‬ ‫البحث‬ ‫خوارزميات‬( .Search) –n * Log n:‫الجيدة‬ ‫الفرز‬ ‫خوارزميات‬( .Sort) –n*n:‫المصفوفات‬ ‫ضرب‬(‫الحجم‬ ‫متوسطة‬ ‫معطيات‬ ‫تعالج‬.) –2 𝑛:‫محدود‬ ‫حجم‬ ‫ذات‬ ‫معطيات‬ ‫حالة‬ ‫في‬ ‫إال‬ ‫تستخدم‬ ‫ال‬ ‫أسي‬. 2020 By Eng. Joud Khattab
  • 60. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ ■‫تنفيذ‬ ‫زمن‬ ‫يكون‬ ‫التي‬ ‫هي‬ ‫معينة‬ ‫مسألة‬ ‫لحل‬ ‫الجيدة‬ ‫الخوارزميات‬ ‫إن‬ ‫نقول‬ ‫ان‬ ‫يمكن‬‫ها‬: –‫المعطيات‬ ‫حجم‬ ‫كان‬ ‫مهما‬ ‫ثابتا‬:‫التقطيع‬ ‫جداول‬ ‫في‬ ‫البحث‬ ‫خوارزميات‬ ‫مثل‬. –‫لوغاريتميا‬:‫الثنائي‬ ‫البحث‬ ‫خوارزميات‬ ‫مثل‬. –‫خطيا‬:‫التسلسلي‬ ‫البحث‬ ‫خوارزمية‬ ‫مثل‬. –‫مرتبة‬ ‫من‬n*log(n):‫الجيدة‬ ‫الفرز‬ ‫خوارزميات‬ ‫مثل‬. 2020 By Eng. Joud Khattab
  • 61. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 3 void Main() { for (int i=1; i<=n; i++) { m=m+1; p=p*2; l=l+3; } } ■‫السؤال‬: –‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬ ‫التالية‬: ■‫اإلجابة‬: 2020 By Eng. Joud Khattab
  • 62. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 4 void Main() { for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++){ m=m+1; p=p*2; l=l+3; } } } ■‫السؤال‬: –‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬ ‫التالية‬: ■‫اإلجابة‬: 2020 By Eng. Joud Khattab
  • 63. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 5 void Main() { for (int i=1; i<=n; i++) { for (int j=1; j<=i; j++){ m=m+1; p=p*2; l=l+3; } } } ■‫السؤال‬: –‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬ ‫التالية‬: ■‫اإلجابة‬: 2020 By Eng. Joud Khattab
  • 64. Complexity (‫الخوارزميات‬ ‫)تعقيد‬ Question 6 void Main() { for (int cnt=5,i=1; i<=n; i++) for (int j=1; j<=n; j=j*2) cnt++; } ■‫السؤال‬: –‫الخوارزميات‬ ‫تعقيد‬ ‫احسب‬ ‫التالية‬: ■‫اإلجابة‬: –n * log n 2020 By Eng. Joud Khattab
  • 66. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) ■‫للتوقف‬ ‫شرط‬ ‫بتحقق‬ ‫االستدعاء‬ ‫وينتهي‬ ‫نفسها‬ ‫تستدعي‬ ‫خوارزمية‬ ‫هي‬. ■‫أمثلة‬: –‫فيبوناتشي‬ ‫اعداد‬ ‫حساب‬. –‫أكريمان‬ ‫سلسلة‬. –‫هانوي‬ ‫أبراج‬. –‫المنحنيات‬ ‫رسم‬. –‫الثمانية‬ ‫الوزراء‬ ‫مسألة‬. –‫هلبرت‬ ‫منحنيات‬. ■‫الخوارزمية‬ ‫تعقيد‬ ‫حساب‬ ‫يؤول‬‫العودية‬‫تراجعية‬ ‫معادلة‬ ‫حل‬ ‫إلى‬. 2020 By Eng. Joud Khattab
  • 67. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) ■‫اإلجرائيات‬ ‫من‬ ‫نوعين‬ ‫بين‬ ‫التمييز‬ ‫يمكن‬‫العودية‬: –‫ذات‬ ‫اإلجرائيات‬‫العودية‬‫المباشرة‬: ■‫إجرائية‬ ‫عن‬ ‫نقول‬P‫إنها‬‫عودية‬‫لنفسها‬ ‫صريح‬ ‫استدعاء‬ ‫تحوي‬ ‫كانت‬ ‫إذا‬ ‫مباشرة‬. –‫ذات‬ ‫اإلجرائيات‬‫العودية‬‫المباشرة‬ ‫غير‬: ■‫إجرائية‬ ‫عن‬ ‫نقول‬P‫إنها‬‫عودية‬‫أخرى‬ ‫إجرائية‬ ‫تستدعي‬ ‫كانت‬ ‫إذا‬ ‫مباشرة‬ ‫غير‬Q ‫تستدعي‬P. 2020 By Eng. Joud Khattab
  • 68. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) ■‫االستدعاء‬ ‫عملية‬‫العودي‬‫المطلوبة‬ ‫الذاكرة‬ ‫وحجم‬ ‫التنفيذ‬ ‫الزمن‬ ‫حيث‬ ‫من‬ ‫مكلفة‬. ■‫خوارزمية‬ ‫تحويل‬ ‫يمكن‬‫عودية‬‫مكدس‬ ‫باستخدام‬ ‫تكرارية‬ ‫إلى‬ –‫ث‬ ‫فيه‬ ‫عودي‬ ‫استدعاء‬ ‫لكل‬ ‫المحلية‬ ‫والمتحوالت‬ ‫الدخل‬ ‫معامالت‬ ‫تخزين‬ ‫يتم‬ ‫حيث‬‫م‬ ‫االستدعاء‬ ‫بعد‬ ‫التعليمات‬ ‫بقية‬ ‫لتنفيذ‬ ‫المكدس‬ ‫عناصر‬ ‫حذف‬ ‫يتم‬‫العودي‬‫عل‬‫هذه‬ ‫ى‬ ‫األول‬ ‫إلى‬ ‫األخير‬ ‫االستدعاء‬ ‫من‬ ‫التنفيذ‬ ‫يتم‬ ‫حيث‬ ‫العناصر‬. 2020 By Eng. Joud Khattab
  • 69. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 1 ■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(33,33) int f(int x, int y) { if (x==1) return y; else if (y==1) return x; else if (x%2==0) return y+f(x/2,y); else return x+f(x,y/2); } ■‫اإلجابة‬: 198 2020 By Eng. Joud Khattab
  • 70. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 1 ■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(22,22) int f(int x, int y) { if (x==1) return y; else if (y==1) return x; else if (x%2==0) return y+f(x/2,y); else return x+f(x,y/2); } ■‫اإلجابة‬: 77 2020 By Eng. Joud Khattab
  • 71. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 2 ■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(1024*1024) Public int f(int n) { int x=0; for (int i=2; i<=n ; i*=2) { x++; } return x; } ■‫اإلجابة‬: f(210*210)=20 2020 By Eng. Joud Khattab
  • 72. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 3 ■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(33) Int f(int n) { for (int i=1;i<=n;i++) { i=i+1; n=n-1; } return n; } ■‫اإلجابة‬: 22 2020 By Eng. Joud Khattab
  • 73. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 3 ■‫السؤال‬:‫االستدعاء‬ ‫كان‬ ‫إذا‬ ‫النتيجة‬ ‫ما‬f(10) Int f(int n) { for (int i=1;i<=n;i++) { i=i+1; n=n-1; } return n; } ■‫اإلجابة‬: 6 2020 By Eng. Joud Khattab
  • 74. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 4 int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(2)); return 0; } 1. 4 2. 8 3. 16 4. Runtime error. 2020 By Eng. Joud Khattab
  • 75. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 4 int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(2)); return 0; } 1. 4 2. 8 3. 16 4. Runtime error. 2020 By Eng. Joud Khattab
  • 76. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 4 int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(6)); return 0; } 1. 4 2. 8 3. 16 4. Runtime error. 2020 By Eng. Joud Khattab
  • 77. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 4 int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(6)); return 0; } 1. 4 2. 8 3. 16 4. Runtime error. 2020 By Eng. Joud Khattab
  • 78. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 5 int fun(int x, int y) { if (x == 0) return y; return fun(x - 1, x + y); } int main() { printf("%d ", fun(4,3)); return 0; } 1. 13 2. 12 3. 9 4. 10 2020 By Eng. Joud Khattab
  • 79. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 5 int fun(int x, int y) { if (x == 0) return y; return fun(x - 1, x + y); } int main() { printf("%d ", fun(4,3)); return 0; } 1. 13 2. 12 3. 9 4. 10 The rule: x(x+1)/2 + y 2020 By Eng. Joud Khattab
  • 80. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 6 n = 25 void fun(int n) { if (n == 0) return; printf("%d", n%2); fun(n/2); } 1. 11001 2. 10011 3. 11111 4. 00000 2020 By Eng. Joud Khattab
  • 81. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 6 n = 25 void fun(int n) { if (n == 0) return; printf("%d", n%2); fun(n/2); } 1. 11001 2. 10011 3. 11111 4. 00000 2020 By Eng. Joud Khattab
  • 82. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 7 n = 25 void fun(int n) { if (n == 0) return; fun(n/2); printf("%d", n%2); } 1. 11001 2. 10011 3. 11111 4. 00000 2020 By Eng. Joud Khattab
  • 83. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 7 n = 25 void fun(int n) { if (n == 0) return; fun(n/2); printf("%d", n%2); } 1. 11001 2. 10011 3. 11111 4. 00000 2020 By Eng. Joud Khattab
  • 84. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 8 What does the following function do? int fun(int x, int y) { if (y == 0) return 0; return (x + fun(x, y-1)); } 1. x+y 2. x+x*y 3. x*y 4. x^y 2020 By Eng. Joud Khattab
  • 85. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 8 What does the following function do? int fun(int x, int y) { if (y == 0) return 0; return (x + fun(x, y-1)); } 1. x+y 2. x+x*y 3. x*y 4. x^y 2020 By Eng. Joud Khattab
  • 86. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 9 int f(int n) { if(n <= 1) return 1; if(n%2 == 0) return f(n/2); return f(n/2) + f(n/2+1); } int main() { printf("%d", f(11)); return 0; } 1. Stack overflow 2. 3 3. 4 4. 5 2020 By Eng. Joud Khattab
  • 87. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 9 int f(int n) { if(n <= 1) return 1; if(n%2 == 0) return f(n/2); return f(n/2) + f(n/2+1); } int main() { printf("%d", f(11)); return 0; } 1. Stack overflow 2. 3 3. 4 4. 5 2020 By Eng. Joud Khattab
  • 88. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 10 Consider the following: f(5) int fun (int n) { int x=1, k; if (n==1) return x; for (k=1; k<n; ++k) x = x + fun(k) * fun(n – k); return x; } 1. 0 2. 26 3. 51 4. 71 2020 By Eng. Joud Khattab
  • 89. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 10 Consider the following: f(5) int fun (int n) { int x=1, k; if (n==1) return x; for (k=1; k<n; ++k) x = x + fun(k) * fun(n – k); return x; } 1. 0 2. 26 3. 51 4. 71 2020 By Eng. Joud Khattab
  • 90. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 11 If get(6) function is being called. how many times will the get() function be invoked? void get (int n) { if (n < 1) return; get(n-1); get(n-3); printf("%d", n); } 1. 15 2. 25 3. 35 4. 45 2020 By Eng. Joud Khattab
  • 91. Recursive Functions ( ‫الخوارزميات‬‫العودية‬ ) Question 11 If get(6) function is being called. how many times will the get() function be invoked? void get (int n) { if (n < 1) return; get(n-1); get(n-3); printf("%d", n); } 1. 15 2. 25 3. 35 4. 45 get(6) [25 Calls] / [17 Calls] get(5) get(3) [7 Calls] / get(4) get(2) [5 Calls] / [7 Calls] get(3) get(1) [3 Calls] / get(2) get(0) / [3 Calls] get(1) get(-1) / get(0) get(-2) 2020 By Eng. Joud Khattab
  • 93. Linked List (‫الخطية‬ ‫)السالسل‬ ■‫النمط‬ ‫نفس‬ ‫من‬ ‫عناصر‬ ‫تخزين‬ ‫من‬ ‫تمكن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬. ■‫السالسل‬ ‫ميزات‬: –‫مسبقا‬ ‫طولها‬ ‫لتحديد‬ ‫ضرورة‬ ‫ال‬. –‫واالضافة‬ ‫الحذف‬ ‫عند‬ ‫السلسلة‬ ‫عناصر‬ ‫ازاحة‬ ‫إلى‬ ‫نحتاج‬ ‫ال‬. ■‫سيئاتها‬: –‫عنصر‬ ‫إلى‬ ‫المباشر‬ ‫النفاذ‬ ‫يمكن‬ ‫ال‬,‫إلى‬ ‫تحتاج‬ ‫وبالتالي‬n‫االحوال‬ ‫أسوأ‬ ‫في‬ ‫مقارنة‬ ‫عملية‬ ‫العنصر‬ ‫إلى‬ ‫للوصول‬. –‫المؤشرات‬ ‫لتخزين‬ ‫إضافي‬ ‫تخزين‬ ‫حجم‬ ‫إلى‬ ‫نحتاج‬. ■‫مثل‬ ‫للسالسل‬ ‫أخرى‬ ‫أنواع‬ ‫يوجد‬: –‫الدائرية‬ ‫السالسل‬circular linked list. –‫االرتباط‬ ‫المضاعفة‬ ‫السالسل‬doubly linked list. 2020 By Eng. Joud Khattab
  • 94. Linked List (‫الخطية‬ ‫)السالسل‬ A B C Head A data pointer node 2020 By Eng. Joud Khattab
  • 95. Linked List (‫الخطية‬ ‫)السالسل‬ V.S. Ordinary and Dynamic Arrays Ordinary Arrays ■‫الميزات‬: –‫واستخدام‬ ‫إنشاء‬ ‫جدا‬ ‫السهل‬ ‫من‬. –‫عنصر‬ ‫أي‬ ‫إلى‬ ‫المباشر‬ ‫الوصول‬. ■‫السيئات‬: –‫في‬ ‫ا‬ً‫معروف‬ ‫حجمها‬ ‫يكون‬ ‫أن‬ ‫يجب‬ ‫يمكن‬ ‫وال‬ ،‫البرمجي‬ ‫التحويل‬ ‫وقت‬ ‫التشغيل‬ ‫وقت‬ ‫في‬ ‫تغييره‬. –‫نقل‬ ‫حذفه‬ ‫أو‬ ‫عنصر‬ ‫إدراج‬ ‫يتطلب‬ ‫األخرى‬ ‫العناصر‬ ‫كل‬. Dynamic Arrays ■‫الميزات‬: –‫إنشائها‬ ‫جدا‬ ‫السهل‬ ‫من‬. –‫عنصر‬ ‫أي‬ ‫إلى‬ ‫المباشر‬ ‫الوصول‬. –‫التشغيل‬ ‫وقت‬ ‫في‬ ‫الحجم‬ ‫تحديد‬ ‫يمكن‬. ■‫السيئات‬: –‫كل‬ ‫نقل‬ ‫حذفه‬ ‫أو‬ ‫عنصر‬ ‫إدراج‬ ‫يتطلب‬ ‫األخرى‬ ‫العناصر‬. –‫تتخطى‬ ‫أن‬ ‫المصفوفة‬ ‫على‬ ‫كان‬ ‫إذا‬ ‫تشكيل‬ ‫إعادة‬ ‫فيجب‬ ، ‫األولي‬ ‫الحجم‬ ‫جديد‬ ‫موقع‬ ‫إلى‬ ‫بأكملها‬ ‫المصفوفة‬. 2020 By Eng. Joud Khattab
  • 96. Stack (‫)المكدس‬ ■‫ندع‬ ‫واحدة‬ ‫جهة‬ ‫من‬ ‫تتم‬ ‫والحذف‬ ‫اإلضافة‬ ‫عمليات‬ ‫إن‬ ‫غير‬ ،‫السلسلة‬ ‫تشبه‬ ‫خطية‬ ‫بنية‬ ‫هي‬‫وها‬ ‫المكدس‬ ‫قمة‬. ■‫النمط‬ ‫نفس‬ ‫من‬ ‫عناصر‬ ‫تخزين‬ ‫من‬ ‫تمكن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬. ■‫مبدأ‬ ‫تتبع‬: –First In last Out (FILO) –Last In First Out (LIFO) ■‫عليه‬ ‫االساسية‬ ‫العمليات‬: –‫قمته‬ ‫خالل‬ ‫من‬ ‫العناصر‬ ‫إلى‬ ‫الوصول‬ ‫يمكن‬head)) –‫القمة‬ ‫إلى‬ ‫عنصر‬ ‫إضافة‬push)) –‫القمة‬ ‫من‬ ‫عنصر‬ ‫حذف‬pop)) ■‫الخطية‬ ‫السالسل‬ ‫أو‬ ‫المصفوفات‬ ‫باستخدام‬ ‫المكدس‬ ‫تمثيل‬ ‫يمكن‬. 2020 By Eng. Joud Khattab
  • 98. Stack (‫)المكدس‬ ■‫المكدسات‬ ‫تطبيقات‬: –‫الصفحات‬ ‫سجل‬‫المزارة‬‫االنترنت‬ ‫متصفح‬ ‫في‬. –‫النصوص‬ ‫محررات‬ ‫في‬ ‫التراجع‬ ‫عمليات‬. –‫الرياضية‬ ‫التعابير‬ ‫في‬ ‫األقواس‬ ‫أزواج‬ ‫ربط‬. –‫قيم‬ ‫وحساب‬ ‫الملحقة‬ ‫التعابير‬ ‫إلى‬ ‫النظامية‬ ‫الرياضية‬ ‫التعابير‬ ‫من‬ ‫التحويل‬‫هذه‬ ‫ة‬ ‫التعابير‬. –‫تابع‬ ‫جسم‬ ‫في‬ ‫تابع‬ ‫استدعاء‬. –‫أوال‬ ‫العمق‬ ‫بطريقة‬ ‫والبيانات‬ ‫األشجار‬ ‫في‬ ‫التجول‬. –‫المترجمات‬ ‫في‬ ‫األخطاء‬ ‫مكدس‬. 2020 By Eng. Joud Khattab
  • 99. Stack (‫)المكدس‬ Infix (‫)نظامي‬ Prefix (‫)مصدر‬ Postfix (‫)ملحق‬ A+B +AB AB+ A+B*C +A*BC ABC*+ A*(B+C) *A+BC ABC+* A*B+C +*ABC AB*C+ A+B*C+D-E*F -++A*BCD*EF ABC*+D+EF*- (A+B)*(C+D-E)*F **+AB-+CDEF AB+CD+E-*F* 2020 By Eng. Joud Khattab
  • 100. Stack (‫)المكدس‬ ■ Infix to Postfix: 1. Scan the infix expression from left to right. 2. If the scanned character is an operand, output it. 3. Else, 1. If the precedence of the scanned operator is greater or equal than the precedence of the operator in the stack (or the stack is empty), push it. 2. Else, pop the operator from the stack until the precedence of the scanned operator is less-equal to the precedence of the operator residing on the top of the stack. Then push the scanned operator to the stack. 4. If the scanned character is an ‘(‘, push it to the stack. 5. If the scanned character is an ‘)’, pop and output from the stack until an ‘(‘ is encountered. 6. Repeat steps 2 to 6 until infix expression is scanned. 7. Pop and output from the stack until it is not empty. 2020 By Eng. Joud Khattab
  • 101. Stack (‫)المكدس‬ ■ Infix to Prefix: 1. Reverse the infix expression i.e A+B*C will become C*B+A. ■ Note while reversing each ‘(‘ will become ‘)’ and each ‘)’ becomes ‘(‘. 2. Obtain the postfix expression of the modified expression i.e CB*A+. 3. Reverse the postfix expression. Hence in our example prefix is +A*BC. 2020 By Eng. Joud Khattab
  • 102. Stack (‫)المكدس‬ ■ Postfix Calculation: 1. Create a stack to store operands (values). 2. Scan the given expression and do following for every scanned element: 1. If the element is a number, push it into the stack. 2. If the element is a operator, pop operands for the operator from stack. Evaluate the operator and push the result back to the stack. 3. When the expression is ended, the number in the stack is the final answer. 2020 By Eng. Joud Khattab
  • 103. Stack (‫)المكدس‬ ■ Prefix Calculation: 1. Put a pointer P at the end of the end. 2. If character at P is a number push it to Stack. 3. If the character at P is an operator pop two elements from the Stack. Operate on these elements according to the operator, and push the result back to the Stack. 4. Decrement P by 1 and go to Step 2 as long as there are characters left to be scanned in the expression. 5. The Result is stored at the top of the Stack. 2020 By Eng. Joud Khattab
  • 104. Queue (‫)األرتال‬ ■‫الرت‬ ‫ذيل‬ ‫ندعوها‬ ‫جهة‬ ‫في‬ ‫تجري‬ ‫اإلضافة‬ ‫عمليات‬ ‫أن‬ ‫غير‬ ‫السلسلة‬ ‫تشبه‬ ‫خطية‬ ‫بنية‬ ‫هي‬‫ل‬. ‫الرتل‬ ‫بداية‬ ‫نسميها‬ ‫التي‬ ‫المعاكسة‬ ‫الجهة‬ ‫في‬ ‫الحذف‬ ‫ويجري‬. ■‫النمط‬ ‫نفس‬ ‫من‬ ‫عناصر‬ ‫تخزين‬ ‫من‬ ‫تمكن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬. ■‫مبدأ‬ ‫تتبع‬: –First In First Out (FIFO) –Last In Last Out (LILO) ■‫عليه‬ ‫االساسية‬ ‫العمليات‬: –‫بدايته‬ ‫خالل‬ ‫من‬ ‫العناصر‬ ‫إلى‬ ‫الوصول‬ ‫يمكن‬(head)‫نهايته‬ ‫أو‬(tail.) –‫النهاية‬ ‫إلى‬ ‫عنصر‬ ‫إضافة‬(enqueue.) –‫البداية‬ ‫من‬ ‫عنصر‬ ‫حذف‬(dequeue.) ■‫الخطية‬ ‫السالسل‬ ‫أو‬ ‫المصفوفات‬ ‫باستخدام‬ ‫االرتال‬ ‫تمثيل‬ ‫يمكن‬. 2020 By Eng. Joud Khattab
  • 106. Queue (‫)األرتال‬ ■‫األرتال‬ ‫تطبيقات‬: –‫الكمبيوتر‬ ‫في‬ ‫والمخرجات‬ ‫المدخالت‬ ‫مخازن‬(‫والطابعة‬ ‫المفاتيح‬ ‫لوحة‬.) –‫في‬ ‫أوال‬ ‫بالعرض‬ ‫التجول‬ ‫خوارزميات‬ ‫مثل‬ ‫الخوارزميات‬ ‫في‬ ‫مساعدة‬ ‫معطيات‬ ‫بنية‬ ‫والبيانات‬ ‫األشجار‬. –‫اليومية‬ ‫الحياة‬ ‫أرتال‬ ‫محاكاة‬. 2020 By Eng. Joud Khattab
  • 107. Queue (‫)األرتال‬ ■‫االولويات‬ ‫رتل‬: –‫الرتل‬ ‫إلى‬ ‫األولوية‬ ‫عامل‬ ‫يضاف‬. –‫اوال‬ ‫األعلى‬ ‫األولوية‬ ‫ذو‬ ‫العنصر‬ ‫تخديم‬ ‫يتم‬. –‫مثال‬: ■‫للحاالت‬ ‫األولوية‬ ‫تكون‬ ‫حيث‬ ‫الطبيب‬ ‫عيادة‬ ‫في‬ ‫االنتظار‬ ‫أرتال‬‫اإلسعافية‬. 2020 By Eng. Joud Khattab
  • 108. NON SEQUENTIAL DATA STRUCTURES ‫التسلسلية‬ ‫غير‬ ‫المعطيات‬ ‫بنى‬ 2020 By Eng. Joud Khattab
  • 109. Trees (‫)االشجار‬ ■‫الشجرة‬ ‫نعرف‬: –‫عقد‬ ‫نسميها‬ ‫العناصر‬ ‫من‬ ‫مجموعة‬ ‫بأنها‬nodes))، –‫بروابط‬ ‫بعضها‬ ‫بين‬ ‫مرتبطة‬(Links)، –‫هرميا‬ ‫تنظيما‬ ‫ومنظمة‬(Hierarchical)، –‫حلقات‬ ‫يحتوي‬ ‫ال‬(Cycles)،‫مغلقة‬ –‫جذر‬ ‫نسميها‬ ‫ووحيدة‬ ‫مميزة‬ ‫عقدة‬ ‫توجد‬ ‫إنه‬ ‫أي‬(Root.) ■‫أمثلة‬: –‫مجلدات‬ ‫في‬ ‫الملفات‬ ‫تنظيم‬. –‫حسابية‬ ‫عبارة‬ ‫تمثيل‬. 2020 By Eng. Joud Khattab
  • 110. Binary Trees (‫الثنائية‬ ‫)األشجار‬ ■‫األكثر‬ ‫علي‬ ‫ابنان‬ ‫عقدة‬ ‫لكل‬ ‫فيها‬ ‫يكون‬ ‫األشجار‬ ‫من‬ ‫خاصة‬ ‫حالة‬: –‫داخلية‬ ‫عقد‬ ‫األقل‬ ‫على‬ ‫ولد‬ ‫لها‬ ‫التي‬ ‫العقد‬ ‫نسمي‬. –‫أوراق‬ ‫أو‬ ‫خارجية‬ ‫عقد‬ ‫ولد‬ ‫أي‬ ‫لها‬ ‫ليس‬ ‫التي‬ ‫العقد‬ ‫نسمي‬(Leaf.) –‫طريقا‬ ‫نسمي‬(Path)‫العقد‬ ‫من‬ ‫متتالية‬ ‫كل‬. –‫األوراق‬ ‫وإحدى‬ ‫الجذر‬ ‫بين‬ ‫يصل‬ ‫طريق‬ ‫كل‬ ‫فرعا‬ ‫نسمي‬. 2020 By Eng. Joud Khattab
  • 111. Binary Trees (‫الثنائية‬ ‫)األشجار‬ ■‫مهمة‬ ‫تعاريف‬: –‫الشجرة‬ ‫درجة‬:‫عقدة‬ ‫ألوالد‬ ‫األعظمي‬ ‫العدد‬( .‫هي‬ ‫ثنائية‬ ‫شجرة‬ ‫درجة‬2) –‫الشجرة‬ ‫حجم‬:‫عقدها‬ ‫عدد‬. –‫عقدة‬ ‫ارتفاع‬:‫الجذر‬ ‫الى‬ ‫العقدة‬ ‫من‬ ‫الواصل‬ ‫الطريق‬ ‫في‬ ‫االتصاالت‬ ‫عدد‬. –‫الشجرة‬ ‫ارتفاع‬:‫فيها‬ ‫عقدة‬ ‫ارتفاع‬ ‫أطول‬. –‫الشجرة‬ ‫عرض‬:‫ما‬ ‫مستوى‬ ‫في‬ ‫للعقد‬ ‫األعظم‬ ‫العدد‬. –‫التجول‬ ‫مسافة‬:‫عقدها‬ ‫ارتفاعات‬ ‫مجموع‬. –‫الخارجي‬ ‫التجول‬ ‫مسافة‬:‫أوراقها‬ ‫ارتفاعات‬ ‫مجموع‬. –‫الداخلي‬ ‫التجول‬ ‫مسافة‬:‫الداخلية‬ ‫عقدها‬ ‫ارتفاعات‬ ‫مجموع‬. 2020 By Eng. Joud Khattab
  • 112. Binary Trees (‫الثنائية‬ ‫)األشجار‬ Exercise ■‫الشجرة‬ ‫جذر‬:n1 ■‫االيسر‬ ‫االبن‬:n2 ■‫األيمن‬ ‫االبن‬:n4 ■‫األوراق‬:n8 – n10 – n5 – n9 ■‫الداخلية‬ ‫العقد‬:n1 – n2 – n3 – n4 – n6 – n7 ■‫عقدة‬ ‫ارتفاع‬: n1=0 , n2=n4=1 , n3=n5=n7=2 ■‫الشجرة‬ ‫ارتفاع‬:4 ■‫التجول‬ ‫مسافة‬:22 ■‫الخارجي‬ ‫التجول‬ ‫مسافة‬:13 ■‫الداخلي‬ ‫التجول‬ ‫مسافة‬:9 2020 By Eng. Joud Khattab
  • 113. Binary Trees (‫الثنائية‬ ‫)األشجار‬ ■‫الخاصة‬ ‫الثنائية‬ ‫األشجار‬ ‫بعض‬: –‫الخطية‬ ‫الثنائية‬ ‫الشجرة‬:‫األ‬ ‫على‬ ‫واحد‬ ‫ولد‬ ‫منها‬ ‫عقدة‬ ‫لكل‬ ‫يكون‬ ‫ثنائية‬ ‫شجرة‬‫كثر‬. –‫التامة‬ ‫الثنائية‬ ‫الشجرة‬:‫المستوى‬ ‫في‬ ‫واحدة‬ ‫عقدة‬ ‫تحوي‬ ‫شجرة‬ ‫كل‬0‫في‬ ‫وعقدتين‬ ‫المستوى‬1‫المستوى‬ ‫في‬ ‫عقد‬ ‫وأربع‬2‫و‬2 𝑘‫المستوى‬ ‫في‬ ‫عقدة‬k. ■(‫ارتفاعها‬ ‫تامة‬ ‫بشجرة‬ ‫العقد‬ ‫عدد‬h‫هو‬2ℎ+1 − 1) –‫الكاملة‬ ‫الثنائية‬ ‫الشجرة‬:‫بال‬ ‫مليئة‬ ‫مستوياتها‬ ‫كل‬ ‫تكون‬ ‫ثنائية‬ ‫شجرة‬ ‫كل‬‫ماعدا‬ ‫عقد‬ ‫فراغات‬ ‫على‬ ‫يحوي‬ ‫أن‬ ‫يمكن‬ ‫األخير‬ ‫المستوى‬. 2020 By Eng. Joud Khattab
  • 114. Binary Trees (‫الثنائية‬ ‫)األشجار‬ Question 1 ■‫السؤال‬:‫عقدها‬ ‫عدد‬ ‫خطية‬ ‫شجرة‬ ‫ارتفاع‬ ‫هو‬ ‫ما‬n‫؟‬ ■‫اإلجابة‬:n-1 ■‫السؤال‬:‫تامة‬ ‫ثنائية‬ ‫شجرة‬ ‫أوراق‬ ‫عدد‬ ‫كم‬‫؟‬ ■‫اإلجابة‬:2h‫حيث‬h‫الشجرة‬ ‫ارتفاع‬ ‫هو‬ ■‫السؤال‬:‫؟‬ ‫تامة‬ ‫ثنائية‬ ‫لشجرة‬ ‫العقد‬ ‫عدد‬ ‫كم‬ ■‫اإلجابة‬: ෍ 𝒊=𝟎 𝒊=𝒉 𝟐𝒊 = 𝟐 𝒉+𝟏 − 𝟏 2020 By Eng. Joud Khattab
  • 115. Binary Trees (‫الثنائية‬ ‫)األشجار‬ Question 2 ■‫السؤال‬:‫ثنائية؟‬ ‫بحث‬ ‫شجرة‬ ‫ضمن‬ ‫للبحث‬ ‫حالة‬ ‫أسوأ‬ ‫ماهي‬ ■‫اإلجابة‬:‫أعظمية‬ ‫التجول‬ ‫مسافة‬ ‫تكون‬ ‫حيث‬ ‫خطية‬ ‫الشجرة‬ ‫تكون‬ ‫عندما‬. ■‫السؤال‬:‫ثنائية؟‬ ‫بحث‬ ‫شجرة‬ ‫ضمن‬ ‫للبحث‬ ‫حالة‬ ‫أفضل‬ ‫ماهي‬ ■‫اإلجابة‬:‫التجول‬ ‫مسافة‬ ‫تكون‬ ‫متوازنة‬ ‫او‬ ‫كاملة‬ ‫الشجرة‬ ‫تكون‬ ‫عندما‬‫أصغرية‬. 2020 By Eng. Joud Khattab
  • 116. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ ■‫التالية‬ ‫الخواص‬ ‫تحقق‬ ‫ثنائية‬ ‫شجرة‬ ‫هي‬: –‫محددة‬ ‫عقدة‬ ‫أجل‬ ‫من‬n‫أصغر‬ ‫هي‬ ‫اليسارية‬ ‫الجزئية‬ ‫الشجرة‬ ‫في‬ ‫المخزنة‬ ‫القيم‬ ‫كل‬ ‫العقدة‬ ‫في‬ ‫المخزنة‬ ‫القيمة‬ ‫من‬n. –‫محددة‬ ‫عقدة‬ ‫أجل‬ ‫من‬n‫أكب‬ ‫هي‬ ‫اليمينية‬ ‫الجزئية‬ ‫الشجرة‬ ‫في‬ ‫المخزنة‬ ‫القيم‬ ‫كل‬‫ر‬ ‫العقدة‬ ‫في‬ ‫المخزنة‬ ‫القيمة‬ ‫من‬n. 2020 By Eng. Joud Khattab
  • 117. Binary Search Trees (‫الثنائية‬ ‫)األشجار‬ Binary search tree Not a binary search tree 5 10 30 2 25 45 5 10 45 2 25 30 5 10 30 2 25 45 Binary search tree 2020 By Eng. Joud Khattab
  • 118. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ Inserting Method 2020 By Eng. Joud Khattab
  • 119. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ Representation Methods ■‫الثنائية‬ ‫األشجار‬ ‫تمثيل‬ ‫طرق‬: –‫المؤشرات‬ ‫طريق‬ ‫عن‬. –‫أعمدتها‬ ‫وعدد‬ ‫العقد‬ ‫بعدد‬ ‫أسطرها‬ ‫عدد‬ ‫يكون‬ ‫حيث‬ ‫المصفوفات‬ ‫طريق‬ ‫عن‬3‫حيث‬ ‫االبن‬ ‫رقم‬ ‫الثالث‬ ‫وفي‬ ‫االيمن‬ ‫االبن‬ ‫رقم‬ ‫والثاني‬ ‫العقدة‬ ‫رقم‬ ‫األول‬ ‫العمود‬ ‫يحوي‬ ‫االيسر‬. 2020 By Eng. Joud Khattab
  • 120. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ Question 3 ■‫السؤال‬:‫تعتبر‬ ‫التالية‬ ‫الشجر‬ ‫من‬ ‫أي‬"‫ثنائية‬ ‫بحث‬ ‫شجرة‬"‫؟‬ ■‫اإلجابة‬:b‫و‬c 2020 By Eng. Joud Khattab
  • 121. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ Question 4 ■‫السؤال‬:‫المصفوفات؟؟‬ ‫طريقة‬ ‫سيئة‬ ‫ماهي‬ ■‫اإلجابة‬:‫الكاملة‬ ‫أو‬ ‫التامة‬ ‫غير‬ ‫األشجار‬ ‫حالة‬ ‫في‬ ‫للذاكرة‬ ‫كبير‬ ‫هدر‬ ‫فيها‬. 2020 By Eng. Joud Khattab
  • 122. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ AVL (Height-balanced Trees) ■ An AVL tree (or height-balanced tree) is a binary search tree such that: – The height of the left and right subtrees of the root differ by at most 1 – The left and right subtrees of the root are AVL trees 2020 By Eng. Joud Khattab
  • 123. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ DFS ■‫الشجرة‬ ‫في‬ ‫التجول‬ ‫طرق‬: –‫أوال‬ ‫بالعمق‬ ‫التجول‬(depth first search) 33 -1 6 22 16 8 7 45 start ‫التجول‬ ‫في‬ ‫العقد‬ ‫زيارة‬ ‫ترتيب‬VLR: 22,6,-1,8,7,16,33,45 2020 By Eng. Joud Khattab
  • 124. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ DFS ■‫الشجرة‬ ‫في‬ ‫التجول‬ ‫طرق‬:‫أوال‬ ‫بالعمق‬ ‫التجول‬(depth first search) –VLR‫الترتي‬ ‫ويدعى‬ ،‫اليمينية‬ ‫ثم‬ ‫اليسارية‬ ‫الجزئية‬ ‫الشجرة‬ ‫ثم‬ ‫العقدة‬ ‫يزور‬‫المصدر‬ ‫ب‬ (preorder.) –VRL‫اليسارية‬ ‫ثم‬ ‫اليمينية‬ ‫الجزئية‬ ‫الشجرة‬ ‫ثم‬ ‫العقدة‬ ‫يزور‬. –LVR‫الترتي‬ ‫ويدعى‬ ‫اليمينية‬ ‫ثم‬ ‫العقدة‬ ‫ثم‬ ‫اليسارية‬ ‫الجزئية‬ ‫الشجرة‬ ‫يزور‬‫المتناظر‬ ‫ب‬ (inorder.) –RVL –LRV‫الملحق‬ ‫الترتيب‬ ‫ويدعى‬(postorder.) –RLV 2020 By Eng. Joud Khattab
  • 125. Binary Search Trees (‫الثنائية‬ ‫البحث‬ ‫)أشجار‬ BFS ■‫الشجرة‬ ‫في‬ ‫التجول‬ ‫طرق‬: –‫أوال‬ ‫بالعرض‬ ‫التجول‬(breadth first search.) 33 -1 6 22 16 8 7 45 ‫التجول‬ ‫في‬ ‫العقد‬ ‫زيارة‬ ‫ترتيب‬VLR: 22,6,33,-1,8,45,7,16 2020 By Eng. Joud Khattab
  • 127. Graphs (‫)البيانات‬ ■‫كعقد‬ ‫العناصر‬ ‫تخزن‬ ‫معطيات‬ ‫بنية‬ ‫هي‬vertex‫العق‬ ‫بين‬ ‫العالقات‬ ‫تمثل‬ ‫وصالت‬ ‫بينها‬ ‫ويوجد‬‫د‬ edges. ■‫النظ‬ ‫الناحية‬ ‫من‬ ‫التسلسلية‬ ‫غير‬ ‫الهرمية‬ ‫للبنى‬ ‫تعميما‬ ‫البيانات‬ ‫اعتبار‬ ‫يمكن‬‫فاألشجار‬ ،‫رية‬ ‫البيانات‬ ‫من‬ ‫خاصة‬ ‫حالة‬ ‫هي‬(‫حلقات‬ ‫تحوي‬ ‫ال‬ ‫بيانات‬.) 2020 By Eng. Joud Khattab
  • 128. Graphs (‫)البيانات‬ ■‫مكان‬ ‫كل‬ ‫في‬ ‫البيانات‬ ‫تتواجد‬: –‫الحواسيب‬ ‫شبكات‬ ،‫الجوية‬ ‫الخطوط‬ ،‫الطرق‬ ‫شبكات‬. ■‫الصنعي‬ ‫الذكاء‬ ‫في‬ ‫المسائل‬ ‫حل‬ ‫منهجيات‬ ‫أهم‬ ‫من‬: –‫بيان‬ ‫في‬ ‫بحث‬ ‫مسألة‬ ‫إلى‬ ‫المسألة‬ ‫تحويل‬. 2020 By Eng. Joud Khattab
  • 129. Graphs (‫)البيانات‬ ■‫العقدة‬ ‫درجة‬Deg(v)‫إليها‬ ‫والواردة‬ ‫العقدة‬ ‫من‬ ‫الصادرة‬ ‫األسهم‬ ‫عدد‬ ‫هي‬ –‫حيث‬Deg-(v)‫الواردة‬ ‫الدرجة‬ ‫هي‬. –‫و‬Deg+(v)‫الصادرة‬ ‫الدرجة‬ ‫هي‬. ■‫عقدتين‬ ‫كل‬ ‫حالة‬ ‫في‬ ‫كان‬ ‫إذا‬ ‫بشدة‬ ‫متصل‬ ‫البيان‬ ‫يكون‬v,w‫من‬ ‫طريق‬ ‫يوجد‬v‫إلى‬w‫و‬ ‫من‬w‫إلى‬v ■‫يحوي‬ ‫موجه‬ ‫غير‬ ‫بيان‬ ‫في‬ ‫األعظمي‬ ‫الروابط‬ ‫عدد‬n‫يساوي‬ ‫عقدة‬ 𝑛(𝑛−1) 2 ‫هذه‬ ‫وفي‬ ‫تام‬ ‫إنه‬ ‫البيان‬ ‫عن‬ ‫نقول‬ ‫الحالة‬(Complete.) 2020 By Eng. Joud Khattab
  • 130. Graphs (‫)البيانات‬ ■‫التجاور‬ ‫مصفوفة‬ ‫باستخدام‬ ‫البيان‬ ‫تمثيل‬(adjacency matrix.) The Graph The Adjacency Matrix 2020 By Eng. Joud Khattab
  • 131. Graphs (‫)البيانات‬ ■‫التجاور‬ ‫قائمة‬ ‫باستخدام‬ ‫البيان‬ ‫تمثيل‬(adjacency list.) The Adjacency List The Graph 2020 By Eng. Joud Khattab
  • 132. Graphs (‫)البيانات‬ Question 1 ■‫السؤال‬:‫التجاور؟‬ ‫قائمة‬ ‫بطريقة‬ ‫ممثلة‬ ‫لعقدة‬ ‫مجاورة‬ ‫عقد‬ ‫عن‬ ‫البحث‬ ‫كلفة‬ ‫ماهي‬ ■‫الجواب‬:O(deg(v)) ■‫السؤال‬:‫التج‬ ‫قائمة‬ ‫بطريقة‬ ‫ممثل‬ ‫بيان‬ ‫في‬ ‫لعقدة‬ ‫الواردة‬ ‫الروابط‬ ‫مسح‬ ‫كلفة‬ ‫ماهي‬‫اور؟‬ ■‫الجواب‬:O(V+E)‫جدا‬ ‫مكلف‬ 2020 By Eng. Joud Khattab
  • 133. Graphs (‫)البيانات‬ ■‫البيان‬ ‫في‬ ‫التجول‬ ‫طرق‬: –‫أوال‬ ‫العمق‬(DFS.) –‫أوال‬ ‫العرض‬(BFS:)‫الوصول‬ ‫ألن‬ ‫موزون‬ ‫غير‬ ‫بيان‬ ‫في‬ ‫طريق‬ ‫أقصر‬ ‫إليجاد‬ ‫طريقة‬ ‫هي‬ ‫للروابط‬ ‫عدد‬ ‫أقل‬ ‫بمسح‬ ‫يتم‬ ‫للعقد‬. 2020 By Eng. Joud Khattab
  • 134. Graphs (‫)البيانات‬ DFS V.S BFS 2020 By Eng. Joud Khattab
  • 135. Graphs (‫)البيانات‬ Dijkstra ■‫خوارزمية‬Dijkstra‫موزون‬ ‫بيان‬ ‫في‬ ‫طريق‬ ‫أقصر‬ ‫إليجاد‬. 2020 By Eng. Joud Khattab
  • 136. Graphs (‫)البيانات‬ Dijkstra 1 6 2 5 4 3 8 9 7 4 7 12 3 4 5 11 8 6 9 2 1 2 3 4 5 6 7 8 9 0 ? ? ? ? ? ? ? ? -1 -1 -1 -1 -1 -1 -1 -1 -1 Processed distance predecessor 2020 By Eng. Joud Khattab
  • 137. Graphs (‫)البيانات‬ Topological Sort ■‫الفرز‬‫الطبولوجي‬‫األسهم‬ ‫كل‬ ‫تكون‬ ‫حيث‬ ‫ورودها‬ ‫درجات‬ ‫حسب‬ ‫العقد‬ ‫ترتيب‬ ‫على‬ ‫يعتمد‬‫او‬ ‫اليمين‬ ‫هي‬ ‫واحدة‬ ‫جهة‬ ‫إلى‬ ‫تؤشر‬ ‫الوصالت‬. ■‫حلقات‬ ‫على‬ ‫يحتوي‬ ‫الذي‬ ‫البيان‬ ‫على‬ ‫تطبيقها‬ ‫يمكن‬ ‫ال‬. ■‫مثال‬: –‫لجامعة‬ ‫السنوي‬ ‫المنهاج‬. 2020 By Eng. Joud Khattab
  • 138. Graphs (‫)البيانات‬ Topological Sort 1 2 4 5 3 6 7 8 next 0 1 2 3 4 5 6 7 8 2 2 3 2 1 1 0 2 Node Indegree LIST 7 2020 By Eng. Joud Khattab
  • 139. Graphs (‫)البيانات‬ Minimum Spanning Tree ■‫االرتباط‬ ‫شجرة‬‫األصغرية‬:‫الروابط‬ ‫من‬ ‫ممكنة‬ ‫كلفة‬ ‫بأقل‬ ‫البيان‬ ‫تربط‬ ‫شجرة‬ ‫هي‬. ■‫فقط‬ ‫المترابط‬ ‫البيان‬ ‫حالة‬ ‫في‬ ‫الشجرة‬ ‫هذه‬ ‫تتواجد‬. ■Prim’s algorithm a c e d b 2 45 9 6 4 5 5 a c e d b 2 45 9 6 4 5 5 2020 By Eng. Joud Khattab
  • 141. Bubble Sort Algorithm ( ‫الفرز‬ ‫خوارزمية‬‫الفقاعي‬ ) ■‫الفرز‬ ‫خوارزمية‬ ‫تعقيد‬‫الفقاعي‬: –‫األحوال‬ ‫أحسن‬:‫حيث‬ ‫مفروزة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬‫اليوجد‬‫اسناد‬ ‫عمليات‬. –‫األحوال‬ ‫أسوأ‬:‫المصفوفة‬ ‫تكون‬ ‫عندما‬‫مرتية‬‫عمليات‬ ‫عدد‬ ‫يكون‬ ‫عكسي‬ ‫ترتيب‬ ‫مرتبة‬ ‫من‬ ‫االسناد‬O(n*n). –‫الوسطية‬ ‫الحالة‬:ً‫عشوائيا‬ ‫مرتبة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬O(n*n). 2020 By Eng. Joud Khattab
  • 142. Selection Sort Algorithm (‫باالختيار‬ ‫الفرز‬ ‫)خوارزمية‬ ■‫الخوارزمية‬ ‫تعقيد‬: –‫المقارنة‬ ‫عمليات‬ ‫عدد‬O(n*n) –‫التبديل‬ ‫عمليات‬ ‫عدد‬O(n) ■‫مكل‬ ‫غير‬ ‫المقارنة‬ ‫وعملية‬ ‫مكلفة‬ ‫التبديل‬ ‫عملية‬ ‫كانت‬ ‫حالة‬ ‫وفي‬ ‫صغير‬ ‫لحجم‬ ‫جيدة‬‫فة‬. 2020 By Eng. Joud Khattab
  • 143. Insertion Sort Algorithm (‫باإلضافة‬ ‫الفرز‬ ‫)خوارزمية‬ ■‫باإلضافة‬ ‫الفرز‬ ‫خوارزمية‬ ‫تعقيد‬: –‫األحوال‬ ‫أحسن‬:‫اسناد‬ ‫عمليات‬ ‫يوجد‬ ‫ال‬ ‫حيث‬ ‫مفروزة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬O(1) ‫المقارنة‬ ‫وعمليات‬O(n). –‫األحوال‬ ‫أسوأ‬:‫المصفوفة‬ ‫تكون‬ ‫عندما‬‫مرتية‬‫عمليات‬ ‫عدد‬ ‫يكون‬ ‫عكسي‬ ‫ترتيب‬ ‫مرتبة‬ ‫من‬ ‫االسناد‬O(n*n). –‫الوسطية‬ ‫الحالة‬:ً‫عشوائيا‬ ‫مرتبة‬ ‫المصفوفة‬ ‫تكون‬ ‫عندما‬O(n*n). 2020 By Eng. Joud Khattab
  • 144. Merge Sort Algorithm (‫بالدمج‬ ‫الفرز‬ ‫)خوارزمية‬ ■‫تسد‬ ‫فرق‬ ‫مبدأ‬ ‫تعتمد‬. ■‫يلي‬ ‫بما‬ ‫تقوم‬ ‫عوديه‬ ‫خوارزمية‬ ‫هي‬: –،‫جزئين‬ ‫إلى‬ ‫المصفوفة‬ ‫تقسم‬ –،‫حدا‬ ‫على‬ ‫جزء‬ ‫كل‬ ‫تفرز‬ –‫المفروزين‬ ‫الجزئيين‬ ‫تدمج‬ ‫مفروزة‬ ‫واحدة‬ ‫مصفوفة‬ ‫في‬. ■‫الخوارزمية‬ ‫تعقيد‬: –O(nlog(n))‫دوما‬ 2020 By Eng. Joud Khattab
  • 145. Quick Sort Algorithm (‫السريع‬ ‫الفرز‬ ‫)خوارزمية‬ ■‫الخوارزمية‬ ‫تعقيد‬: –O(nlog(n))‫الوسطية‬ ‫والحالة‬ ‫األحوال‬ ‫أحسن‬ ‫في‬. –O(n*n)‫األحوال‬ ‫أسوأ‬ ‫في‬. 2020 By Eng. Joud Khattab
  • 146. Sorting Algorithms 2020 By Eng. Joud Khattab
  • 147. SEARCH ALGORITHMS ‫مصفوفة‬ ‫في‬ ‫البحث‬ ‫خوارزميات‬ 2020 By Eng. Joud Khattab
  • 148. Search Algorithms Binary V.S. Sequential ■‫التسلسلي‬ ‫البحث‬:‫تعقيده‬O(n) ■‫الثنائي‬ ‫البحث‬:‫تعقيده‬O(log(n)) 2020 By Eng. Joud Khattab
  • 150. Backtracking Algorithms (‫التراجعية‬ ‫)الخوارزميات‬ ■‫خوارزميات‬ ‫هي‬‫عودية‬‫المشاكل‬ ‫حل‬ ‫في‬ ‫والخطأ‬ ‫التجريب‬ ‫طريقة‬ ‫تعتمد‬. ■‫الخطوات‬ ‫من‬ ‫مجموعة‬ ‫طريق‬ ‫عن‬ ‫للمسألة‬ ‫النهائي‬ ‫الحل‬ ‫ببناء‬ ‫الطريقة‬ ‫هذه‬ ‫تتلخص‬: –،‫التالية‬ ‫للخطوة‬ ‫المتاحة‬ ‫اإلمكانيات‬ ‫نحدد‬ ‫الخطوة‬ ‫في‬ –،‫أحدها‬ ‫ننتقي‬ ‫بأن‬ ‫اإلمكانيات‬ ‫هذه‬ ‫ندرس‬ ‫ثم‬ –،‫النهائي‬ ‫الحل‬ ‫في‬ ‫التالية‬ ‫الخطوة‬ ‫أنها‬ ‫على‬ ‫نسجلها‬ ‫و‬ –‫الخطوة‬ ‫هذه‬ ‫على‬ ً‫اعتمادا‬ ‫الخوارزمية‬ ‫نتابع‬ ‫و‬. –‫مسدو‬ ‫طريق‬ ‫إلى‬ ‫يؤدي‬ ‫أو‬ ،‫النهائي‬ ‫الحل‬ ‫إلى‬ ‫يقود‬ ‫ال‬ ‫اختيارنا‬ ‫أن‬ ‫لنا‬ ‫يظهر‬ ‫عندما‬،‫د‬ –‫الخطوة‬ ‫هذه‬ ‫عن‬ ‫نعدل‬. ■‫مرتين‬ ‫الخطأ‬ ‫في‬ ‫الوقوع‬ ‫تجنب‬ ‫في‬ ‫يفيد‬ ‫أخطاء‬ ‫سجل‬ ‫بناء‬ ‫العملية‬ ‫هذه‬ ‫تشبه‬. 2020 By Eng. Joud Khattab
  • 151. Backtracking Algorithms (‫التراجعية‬ ‫)الخوارزميات‬ ■‫مثال‬: –‫الشطرنج‬ ‫حصان‬ ‫جولة‬ ‫مسألة‬: ■‫باست‬ ‫وذلك‬ ‫الحصان‬ ‫فيه‬ ‫يقف‬ ‫معين‬ ‫موقع‬ ‫من‬ ‫الشطرنج‬ ‫رقعة‬ ‫لتغطية‬ ‫طريقة‬ ‫إيجاد‬‫خدام‬ ‫واحدة‬ ‫مرة‬ ‫مربع‬ ‫بكل‬ ‫المرور‬ ‫وبشرط‬ ‫الشطرنج‬ ‫في‬ ‫المعروفة‬ ‫الحصان‬ ‫حركات‬. –‫الثمانية‬ ‫الوزراء‬ ‫مسألة‬: ■‫لألخر‬ ‫مهدد‬ ‫واحد‬ ‫اي‬ ‫فيها‬ ‫يكون‬ ‫ال‬ ‫بحيث‬ ‫الشطرنج‬ ‫رقعة‬ ‫على‬ ‫وزراء‬ ‫ثمانية‬ ‫توزيع‬. –‫األمثل‬ ‫الخيار‬ ‫مسألة‬: ■‫معاي‬ ‫وفق‬ ‫األمثل‬ ‫بالحل‬ ‫واالحتفاظ‬ ‫معينة‬ ‫لمسألة‬ ‫ايجادها‬ ‫يمكن‬ ‫التي‬ ‫الحلول‬ ‫مقارنة‬‫ير‬ ‫للمسألة‬ ‫محددة‬. 2020 By Eng. Joud Khattab
  • 152. Greedy Algorithms (‫الجشعة‬ ‫)الخوارزميات‬ ■‫هي‬‫خوارزمية‬‫على‬ ‫تستند‬ ‫التي‬‫المهني‬ ‫الحدس‬‫اإلمكاني‬ ‫اختيار‬ ‫طريقه‬ ‫عن‬ ‫يتم‬ ‫الذي‬‫ة‬ ‫الحالية‬ ‫المرحلة‬ ‫في‬ ‫المرئية‬ ‫األفضل‬(‫الحالية‬ ‫المرحلة‬ ‫في‬ ‫األمثل‬ ‫الحل‬),‫األ‬ ‫دون‬ ‫من‬‫خذ‬ ‫الحل‬ ‫تكملة‬ ‫على‬ ‫الخطوة‬ ‫هذه‬ ‫تأثير‬ ‫بالحسبان‬. ■‫للمسألة‬ ‫األمثل‬ ‫الحل‬ ‫إلى‬ ‫المرحلي‬ ‫األمثل‬ ‫الحل‬ ‫يقودنا‬ ‫ال‬ ‫قد‬. ■‫خياراتها‬ ‫عن‬ ‫تتراجع‬ ‫ان‬ ‫يكن‬ ‫ال‬ ‫الجشع‬ ‫خوارزمية‬.‫بينها‬ ‫الرئيسي‬ ‫الفرق‬ ‫هو‬ ‫هذا‬ ‫وبين‬‫الديناميكية‬ ‫البرمجة‬. ■‫وأشجار‬ ‫برايم‬ ‫خوارزمية‬ ‫مثل‬‫هوفمان‬. 2020 By Eng. Joud Khattab
  • 153. Divide and Conquer (‫تسد‬ ‫فرق‬ ‫)خوارزميات‬ ■‫عمل‬‫خوارزمية‬‫مسألتين‬ ‫إلى‬ ‫عودي‬ ‫بشكل‬ ‫المسألة‬ ‫تقسيم‬ ‫طريق‬ ‫عن‬ ‫تسد‬ ‫فرق‬ ‫فيه‬ ‫بما‬ ‫بسيطة‬ ‫الجزئية‬ ‫المسائل‬ ‫تصبح‬ ‫حتى‬ ،‫النوع‬ ‫نفس‬ ‫من‬ ‫أكثر‬ ‫أو‬ ‫جزئيتين‬‫الكفاية‬ ‫مباشر‬ ‫بشكل‬ ‫لتحل‬.‫ا‬ ‫للمسألة‬ ً‫حال‬ ‫لتعطي‬ ‫الجزئية‬ ‫المسائل‬ ‫حلول‬ ‫تدمج‬ ‫ثم‬ ‫ومن‬‫لجزئية‬. ■‫امثلة‬: –‫الثنائي‬ ‫البحث‬ ‫خوارزميات‬. –‫بالدمج‬ ‫الفرز‬ ‫خوارزميات‬. –‫السريع‬ ‫الفرز‬ ‫خوارزميات‬. –‫هانوي‬ ‫ابراج‬ ‫خوارزمية‬. 2020 By Eng. Joud Khattab
  • 154. Dynamic Programming (‫الديناميكية‬ ‫)البرمجة‬ ■‫المسألة‬ ‫من‬ ‫مختلفة‬ ‫أجزاء‬ ‫حل‬ ‫إلى‬ ‫بحاجة‬ ‫نحن‬ ،‫ما‬ ‫مسألة‬ ‫لحل‬(‫فرعية‬ ‫مسائل‬)‫ومن‬ ، ‫شامل‬ ‫حل‬ ‫على‬ ‫للحصول‬ ‫الفرعية‬ ‫المسائل‬ ‫حلول‬ ‫جمع‬ ‫ثم‬. ■‫الديناميكية‬ ‫البرمجة‬ ‫نهج‬: –،‫فقط‬ ‫واحدة‬ ‫مرة‬ ‫فرعية‬ ‫مسألة‬ ‫كل‬ ‫حل‬ ‫عن‬ ‫البحث‬ –‫الحسابات‬ ‫عدد‬ ‫تقليل‬ ‫وبالتالي‬:‫حف‬ ‫يتم‬ ،‫ما‬ ‫فرعية‬ ‫مسألة‬ ‫حل‬ ‫حساب‬ ‫تم‬ ‫حالما‬،‫ظه‬ ‫استرجاعه‬ ‫ببساطة‬ ‫يتم‬ ،‫نفسه‬ ‫للحل‬ ‫الحاجة‬ ‫عند‬ ‫القادمة‬ ‫المرة‬ ‫وفي‬. ■‫وتق‬ ‫الثانوية‬ ‫للمسائل‬ ‫السابقة‬ ‫الحلول‬ ‫ستدرس‬ ‫الديناميكية‬ ‫البرمجة‬ ‫خوارزميات‬‫بدمجها‬ ‫وم‬ ‫حله‬ ‫المراد‬ ‫للمسائلة‬ ‫حل‬ ‫افضل‬ ‫علي‬ ‫للحصول‬. 2020 By Eng. Joud Khattab
  • 156. Hashing Tables (‫التقطيع‬ ‫)جداول‬ ■‫موقعه‬ ‫إلى‬ ‫المباشر‬ ‫النفاذ‬ ‫خالل‬ ‫من‬ ‫بحث‬ ‫خوارزمية‬ ‫إلى‬ ‫الحاجة‬ ‫دون‬ ‫مباشرة‬ ‫عنصر‬ ‫لإليجاد‬ ‫طريقة‬ ‫هي‬. ■‫التالية‬ ‫التطبيقات‬ ‫برمجة‬ ‫في‬ ‫فعالة‬ ‫بنية‬ ‫هي‬: –‫معجم‬ ‫عمليات‬ ‫إلى‬ ‫تحتاج‬ ‫التي‬. –‫بالترتيب‬ ‫تهتم‬ ‫ال‬ ‫التي‬ ‫االمثلة‬. ■‫المفتاح‬ ‫ذو‬ ‫العنصر‬ ‫يخزن‬k‫الخانة‬ ‫في‬h(k)‫حيث‬h‫الخانة‬ ‫دليل‬ ‫لحساب‬ ‫يستخدم‬ ‫الذي‬ ‫التقطيع‬ ‫تابع‬ ‫هو‬ ‫المفتاح‬ ‫من‬k. ■‫التقطيع‬ ‫تابع‬ ‫قيمة‬ ‫نفس‬ ‫لهما‬ ‫مفتاحين‬ ‫وجود‬ ‫حال‬ ‫في‬ ‫تصادم‬ ‫يحدث‬ ‫قد‬. ■‫من‬ ‫ازواج‬ ‫شكل‬ ‫على‬ ‫القيم‬ ‫تخزن‬(key, value) ■‫القيم‬ ‫من‬ ‫سلسلة‬ ‫حول‬ ‫للتجول‬ ‫جيدة‬ ‫بنية‬ ‫ليست‬ ‫التقطيع‬ ‫جداول‬( .Iteration) ■‫مناسبة‬ ‫فرضيات‬ ‫ضمن‬ ‫تقطيع‬ ‫جدول‬ ‫في‬ ‫عنصر‬ ‫عن‬ ‫والبحث‬ ‫إلضافة‬ ‫المتوقع‬ ‫الزمن‬O(1)( .‫الوسطية‬ ‫الحالة‬) 2020 By Eng. Joud Khattab
  • 157. Hashing Tables V.S. Other Data Structures ■ We want to implement the dictionary operations Insert(), Delete() and Search()/Find() efficiently. ■ Arrays: – can accomplish in O(n) time – but are not space efficient (assumes we leave empty space for keys not currently in dictionary) ■ Binary search trees – can accomplish in O(log n) time – are space efficient. ■ Hash Tables: – A generalization of an array that under some reasonable assumptions is O(1) for Insert/Delete/Search of a key 2020 By Eng. Joud Khattab
  • 158. Hashing Tables (‫التقطيع‬ ‫)جداول‬ ■‫المباشرة‬ ‫العنونة‬ ‫باستخدام‬ ‫المعلومات‬ ‫تخزين‬ ‫عن‬ ‫مثال‬: ■‫مفتاح‬ ‫لكل‬ ‫الجدول‬ ‫من‬ ‫موقع‬ ‫منح‬ ‫نستطيع‬ ‫عندما‬ ‫تستخدم‬(‫ت‬ ‫المتوقع‬ ‫العناصر‬ ‫عدد‬‫خزينها‬ ‫للعناصر‬ ‫الكلي‬ ‫العدد‬ ‫من‬ ‫قريب‬. Anas - Mazzah 0000001 6131467 6131468 6131469 6131470 9999997 9999998 9999999 Each phone number uniquely determines an array element 0000000 Record for phone number 6131496 For technical or commercial reasons, certain numbers may not be assigned to any subscriber 2020 By Eng. Joud Khattab
  • 159. Hashing Tables (‫التقطيع‬ ‫)جداول‬ ■ For example, if we hash keys 0…1000 into a hash table with 5 entries and use h(key) = key mod 5 , we get the following sequence of events: 0 1 2 3 4 key data Insert 2 2 … 0 1 2 3 4 key data Insert 21 2 … 21 … 0 1 2 3 4 key data Insert 34 2 … 21 … 34 … Insert 54 There is a collision at array entry #4 ??? 2020 By Eng. Joud Khattab
  • 160. Hashing Tables (‫التقطيع‬ ‫)جداول‬ ■‫التصادم‬ ‫لحل‬ ‫الربط‬ ‫تقنية‬: –‫خطية‬ ‫سلسلة‬ ‫في‬ ‫التقطيع‬ ‫تابع‬ ‫قيمة‬ ‫نفس‬ ‫لها‬ ‫التي‬ ‫العناصر‬ ‫جميع‬ ‫توضع‬. (Hashing with Chaining) –‫المتصادمة‬ ‫العناصر‬ ‫سلسلة‬ ‫بداية‬ ‫إلى‬ ‫مؤشر‬ ‫الجدول‬ ‫خانة‬ ‫تصبح‬. 2020 By Eng. Joud Khattab
  • 161. Hashing Tables (‫التقطيع‬ ‫)جداول‬ Hashing with Chaining 0 1 2 3 4 other key key data Insert 54 2 21 54 34 CHAIN 0 1 2 3 4 Insert 101 2 21 54 34 101 2020 By Eng. Joud Khattab
  • 162. Hashing Tables (‫التقطيع‬ ‫)جداول‬ Hashing with Chaining ■ What is the running time to insert/search/delete? – Insert: It takes O(1) time to compute the hash function and insert at head of linked list – Search: It is proportional to max linked list length – Delete: Same as search 2020 By Eng. Joud Khattab
  • 163. Hashing Tables (‫التقطيع‬ ‫)جداول‬ Question 1 ■‫السؤال‬:‫عنصر؟‬ ‫إضافة‬ ‫عملية‬ ‫كلفة‬ ‫ماهي‬ ■‫الجواب‬:O(1)‫السلسلة‬ ‫رأس‬ ‫في‬ ‫المتصادمة‬ ‫للعناصر‬ ‫اإلضافة‬ ‫تتم‬ ‫حيث‬. ■‫السؤال‬:‫األحوال؟‬ ‫أسوأ‬ ‫في‬ ‫والحذف‬ ‫البحث‬ ‫عملية‬ ‫كلفة‬ ‫ماهي‬ ■‫الجواب‬:‫االحوال‬ ‫أسوأ‬ ‫في‬ ‫وهي‬ ‫المتصادمة‬ ‫للعناصر‬ ‫الخطية‬ ‫السلسلة‬ ‫بطول‬ ‫تتعلق‬O(n)‫عند‬ ‫سيء‬ ‫تقطيع‬ ‫تابع‬ ‫اختيار‬. ■‫السؤال‬:‫واالضافة؟‬ ‫للحذف‬ ‫الوسطية‬ ‫الكلفة‬ ‫ماهي‬ ■‫الجواب‬:‫م‬ ‫توزع‬ ‫يحقق‬ ‫تقطيع‬ ‫تابع‬ ‫استخدام‬ ‫عند‬ ‫السلسلة‬ ‫في‬ ‫الوسطي‬ ‫العناصر‬ ‫عدد‬ ‫هو‬‫نتظم‬ ‫وهو‬n/m‫حيث‬n‫و‬ ‫الكلي‬ ‫العناصر‬ ‫عدد‬m‫الجدول‬ ‫في‬ ‫الخانات‬ ‫عدد‬. 2020 By Eng. Joud Khattab
  • 164. Hashing Function (‫التقطيع‬ ‫)توابع‬ ■‫التقسيم‬ ‫طريقة‬: –‫المفتاح‬ ‫بربط‬k‫قسمة‬ ‫باقي‬ ‫تساوي‬ ‫التي‬ ‫بالخانة‬k‫على‬m. –h(k)=k%m –‫قيم‬ ‫تجنب‬ ‫يجب‬m‫قوى‬ ‫من‬2‫عنها‬ ‫بعيدة‬ ‫أولية‬ ‫أعداد‬ ‫واختيار‬. ■‫الضرب‬ ‫طريقة‬: –‫المفتاح‬ ‫نضرب‬k‫بثابت‬A‫حيث‬0<A<1‫القيمة‬ ‫هذه‬ ‫نضرب‬ ‫ثم‬ ‫الكسري‬ ‫الجزء‬ ‫ونأخذ‬ ‫ب‬m‫الناتج‬ ‫العدد‬ ‫من‬ ‫الطبيعي‬ ‫الجزء‬ ‫ونأخذ‬. –‫للعدد‬ ‫قيمة‬ ‫أي‬ ‫اختيار‬ ‫يمكن‬m. 2020 By Eng. Joud Khattab
  • 165. MCQ 2020 By Eng. Joud Khattab
  • 166. Question 1 ■ For a binary search algorithm to work, it is necessary that the array (list) must be? A. sorted B. unsorted C. in a heap D. popped out of stack 2020 By Eng. Joud Khattab
  • 167. Question 1 ■ For a binary search algorithm to work, it is necessary that the array (list) must be? A. sorted B. unsorted C. in a heap D. popped out of stack 2020 By Eng. Joud Khattab
  • 168. Question 2 ■ Which one of the below mentioned is linear data structure? A. Queue B. Stack C. Arrays D. All of the above 2020 By Eng. Joud Khattab
  • 169. Question 2 ■ Which one of the below mentioned is linear data structure? A. Queue B. Stack C. Arrays D. All of the above 2020 By Eng. Joud Khattab
  • 170. Question 3 ■ Binary search tree has best case run-time complexity of Ο(log n). What could the worst case? A. Ο(n) B. Ο(n2) C. Ο(n3) D. None of the above 2020 By Eng. Joud Khattab
  • 171. Question 3 ■ Binary search tree has best case run-time complexity of Ο(log n). What could the worst case? A. Ο(n) B. Ο(n2) C. Ο(n3) D. None of the above 2020 By Eng. Joud Khattab
  • 172. Question 4 ■ An algorithm is? A. a piece of code to be executed. B. a loosely written code to make final code. C. a step by step procedure to solve problem. D. all of the above. 2020 By Eng. Joud Khattab
  • 173. Question 4 ■ An algorithm is? A. a piece of code to be executed. B. a loosely written code to make final code. C. a step by step procedure to solve problem. D. all of the above. 2020 By Eng. Joud Khattab
  • 174. Question 5 ■ Quick sort running time depends on the selection of? A. size of array B. pivot element C. sequence of values D. none of the above! 2020 By Eng. Joud Khattab
  • 175. Question 5 ■ Quick sort running time depends on the selection of? A. size of array B. pivot element C. sequence of values D. none of the above! 2020 By Eng. Joud Khattab
  • 176. Question 6 ■ A queue data-structure can be used for? A. expression parsing B. recursion C. resource allocation D. all of the above 2020 By Eng. Joud Khattab
  • 177. Question 6 ■ A queue data-structure can be used for? A. expression parsing B. recursion C. resource allocation D. all of the above 2020 By Eng. Joud Khattab
  • 178. Question 7 ■ Program with highest run-time complexity is? A. Tower of Hanoi B. Fibonacci Series C. Prime Number Series D. None of the above 2020 By Eng. Joud Khattab
  • 179. Question 7 ■ Program with highest run-time complexity is? A. Tower of Hanoi B. Fibonacci Series C. Prime Number Series D. None of the above 2020 By Eng. Joud Khattab
  • 180. Question 8 ■ From a complete graph, by removing maximum _______________ edges, we can construct a spanning tree? A. e-n+1 B. n-e+1 C. n+e-1 D. e-n-1 2020 By Eng. Joud Khattab
  • 181. Question 8 ■ From a complete graph, by removing maximum _______________ edges, we can construct a spanning tree? A. e-n+1 B. n-e+1 C. n+e-1 D. e-n-1 2020 By Eng. Joud Khattab
  • 182. Question 9 ■ The worst case complexity of binary search matches with? A. interpolation search B. linear search C. merge sort D. none of the above 2020 By Eng. Joud Khattab
  • 183. Question 9 ■ The worst case complexity of binary search matches with? A. interpolation search B. linear search C. merge sort D. none of the above 2020 By Eng. Joud Khattab
  • 184. Question 10 ■ What is a hash table? A. A structure that maps values to keys. B. A structure that maps keys to values. C. A structure used for storage. D. A structure used to implement stack and queue. 2020 By Eng. Joud Khattab
  • 185. Question 10 ■ What is a hash table? A. A structure that maps values to keys. B. A structure that maps keys to values. C. A structure used for storage. D. A structure used to implement stack and queue. 2020 By Eng. Joud Khattab
  • 186. Question 11 ■ The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is A. T(n) = 2T(n – 2) + 2 B. T(n) = 2T(n – 1) + n C. T(n) = 2T(n/2) + 1 D. T(n) = 2T(n – 1) + 1 2020 By Eng. Joud Khattab
  • 187. Question 11 ■ The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is A. T(n) = 2T(n – 2) + 2 B. T(n) = 2T(n – 1) + n C. T(n) = 2T(n/2) + 1 D. T(n) = 2T(n – 1) + 1 2020 By Eng. Joud Khattab
  • 188. Question 12 ■ What does the following function do for a given Linked List with first node as head? void fun1(struct node* head) { if(head == NULL) return; fun1(head->next); printf("%d ", head->data); } A. Prints all nodes of linked lists B. Prints all nodes of linked list in reverse order C. Prints alternate nodes of Linked List D. Prints alternate nodes in reverse order 2020 By Eng. Joud Khattab
  • 189. Question 12 ■ What does the following function do for a given Linked List with first node as head? void fun1(struct node* head) { if(head == NULL) return; fun1(head->next); printf("%d ", head->data); } A. Prints all nodes of linked lists B. Prints all nodes of linked list in reverse order C. Prints alternate nodes of Linked List D. Prints alternate nodes in reverse order 2020 By Eng. Joud Khattab
  • 190. Question 13 ■ Which of the following points is/are true about Linked List data structure when it is compared with array A. Arrays have better cache locality that can make them better in terms of performance B. It is easy to insert and delete elements in Linked List C. Random access is not allowed in a typical implementation of Linked Lists D. All of the above 2020 By Eng. Joud Khattab
  • 191. Question 13 ■ Which of the following points is/are true about Linked List data structure when it is compared with array A. Arrays have better cache locality that can make them better in terms of performance B. It is easy to insert and delete elements in Linked List C. Random access is not allowed in a typical implementation of Linked Lists D. All of the above 2020 By Eng. Joud Khattab
  • 192. Question 14 ■ Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity? A. Insertion Sort B. Quick Sort C. Heap Sort D. Merge Sort 2020 By Eng. Joud Khattab
  • 193. Question 14 ■ Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity? A. Insertion Sort B. Quick Sort C. Heap Sort D. Merge Sort 2020 By Eng. Joud Khattab
  • 194. Question 15 ■ In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is A. log 2 n B. n/2 C. log 2 n – 1 D. n 2020 By Eng. Joud Khattab
  • 195. Question 15 ■ In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is A. log 2 n B. n/2 C. log 2 n – 1 D. n 2020 By Eng. Joud Khattab
  • 196. Question 16 ■ Which one of the following is an application of Stack Data Structure? A. Managing function calls B. The stock span problem C. Arithmetic expression evaluation D. All of the above 2020 By Eng. Joud Khattab
  • 197. Question 16 ■ Which one of the following is an application of Stack Data Structure? A. Managing function calls B. The stock span problem C. Arithmetic expression evaluation D. All of the above 2020 By Eng. Joud Khattab
  • 198. Question 17 ■ The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is A. 284 B. 213 C. 142 D. 71 2020 By Eng. Joud Khattab
  • 199. Question 17 ■ The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is A. 284 B. 213 C. 142 D. 71 2020 By Eng. Joud Khattab
  • 200. Question 18 ■ How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you. A. 1 B. 2 C. 3 D. 4 2020 By Eng. Joud Khattab
  • 201. Question 18 ■ How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you. A. 1 B. 2 C. 3 D. 4 2020 By Eng. Joud Khattab
  • 202. Question 19 ■ The most appropriate matching for the following pairs X: depth first search 1: heap Y: breadth-first search 2: queue Z: sorting 3: stack A. X—1, Y—2 ,Z –3 B. X—3, Y—1, Z –2 C. X—3, Y—2, Z—1 D. X—2 ,Y—3 , Z--1 2020 By Eng. Joud Khattab
  • 203. Question 19 ■ The most appropriate matching for the following pairs X: depth first search 1: heap Y: breadth-first search 2: queue Z: sorting 3: stack A. X—1, Y—2 ,Z –3 B. X—3, Y—1, Z –2 C. X—3, Y—2, Z—1 D. X—2 ,Y—3 , Z--1 2020 By Eng. Joud Khattab
  • 204. Question 20 ■ Aliasing in the context of programming languages refers to A. multiple variables having the same memory location B. multiple variables having the same value C. multiple variables having the same identifier D. multiple uses of the same variable 2020 By Eng. Joud Khattab
  • 205. Question 20 ■ Aliasing in the context of programming languages refers to A. multiple variables having the same memory location B. multiple variables having the same value C. multiple variables having the same identifier D. multiple uses of the same variable 2020 By Eng. Joud Khattab
  • 206. Question 21 ■ Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort? A. O(n) B. O(n Log n) C. O(n^2) D. O(n!) 2020 By Eng. Joud Khattab
  • 207. Question 21 ■ Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort? A. O(n) B. O(n Log n) C. O(n^2) D. O(n!) 2020 By Eng. Joud Khattab
  • 208. Question 22 ■ The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is: A. n/2 B. (n - 1)/3 C. (n - 1)/2 D. (2n + 1)/3 2020 By Eng. Joud Khattab
  • 209. Question 22 ■ The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is: A. n/2 B. (n - 1)/3 C. (n - 1)/2 D. (2n + 1)/3 2020 By Eng. Joud Khattab
  • 210. Question 23 ■ Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree ? A. 7 5 1 0 3 2 4 6 8 9 B. 0 2 4 3 1 6 5 9 8 7 C. 0 1 2 3 4 5 6 7 8 9 D. 9 8 6 4 2 3 0 1 5 7 2020 By Eng. Joud Khattab
  • 211. Question 23 ■ Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree ? A. 7 5 1 0 3 2 4 6 8 9 B. 0 2 4 3 1 6 5 9 8 7 C. 0 1 2 3 4 5 6 7 8 9 D. 9 8 6 4 2 3 0 1 5 7 2020 By Eng. Joud Khattab
  • 212. Question 24 ■ Consider the following graph. Among the following sequences, Which are depth first traversals of the graph? I) a b e g h f II) a b f e h g III) a b f h g e IV) a f g h b e A. I, II and IV only B. I and IV only C. II, III and IV only D. I, III and IV only 2020 By Eng. Joud Khattab
  • 213. Question 24 ■ Consider the following graph. Among the following sequences, Which are depth first traversals of the graph? I) a b e g h f II) a b f e h g III) a b f h g e IV) a f g h b e A. I, II and IV only B. I and IV only C. II, III and IV only D. I, III and IV only 2020 By Eng. Joud Khattab
  • 214. Question 25 ■ What is the weight of a minimum spanning tree of the following graph ? A. 29 B. 31 C. 38 D. 41 2020 By Eng. Joud Khattab
  • 215. Question 25 ■ What is the weight of a minimum spanning tree of the following graph ? A. 29 B. 31 C. 38 D. 41 2020 By Eng. Joud Khattab
  • 216. Question 26 ■ The best data structure to check whether an arithmetic expression has balanced parentheses is a A. Queue B. Stack C. Tree D. List 2020 By Eng. Joud Khattab
  • 217. Question 26 ■ The best data structure to check whether an arithmetic expression has balanced parentheses is a A. Queue B. Stack C. Tree D. List 2020 By Eng. Joud Khattab
  • 218. Question 27 ■ The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is. A. A B. B C. C D. D 2020 By Eng. Joud Khattab
  • 219. Question 27 ■ The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is. A. A B. B C. C D. D 2020 By Eng. Joud Khattab