2012- 5- 16
|
#7
|
|
أكـاديـمـي
|
رد: ^^^^محاضرة searching algorithms 11 وش المهم اللي فيها ^^^^
اقتباس:
المشاركة الأصلية كتبت بواسطة bassmah
>> طيب اشرحوا لي النقاط هذي ::
فكرة عمل الخوارزم ::
كود:
Algorithm
Algorithm is quite simple. It can be done either recursively or iteratively:
1. get the middle element;
2. if the middle element equals to the searched value, the algorithm stops;
3. otherwise, two cases are possible:
o searched value is less, than the middle element. In this case, go to the step 1 for the part of the array, before middle element.
o searched value is greater, than the middle element. In this case, go to the step 1 for the part of the array, after middle element.
|
أهلين بسمه..
فكرة الـــ(Search Algorithms (binary
هي انه عند البحث عن عنصر معين نروح لمنتصف المصفوفه ونسأل هل العنصر اللي نبحث عنه = عنصر المنتصف (middle) إذا يساويه يرجع بالقيمه واذا لا نشوف الرقم أكبر من او اصغر من المنتصف
- اذا كان اصغر نبحث في النصف الاول
- اذا كان اكبر نبحث في النصف اثاني
-واذا كانت القيمة مو موجوده يرجع بــ -1
* طبعا تطلعين منتصف المصفوفه انك تاخذين موقع العنصر الاول =0 + موقع العنصر الاخير =n
وتقسمينهم ع 2
أتمنى اكون افدتك
|
|
|
|
|
|