Back to Browse

GATE 2008CS/IT ALGORITHMS |A code attempt to locate an element using binary search,Code is erroneous

578 views
Premiered Jan 21, 2022
19:31

GATE | GATE CS 2008 | Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous. f(int Y[10], int x) { 2. int i, j, k; i = 0; j = 9; 4. do { k = (i + j) /2; 6. if( Y[k] x) i = k; else j = k; 7. } while(Y[k] != x && i j); 8. if(Y[k] == x) printf ("x is in the array ") ; 9. else printf (" x is not in the array ") ; f(in which of the following contents of Y and x does the program fail? (A) Y is [1 2 3 4 5 6 7 8 9 10] and x 10 (B) Y is [1 3 5 7 9 11 13 15 17 19] and x 1 (C) Y is [2 2 2 2 2 2 2 2 2 2] and x 2 (D) Y is [2 4 6 8 10 12 14 16 18 20] and 2 x 20 and x is even For any queries feel free to comment or direct message on Instagram Instagram - https://www.instagram.com/jatingupta5jan/ Playlist link - C programming - https://www.youtube.com/playlist?list=PLnEHtQ3-a5paHibY82nRWmWOEfYYVXFZ4 Time Complexity - https://www.youtube.com/playlist?list=PLnEHtQ3-a5pY3k4u754YJ_NWMe_6ITHHX Data structure - https://www.youtube.com/playlist?list=PLnEHtQ3-a5pawoiSjUXy25JLpI0k4zQ2l Algorithms - https://www.youtube.com/playlist?list=PLnEHtQ3-a5pYgXnLQ5qN_xKA_vSGQbGr9 Binary tree - https://youtube.com/playlist?list=PLnEHtQ3-a5pYbHh6LzdBGKAKPJCLl_t5z Linked List - https://youtube.com/playlist?list=PLnEHtQ3-a5pYM_kmRl5bwk4CevYJtqQba #Jatin_Gupta_Gate

Download

0 formats

No download links available.

GATE 2008CS/IT ALGORITHMS |A code attempt to locate an element using binary search,Code is erroneous | NatokHD