SlideShare a Scribd company logo
1 of 17
Data Structure
Lecture #5
Searching Techniques
Ust. Khalid Bana (banajibreel111@gmail.com)
‫المحاضرة‬ ‫محاور‬
•‫تمهيد‬
•‫المتسلسل‬ ‫البحث‬ ‫خوارزمية‬Sequential Searching
•‫الثنائي‬ ‫البحث‬ ‫خوارزمية‬Binary Search
•‫؟‬ ‫أفضل‬ ‫أيهما‬
•‫مع‬ ‫البحث‬ ‫و‬ ‫الترتيب‬ArrayList!!
banajibreel111@gmail.com2
‫تمهيد‬
•‫العمليي‬ ‫أميي‬ ‫و‬ ‫أبيرز‬ ‫مين‬ ‫تعتبير‬ ‫ميا‬ ‫مديدر‬ ‫فيي‬ ‫المعلومات‬ ‫عن‬ ‫البحث‬‫ات‬
‫يية‬ ‫المختل‬ ‫لتنفميية‬ ‫البرمظيييات‬ ‫دييناعة‬ ‫لهييا‬ ‫تحتيياا‬ ‫التييي‬,‫يع‬ ‫ا‬ ‫لهيي‬‫كيي‬
‫افف‬ ‫الخوارزمييات‬ ‫دراسة‬ ‫على‬ ‫الحاسوب‬ ‫علوي‬ ‫مظال‬ ‫في‬ ‫الباحثون‬‫ضيل‬
‫للبحث‬.
•‫استخ‬ ‫و‬ ً‫ة‬‫شهر‬ ‫البحث‬ ‫خوارزميات‬ ‫أكثر‬ ‫سنناقش‬ ‫الوحدة‬ ‫ه‬ ‫م‬ ‫في‬‫ميع‬ ‫داما‬
‫استخدامها‬ ‫المشهور‬ ‫البيانات‬ ‫تراكيب‬.
banajibreel111@gmail.com 3
‫خوارزمية‬Sequential Searching
•‫المتسلسل‬ ‫البحث‬ ‫خوارزمية‬‫على‬ ‫تعتمد‬ ‫مي‬ ‫و‬:
‫عندر‬ ‫عندرا‬ ‫العنادر‬ ‫كافة‬ ‫مع‬ ‫المطلوبة‬ ‫القيمة‬ ‫مقارنة‬.
‫المقارنات‬ ‫تتوق‬ ‫المطلوبة‬ ‫القيمة‬ ‫إيظاد‬ ‫عند‬.
banajibreel111@gmail.com4
‫خوارزمية‬Sequential Searching
banajibreel111@gmail.com5
2 5
8
1
8
8
9
0
9
9
7 9
3
4
5
5
5
6
6
6
7
9
8
0
1 2 3 4 5 6 7 8 9 10 11 12 13
Wanted = 80
array
0
==‫؟‬
.... ....
‫العاشرة‬ ‫الخانة‬ ‫في‬ ‫توجد‬ ‫المطلوبة‬ ‫القيمة‬,‫و‬‫بعد‬ ‫لها‬ ‫وصلنا‬‫عشر‬‫مقارنة‬ ‫عمليات‬
‫خوارزمية‬Sequential Searching‫المصفوفات‬ ‫مع‬
banajibreel111@gmail.com6
1. static void Main(string[] args)
2. { int[] a = { 10, 2, 34, 4, 3, 1, 100 };
3. int wanted = 1;
4. int target_index=-1;
5. for (int i = 0; i < a.Length; i++)
6. if (a[i] == wanted) {
7. target_index = i;
8. break; }
9. if (target_index >= 0)
10. System.out.print (" The wanted value exist at position:
"+(target_index+1)+"'th");
11. System.out.print (); }
‫ذاتي‬ ‫تدريب‬:‫دراست‬ ‫خالل‬ ‫من‬‫ك‬
‫ااااابقة‬‫ا‬‫الس‬ ‫ااااة‬‫ا‬‫البرمج‬ ‫ااااالات‬‫ا‬‫لمس‬,
‫اة‬‫ا‬‫كلم‬ ‫ان‬‫ا‬‫ع‬ ‫ال‬‫ا‬‫للبن‬ ‫اامب‬‫ا‬‫برن‬ ‫اب‬‫ا‬‫اكت‬
‫اااات‬‫ا‬‫كلم‬ ‫ااامن‬‫ا‬‫ص‬ ‫ااان‬‫ا‬‫م‬,‫اااتخدما‬‫ا‬‫مس‬
‫اا‬‫ا‬‫تطبيقه‬ ‫اق‬‫ا‬‫م‬ ‫ال‬‫ا‬‫البن‬ ‫اة‬‫ا‬‫خوارزمي‬
‫باستخدام‬flag
‫خوارزمية‬Binary Search
•‫يين‬‫ي‬‫م‬ ‫مظموعيية‬ ‫ييع‬‫ي‬‫م‬ ‫التعامييل‬ ‫ييى‬‫ي‬‫عل‬ ‫الثنييائي‬ ‫ييث‬‫ي‬‫البح‬ ‫خوارزمييية‬ ‫تعتمييد‬
‫ن‬ ‫أو‬ ‫أرقاي‬ ‫كانت‬ ‫سواء‬ ‫تنازليا‬ ‫أو‬ ‫تداعديا‬ ‫المرتبة‬ ‫العنادر‬‫دوص‬.
•‫ت‬ ‫فيي‬ ‫الحقيقية‬ ‫ه‬ ‫مي‬ ‫عليى‬ ‫االعتمياد‬ ‫فيمكن‬ ‫مرتبة‬ ‫العنادر‬ ‫فن‬ ‫و‬‫ظاميل‬
‫إليى‬ ‫العنادير‬ ‫تقسييمها‬ ‫خيلل‬ ‫من‬ ‫اعتمادما‬ ‫أو‬ ‫العنادر‬ ‫من‬ ‫مظموعة‬
‫مقارني‬ ‫عليى‬ ‫بنياء‬ ‫افخيرب‬ ‫اعتمياد‬ ‫و‬ ‫أحدمما‬ ‫تظامل‬ ‫فيتي‬ ‫ين‬ ‫ند‬‫ميل‬ ‫ة‬
‫يساويه؟‬ ‫أي‬ ‫أدغر‬ ‫أي‬ ‫المراد‬ ‫العندر‬ ‫من‬ ‫أكبر‬ ‫الوسط‬ ‫العندر‬
banajibreel111@gmail.com7
‫النتيظ‬ ‫إلى‬ ‫الودول‬ ‫حتى‬ ‫لك‬ ‫تكرار‬ ‫يتي‬ ‫و‬‫ة‬
‫م‬ ‫العندر‬ َّ‫أن‬ ‫في‬ ‫تتمثل‬ ‫التي‬ ‫و‬ ‫النهائية‬‫وظود‬
‫موظود‬ ‫غير‬ ‫أو‬ ‫لني‬ ‫ال‬ ‫الموقع‬ ‫في‬.
banajibreel111@gmail.com
8
‫خوارزمية‬Binary Search
banajibreel111@gmail.com9
‫خوارزمية‬Binary Search‫المصفوفة‬ ‫مع‬
banajibreel111@gmail.com10
2 5 81 88 90 997 9 34 55 56 66 79 80
1 2 3 4 5 6 7 8 9 10 11 12 13
(0+13) / 2 = 6
If (array[6] == 80)
return 6
Elseif (array[6] >
80)
High = 6 -1
Else
Low = 6+1
Middle = (low + high)/2
Wanted = 80
array
0
(7+13) / 2 = 10
If (array[10] == 80)
return 10
Elseif (array[10] > 80)
High = 10 -1
Else
Low = 10+1
(7+9) / 2 = 8
If (array[8] == 80)
return 8
Elseif (array[8] >
80)
High = 8-1
Else
Low = 8+1
1 2 3
‫خوارزمية‬Binary Search‫المصفوفة‬ ‫مع‬
banajibreel111@gmail.com11
2 5 81 88 90 997 9 34 55 56 66 79 80
1 2 3 4 5 6 7 8 9 10 11 12 13
Middle = (low + high)/2
Wanted = 80
array
0
(7+9) / 2 = 8
If (array[8] == 80)
return 8
Elseif (array[8] >
80)
High = 8-1
Else
Low = 8+1
3
(9+9) / 2 = 9
If (array[9] == 80)
return 8
Elseif (array[9] >
80)
High = 9-1
Else
Low = 9+1
4
return 8
‫خوارزمية‬Binary Search‫المصفوفة‬ ‫مع‬
banajibreel111@gmail.com12
class BinarySearch {
// Returns index of x if it is present in arr[], // else return -1
int binarySearch(int arr[], int x)
{ int l = 0, r = arr.length - 1;
while (l <= r) { int m = l + (r-l)/2;
// Check if x is present at mid
if (arr[m] == x)
return m;
// If x greater, ignore left half
if (arr[m] < x) l = m + 1;
// If x is smaller, ignore right half
else r = m - 1;
}
// if we reach here, then element was // not present
return -1;
}
// Driver method to test above
public static void main(String args[])
{
BinarySearch ob = new BinarySearch();
int arr[] = {2, 3, 4, 10, 40};
int n = arr.length;
int x = 0;
int result = ob.binarySearch(arr, x);
if (result == -1)
System.out.println("Element not present");
else
System.out.println("Element found at " + "index " + result);
} }
banajibreel111@gmail.com
13
‫؟‬ ‫أفضل‬ ‫أيهما‬
•‫خير‬ ‫ا‬ ‫مين‬ ‫أفضيل‬ ‫أحيدمما‬ َّ‫بيَّن‬ ‫مطلقياا‬ ‫الحكي‬ ‫يمكن‬ ‫ال‬,‫وا‬ ‫كيل‬ ‫بيل‬‫حيد‬
‫حاالت‬ ‫في‬ ‫خر‬ ‫ا‬ ‫من‬ ‫أفضل‬ ‫منهما‬,‫يلي‬ ‫كما‬ ‫التوضيح‬ ‫و‬/
‫مرتبا‬ ‫و‬ ‫كبيرة‬ ‫فيها‬ ‫البحث‬ ‫نود‬ ‫التي‬ ‫البيانات‬ ‫كمية‬ ‫تكون‬ ‫عندما‬‫ما‬ ‫بترتيب‬ ‫ة‬,
‫أفضل‬ ‫الثنائي‬ ‫البحث‬ ‫خوارزمية‬ ‫تعتبر‬ ‫الحالة‬ ‫ه‬ ‫م‬ ‫في‬,‫فنه‬ ‫لك‬ ‫و‬‫ه‬ ‫مي‬ ‫فيي‬ ‫ا‬
‫يدم‬‫ي‬‫عن‬ ‫ير‬‫ي‬‫العناد‬ ‫ين‬‫ي‬‫م‬ ‫ير‬‫ي‬‫كبي‬ ‫يدد‬‫ي‬‫ع‬ ‫يي‬‫ي‬‫ف‬ ‫يث‬‫ي‬‫البح‬ ‫ياء‬‫ي‬‫عن‬ ‫يا‬‫ي‬‫علين‬ ‫يتوفر‬‫ي‬‫س‬ ‫ية‬‫ي‬‫الحال‬‫يتي‬‫ي‬‫ي‬ ‫ا‬
‫الشرط‬ ‫على‬ ً‫ء‬‫بنا‬ ‫تظامله‬.
‫مرتبياة‬ ‫غيير‬ ‫و‬ ‫ديغيرة‬ ‫البيانيات‬ ‫كميية‬ ‫تكيون‬ ‫عندما‬,‫ت‬ ‫الحالية‬ ‫ه‬ ‫مي‬ ‫فيي‬‫عتبير‬
‫أفضييل‬ ‫المتسلسييل‬ ‫البحييث‬ ‫خوارزمييية‬,‫غييي‬ ‫و‬ ‫دييغير‬ ‫العناديير‬ ‫عييدد‬ ‫فن‬‫ر‬
‫مرتب‬,‫مبا‬ ‫الثنيائي‬ ‫البحيث‬ ‫اسيتخداي‬ ‫نستطيع‬ ‫ال‬ ‫فإننا‬ ‫بالتالي‬ ‫و‬‫شيرة‬,‫لك‬ ‫كي‬ ‫و‬
‫المقارنات‬ ‫من‬ ‫قليل‬ ‫لعدد‬ ‫سنحتاا‬ ‫أننا‬ ‫يعني‬ ‫الدغير‬ ‫العنادر‬ ‫عدد‬.
banajibreel111@gmail.com14
‫مع‬ ‫البحث‬ ‫و‬ ‫الترتيب‬ArrayList!!
•‫دن‬ ‫يمتلك‬ArrayList‫عنها‬ ‫الحديث‬ ‫سبق‬ ‫التي‬ ‫الدوال‬ ‫من‬ ‫العديد‬,
‫دالتي‬ ‫الدوال‬ ‫ه‬ ‫م‬ ‫من‬ ‫و‬Sort‫و‬BinarySerach.
•‫دالة‬ ‫تقوي‬Sort‫االفتراض‬ ‫المقارنة‬ ‫خلل‬ ‫من‬ ‫وفة‬ ‫المد‬ ‫بترتيب‬‫ية‬
(‫التساوي‬)‫للدالة‬ ‫أنت‬ ‫تعطيها‬ ‫مقارنة‬ ‫خلل‬ ‫من‬ ‫أو‬.
•‫دالة‬ ‫تقوي‬BinarySearch‫م‬ ‫عندر‬ ‫عن‬ ‫وفة‬ ‫المد‬ ‫ضمن‬ ‫بالبحث‬‫ا‬
‫ك‬ ‫إن‬ ‫موضعه‬ ‫رقي‬ ‫تعيد‬ ‫و‬ ‫الثنائي‬ ‫البحث‬ ‫خوارزمية‬ ‫باستخداي‬‫ان‬
‫سالبة‬ ‫قيمة‬ ‫تعيد‬ ‫إال‬ ‫و‬ ‫موظودا‬,‫بترتي‬ ‫اتها‬ ‫الدالة‬ ‫تقوي‬ ‫حيث‬‫ب‬
‫الثنائي‬ ‫البحث‬ ‫تتطبق‬ ‫ثي‬ ‫تداعديا‬ ‫ترتيبا‬ ‫العنادر‬.
banajibreel111@gmail.com
15
‫مع‬ ‫البحث‬ ‫و‬ ‫الترتيب‬ArrayList!!
banajibreel111@gmail.com16
1.import java.util.*;
2.class TestCollection1{
3. public static void main(String args[]){
4. ArrayList<String> list=new ArrayList<String>();
5.//Creating arraylist
6. list.add("Ravi");//Adding object in arraylist
7. list.add("Vijay");
8. list.add("Ravi");
9. list.add("Ajay");
10. //Traversing list through Iterator
11. Iterator itr=list.iterator();
12. while(itr.hasNext()){
13. System.out.println(itr.next());
14. }
15. }
16.}
‫أشكركم‬
banajibreel111@gmail.com17
‫كلها‬ ‫للعلوم‬ ‫مفتاح‬ ‫السؤال‬...
‫بيااة‬ ‫الظا‬ ‫قوانين‬ ‫إلى‬ ‫ودل‬ ‫احاة‬ ‫الت‬ ‫وقعت‬ ‫ا‬ ‫لما‬ ‫سَّل‬ ‫عندما‬ ‫نيوتن‬ ‫أن‬ ‫كر‬ ‫ت‬...

More Related Content

Recently uploaded

الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...
الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...
الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...MaymonSalim
 
GHASSOUB _Seance 6_ measurement and evaluation in education.pptx
GHASSOUB _Seance 6_ measurement and evaluation in education.pptxGHASSOUB _Seance 6_ measurement and evaluation in education.pptx
GHASSOUB _Seance 6_ measurement and evaluation in education.pptxAbderrahim GHASSOUB
 
عربي عربي الجودة ال الجودة امنية فينا.pptx
عربي عربي الجودة ال الجودة امنية فينا.pptxعربي عربي الجودة ال الجودة امنية فينا.pptx
عربي عربي الجودة ال الجودة امنية فينا.pptxdavidwilson702222
 
نظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdf
نظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdfنظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdf
نظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdfHatem Hadia
 
سياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتها
سياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتهاسياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتها
سياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتهاdoaaapotahon05
 
﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء مستجاب.pdf
﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء  مستجاب.pdf﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء  مستجاب.pdf
﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء مستجاب.pdfEmysplanet
 
GHASSOUB _Seance 2_ measurement and evaluation in education.pptx
GHASSOUB _Seance 2_ measurement and evaluation in education.pptxGHASSOUB _Seance 2_ measurement and evaluation in education.pptx
GHASSOUB _Seance 2_ measurement and evaluation in education.pptxAbderrahim GHASSOUB
 
عرض حول اخراج التلاميذ المشاغبين من القسم
عرض حول اخراج التلاميذ المشاغبين من القسمعرض حول اخراج التلاميذ المشاغبين من القسم
عرض حول اخراج التلاميذ المشاغبين من القسمouhdidaa
 

Recently uploaded (8)

الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...
الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...
الكامل في أسانيد وتصحيح حديث لا صلاة لجار المسجد إلا في المسجد وقول النبي لرج...
 
GHASSOUB _Seance 6_ measurement and evaluation in education.pptx
GHASSOUB _Seance 6_ measurement and evaluation in education.pptxGHASSOUB _Seance 6_ measurement and evaluation in education.pptx
GHASSOUB _Seance 6_ measurement and evaluation in education.pptx
 
عربي عربي الجودة ال الجودة امنية فينا.pptx
عربي عربي الجودة ال الجودة امنية فينا.pptxعربي عربي الجودة ال الجودة امنية فينا.pptx
عربي عربي الجودة ال الجودة امنية فينا.pptx
 
نظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdf
نظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdfنظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdf
نظريات العمارة (AR334 )- محاضرة 01-الجزء الثاني.pdf
 
سياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتها
سياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتهاسياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتها
سياسات اليابان وتطورها وتاريخها وثقافتها ونظامها ومهارتها
 
﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء مستجاب.pdf
﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء  مستجاب.pdf﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء  مستجاب.pdf
﴿ فَاسْتَجَبْنَا لَهُ ﴾ دعاء مستجاب.pdf
 
GHASSOUB _Seance 2_ measurement and evaluation in education.pptx
GHASSOUB _Seance 2_ measurement and evaluation in education.pptxGHASSOUB _Seance 2_ measurement and evaluation in education.pptx
GHASSOUB _Seance 2_ measurement and evaluation in education.pptx
 
عرض حول اخراج التلاميذ المشاغبين من القسم
عرض حول اخراج التلاميذ المشاغبين من القسمعرض حول اخراج التلاميذ المشاغبين من القسم
عرض حول اخراج التلاميذ المشاغبين من القسم
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Searching Techniques تقنيات البحث

  • 1. Data Structure Lecture #5 Searching Techniques Ust. Khalid Bana (banajibreel111@gmail.com)
  • 2. ‫المحاضرة‬ ‫محاور‬ •‫تمهيد‬ •‫المتسلسل‬ ‫البحث‬ ‫خوارزمية‬Sequential Searching •‫الثنائي‬ ‫البحث‬ ‫خوارزمية‬Binary Search •‫؟‬ ‫أفضل‬ ‫أيهما‬ •‫مع‬ ‫البحث‬ ‫و‬ ‫الترتيب‬ArrayList!! banajibreel111@gmail.com2
  • 3. ‫تمهيد‬ •‫العمليي‬ ‫أميي‬ ‫و‬ ‫أبيرز‬ ‫مين‬ ‫تعتبير‬ ‫ميا‬ ‫مديدر‬ ‫فيي‬ ‫المعلومات‬ ‫عن‬ ‫البحث‬‫ات‬ ‫يية‬ ‫المختل‬ ‫لتنفميية‬ ‫البرمظيييات‬ ‫دييناعة‬ ‫لهييا‬ ‫تحتيياا‬ ‫التييي‬,‫يع‬ ‫ا‬ ‫لهيي‬‫كيي‬ ‫افف‬ ‫الخوارزمييات‬ ‫دراسة‬ ‫على‬ ‫الحاسوب‬ ‫علوي‬ ‫مظال‬ ‫في‬ ‫الباحثون‬‫ضيل‬ ‫للبحث‬. •‫استخ‬ ‫و‬ ً‫ة‬‫شهر‬ ‫البحث‬ ‫خوارزميات‬ ‫أكثر‬ ‫سنناقش‬ ‫الوحدة‬ ‫ه‬ ‫م‬ ‫في‬‫ميع‬ ‫داما‬ ‫استخدامها‬ ‫المشهور‬ ‫البيانات‬ ‫تراكيب‬. banajibreel111@gmail.com 3
  • 4. ‫خوارزمية‬Sequential Searching •‫المتسلسل‬ ‫البحث‬ ‫خوارزمية‬‫على‬ ‫تعتمد‬ ‫مي‬ ‫و‬: ‫عندر‬ ‫عندرا‬ ‫العنادر‬ ‫كافة‬ ‫مع‬ ‫المطلوبة‬ ‫القيمة‬ ‫مقارنة‬. ‫المقارنات‬ ‫تتوق‬ ‫المطلوبة‬ ‫القيمة‬ ‫إيظاد‬ ‫عند‬. banajibreel111@gmail.com4
  • 5. ‫خوارزمية‬Sequential Searching banajibreel111@gmail.com5 2 5 8 1 8 8 9 0 9 9 7 9 3 4 5 5 5 6 6 6 7 9 8 0 1 2 3 4 5 6 7 8 9 10 11 12 13 Wanted = 80 array 0 ==‫؟‬ .... .... ‫العاشرة‬ ‫الخانة‬ ‫في‬ ‫توجد‬ ‫المطلوبة‬ ‫القيمة‬,‫و‬‫بعد‬ ‫لها‬ ‫وصلنا‬‫عشر‬‫مقارنة‬ ‫عمليات‬
  • 6. ‫خوارزمية‬Sequential Searching‫المصفوفات‬ ‫مع‬ banajibreel111@gmail.com6 1. static void Main(string[] args) 2. { int[] a = { 10, 2, 34, 4, 3, 1, 100 }; 3. int wanted = 1; 4. int target_index=-1; 5. for (int i = 0; i < a.Length; i++) 6. if (a[i] == wanted) { 7. target_index = i; 8. break; } 9. if (target_index >= 0) 10. System.out.print (" The wanted value exist at position: "+(target_index+1)+"'th"); 11. System.out.print (); } ‫ذاتي‬ ‫تدريب‬:‫دراست‬ ‫خالل‬ ‫من‬‫ك‬ ‫ااااابقة‬‫ا‬‫الس‬ ‫ااااة‬‫ا‬‫البرمج‬ ‫ااااالات‬‫ا‬‫لمس‬, ‫اة‬‫ا‬‫كلم‬ ‫ان‬‫ا‬‫ع‬ ‫ال‬‫ا‬‫للبن‬ ‫اامب‬‫ا‬‫برن‬ ‫اب‬‫ا‬‫اكت‬ ‫اااات‬‫ا‬‫كلم‬ ‫ااامن‬‫ا‬‫ص‬ ‫ااان‬‫ا‬‫م‬,‫اااتخدما‬‫ا‬‫مس‬ ‫اا‬‫ا‬‫تطبيقه‬ ‫اق‬‫ا‬‫م‬ ‫ال‬‫ا‬‫البن‬ ‫اة‬‫ا‬‫خوارزمي‬ ‫باستخدام‬flag
  • 7. ‫خوارزمية‬Binary Search •‫يين‬‫ي‬‫م‬ ‫مظموعيية‬ ‫ييع‬‫ي‬‫م‬ ‫التعامييل‬ ‫ييى‬‫ي‬‫عل‬ ‫الثنييائي‬ ‫ييث‬‫ي‬‫البح‬ ‫خوارزمييية‬ ‫تعتمييد‬ ‫ن‬ ‫أو‬ ‫أرقاي‬ ‫كانت‬ ‫سواء‬ ‫تنازليا‬ ‫أو‬ ‫تداعديا‬ ‫المرتبة‬ ‫العنادر‬‫دوص‬. •‫ت‬ ‫فيي‬ ‫الحقيقية‬ ‫ه‬ ‫مي‬ ‫عليى‬ ‫االعتمياد‬ ‫فيمكن‬ ‫مرتبة‬ ‫العنادر‬ ‫فن‬ ‫و‬‫ظاميل‬ ‫إليى‬ ‫العنادير‬ ‫تقسييمها‬ ‫خيلل‬ ‫من‬ ‫اعتمادما‬ ‫أو‬ ‫العنادر‬ ‫من‬ ‫مظموعة‬ ‫مقارني‬ ‫عليى‬ ‫بنياء‬ ‫افخيرب‬ ‫اعتمياد‬ ‫و‬ ‫أحدمما‬ ‫تظامل‬ ‫فيتي‬ ‫ين‬ ‫ند‬‫ميل‬ ‫ة‬ ‫يساويه؟‬ ‫أي‬ ‫أدغر‬ ‫أي‬ ‫المراد‬ ‫العندر‬ ‫من‬ ‫أكبر‬ ‫الوسط‬ ‫العندر‬ banajibreel111@gmail.com7
  • 8. ‫النتيظ‬ ‫إلى‬ ‫الودول‬ ‫حتى‬ ‫لك‬ ‫تكرار‬ ‫يتي‬ ‫و‬‫ة‬ ‫م‬ ‫العندر‬ َّ‫أن‬ ‫في‬ ‫تتمثل‬ ‫التي‬ ‫و‬ ‫النهائية‬‫وظود‬ ‫موظود‬ ‫غير‬ ‫أو‬ ‫لني‬ ‫ال‬ ‫الموقع‬ ‫في‬. banajibreel111@gmail.com 8
  • 10. ‫خوارزمية‬Binary Search‫المصفوفة‬ ‫مع‬ banajibreel111@gmail.com10 2 5 81 88 90 997 9 34 55 56 66 79 80 1 2 3 4 5 6 7 8 9 10 11 12 13 (0+13) / 2 = 6 If (array[6] == 80) return 6 Elseif (array[6] > 80) High = 6 -1 Else Low = 6+1 Middle = (low + high)/2 Wanted = 80 array 0 (7+13) / 2 = 10 If (array[10] == 80) return 10 Elseif (array[10] > 80) High = 10 -1 Else Low = 10+1 (7+9) / 2 = 8 If (array[8] == 80) return 8 Elseif (array[8] > 80) High = 8-1 Else Low = 8+1 1 2 3
  • 11. ‫خوارزمية‬Binary Search‫المصفوفة‬ ‫مع‬ banajibreel111@gmail.com11 2 5 81 88 90 997 9 34 55 56 66 79 80 1 2 3 4 5 6 7 8 9 10 11 12 13 Middle = (low + high)/2 Wanted = 80 array 0 (7+9) / 2 = 8 If (array[8] == 80) return 8 Elseif (array[8] > 80) High = 8-1 Else Low = 8+1 3 (9+9) / 2 = 9 If (array[9] == 80) return 8 Elseif (array[9] > 80) High = 9-1 Else Low = 9+1 4 return 8
  • 12. ‫خوارزمية‬Binary Search‫المصفوفة‬ ‫مع‬ banajibreel111@gmail.com12 class BinarySearch { // Returns index of x if it is present in arr[], // else return -1 int binarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r-l)/2; // Check if x is present at mid if (arr[m] == x) return m; // If x greater, ignore left half if (arr[m] < x) l = m + 1; // If x is smaller, ignore right half else r = m - 1;
  • 13. } // if we reach here, then element was // not present return -1; } // Driver method to test above public static void main(String args[]) { BinarySearch ob = new BinarySearch(); int arr[] = {2, 3, 4, 10, 40}; int n = arr.length; int x = 0; int result = ob.binarySearch(arr, x); if (result == -1) System.out.println("Element not present"); else System.out.println("Element found at " + "index " + result); } } banajibreel111@gmail.com 13
  • 14. ‫؟‬ ‫أفضل‬ ‫أيهما‬ •‫خير‬ ‫ا‬ ‫مين‬ ‫أفضيل‬ ‫أحيدمما‬ َّ‫بيَّن‬ ‫مطلقياا‬ ‫الحكي‬ ‫يمكن‬ ‫ال‬,‫وا‬ ‫كيل‬ ‫بيل‬‫حيد‬ ‫حاالت‬ ‫في‬ ‫خر‬ ‫ا‬ ‫من‬ ‫أفضل‬ ‫منهما‬,‫يلي‬ ‫كما‬ ‫التوضيح‬ ‫و‬/ ‫مرتبا‬ ‫و‬ ‫كبيرة‬ ‫فيها‬ ‫البحث‬ ‫نود‬ ‫التي‬ ‫البيانات‬ ‫كمية‬ ‫تكون‬ ‫عندما‬‫ما‬ ‫بترتيب‬ ‫ة‬, ‫أفضل‬ ‫الثنائي‬ ‫البحث‬ ‫خوارزمية‬ ‫تعتبر‬ ‫الحالة‬ ‫ه‬ ‫م‬ ‫في‬,‫فنه‬ ‫لك‬ ‫و‬‫ه‬ ‫مي‬ ‫فيي‬ ‫ا‬ ‫يدم‬‫ي‬‫عن‬ ‫ير‬‫ي‬‫العناد‬ ‫ين‬‫ي‬‫م‬ ‫ير‬‫ي‬‫كبي‬ ‫يدد‬‫ي‬‫ع‬ ‫يي‬‫ي‬‫ف‬ ‫يث‬‫ي‬‫البح‬ ‫ياء‬‫ي‬‫عن‬ ‫يا‬‫ي‬‫علين‬ ‫يتوفر‬‫ي‬‫س‬ ‫ية‬‫ي‬‫الحال‬‫يتي‬‫ي‬‫ي‬ ‫ا‬ ‫الشرط‬ ‫على‬ ً‫ء‬‫بنا‬ ‫تظامله‬. ‫مرتبياة‬ ‫غيير‬ ‫و‬ ‫ديغيرة‬ ‫البيانيات‬ ‫كميية‬ ‫تكيون‬ ‫عندما‬,‫ت‬ ‫الحالية‬ ‫ه‬ ‫مي‬ ‫فيي‬‫عتبير‬ ‫أفضييل‬ ‫المتسلسييل‬ ‫البحييث‬ ‫خوارزمييية‬,‫غييي‬ ‫و‬ ‫دييغير‬ ‫العناديير‬ ‫عييدد‬ ‫فن‬‫ر‬ ‫مرتب‬,‫مبا‬ ‫الثنيائي‬ ‫البحيث‬ ‫اسيتخداي‬ ‫نستطيع‬ ‫ال‬ ‫فإننا‬ ‫بالتالي‬ ‫و‬‫شيرة‬,‫لك‬ ‫كي‬ ‫و‬ ‫المقارنات‬ ‫من‬ ‫قليل‬ ‫لعدد‬ ‫سنحتاا‬ ‫أننا‬ ‫يعني‬ ‫الدغير‬ ‫العنادر‬ ‫عدد‬. banajibreel111@gmail.com14
  • 15. ‫مع‬ ‫البحث‬ ‫و‬ ‫الترتيب‬ArrayList!! •‫دن‬ ‫يمتلك‬ArrayList‫عنها‬ ‫الحديث‬ ‫سبق‬ ‫التي‬ ‫الدوال‬ ‫من‬ ‫العديد‬, ‫دالتي‬ ‫الدوال‬ ‫ه‬ ‫م‬ ‫من‬ ‫و‬Sort‫و‬BinarySerach. •‫دالة‬ ‫تقوي‬Sort‫االفتراض‬ ‫المقارنة‬ ‫خلل‬ ‫من‬ ‫وفة‬ ‫المد‬ ‫بترتيب‬‫ية‬ (‫التساوي‬)‫للدالة‬ ‫أنت‬ ‫تعطيها‬ ‫مقارنة‬ ‫خلل‬ ‫من‬ ‫أو‬. •‫دالة‬ ‫تقوي‬BinarySearch‫م‬ ‫عندر‬ ‫عن‬ ‫وفة‬ ‫المد‬ ‫ضمن‬ ‫بالبحث‬‫ا‬ ‫ك‬ ‫إن‬ ‫موضعه‬ ‫رقي‬ ‫تعيد‬ ‫و‬ ‫الثنائي‬ ‫البحث‬ ‫خوارزمية‬ ‫باستخداي‬‫ان‬ ‫سالبة‬ ‫قيمة‬ ‫تعيد‬ ‫إال‬ ‫و‬ ‫موظودا‬,‫بترتي‬ ‫اتها‬ ‫الدالة‬ ‫تقوي‬ ‫حيث‬‫ب‬ ‫الثنائي‬ ‫البحث‬ ‫تتطبق‬ ‫ثي‬ ‫تداعديا‬ ‫ترتيبا‬ ‫العنادر‬. banajibreel111@gmail.com 15
  • 16. ‫مع‬ ‫البحث‬ ‫و‬ ‫الترتيب‬ArrayList!! banajibreel111@gmail.com16 1.import java.util.*; 2.class TestCollection1{ 3. public static void main(String args[]){ 4. ArrayList<String> list=new ArrayList<String>(); 5.//Creating arraylist 6. list.add("Ravi");//Adding object in arraylist 7. list.add("Vijay"); 8. list.add("Ravi"); 9. list.add("Ajay"); 10. //Traversing list through Iterator 11. Iterator itr=list.iterator(); 12. while(itr.hasNext()){ 13. System.out.println(itr.next()); 14. } 15. } 16.}
  • 17. ‫أشكركم‬ banajibreel111@gmail.com17 ‫كلها‬ ‫للعلوم‬ ‫مفتاح‬ ‫السؤال‬... ‫بيااة‬ ‫الظا‬ ‫قوانين‬ ‫إلى‬ ‫ودل‬ ‫احاة‬ ‫الت‬ ‫وقعت‬ ‫ا‬ ‫لما‬ ‫سَّل‬ ‫عندما‬ ‫نيوتن‬ ‫أن‬ ‫كر‬ ‫ت‬...