return ____________________________; }
bool isPalindrome(const char * const s) {
return isPalindrome(s, 0, strlen(s) - 1); }
A) isPalindrome(s, low, high) B) isPalindrome(s, low + 1, high)
C) isPalindrome(s, low, high - 1) D) isPalindrome(s, low + 1, high - 1)
12. Agarda “Xanoy minorasi” masalasida 3 xalqadan iborat bo`lsa rekursya yordamida disklarni ko`cherish jarayoni necha bora amalga oshadi?
A) 3 B) 7 C) 10 D) 14
13. Agarda “Xanoy minorasi” masalasida 4 xalqadan iborat bo`lsa rekursya yordamida disklarni ko`cherish jarayoni necha bora amalga oshadi?
A) 5 B) 10 C) 15 D) 20
14. Quyidagi ikkita kodi qanday natijani chop etadi?.
A:
void xFunction(int length)
{ if (length > 1) {
cout << (length - 1) << " ";
xFunction(length - 1);} }
int main() {
xFunction(5);}
B:
public static void xFunction(int length) {
while (length > 1) {
cout << (length - 1) << " ";
xFunction(length - 1); } }
int main() {
xFunction(5); }
A )Ikki dastur bir xil natija beradi: 5 4 3 2 1.
B) Ikki dastur bir xil natijani beradi, ya'ni 1 2 3 4 5.
C)Ikki dastur bir xil natijani beradi 4 3 2 1.
D) Ikki dastur bir xil natijani beradi 1 2 3 4.
E) A dastur 4 3 2 1 natijani va B dastur 4 3 2 1 natijani chop etadi.
15.Quyidagi javoblardan qaysi biri to`g`ri?
A) Rekursiv funksiya rekursiv bo`lmagan funksiyaga qaraganda yaxshiroq ishlaydi.
B) Odatda rekursiv funksiya rekursiv bo`lmagan funksiyaga nisbatan ko`proq xotiradan joy oladi
C)Rekursiv funksiya rekursiv bo`lmagan funksiyaganing o`rnini bosishi mumkin.
D) Ayrim hollarda bizga qo`yilgan murakkab masalalarni rekursiya yordamida oson yechimini topishga yordam beradi.
16. Quyidagi dastur satrni saralash uchun dasturda tushirib qoldirilgan satrni to`ldiring.
void sort(char list[], int high)
{ if (high > 1)
{ int indexOfMax = 0;
char max = list[0];
for (int i = 1; i <= high; i++)
{ if (list[i] > max)
{ max = list[i];
indexOfMax = i; }
} list[indexOfMax] = list[high];
list[high] = max;
sort(list, high - 1); }
} void sort(char list[])
{ ____________________________; }
void sort(double[] list) {
___________________________; }
A) sort(list) B) sort(list, strlen(list))
C) sort(list, strlen(list) - 1) D) sort(list, strlen(list) - 2)
17. Quyidagi dasturda binar qidiruv amalga oshirilishi tushirib qoldirilgan satrini to`ldiring.
int binarySearch(const int list[], int key, int low, int high){
if (low > high)
return -low - 1;
int mid = (low + high) / 2;
if (key < list[mid])
return binarySearch(list, key, low, mid - 1);
else if (key == list[mid])
return mid;
else return binarySearch(list, key, mid + 1, high);}
int binarySearch(const int list[], int key, int size){
int low = 0;
int high = size - 1;
return __________________________; }
A) binarySearch(list, key) B) binarySearch(list, key, low + 1, high - 1)
C) binarySearch(list, key, low - 1, high + 1) D) binarySearch(list, key, low, high)__
Do'stlaringiz bilan baham: |