by

There is one small error in the following flip routine. Find out which line it is on.

void flip(int arr[], int i)
	2	{
	3	      int t, init = 0;
	4	      while (init < i)
	5	      {
	6		    t = arr[init];
	7		    arr[i] = arr[init] ;
	8		    arr[i] = t;
	9		    init++;
	10		    i--;
	11	      }
	12	}

a) Line 3
b) Line 5
c) Line 7
d) Line 9

1 Answer

0 votes
by

Answer: c
Explanation: After initialization of the array titled arr; for each while loop iteration of increasing init, we should make arr[init]=arr[i]. This makes sure that the changes will be made in order to flip the order of the array that was to be flipped. Here in line 7 it has been written in reverse and is incorrect.

Related questions

0 votes
    There is a one line error in the following routine. Find that line. 1. int Max(int a[], int n) 2. { 3. int mi, i; 4. for (mi = 0, ... (a[i] > a[mi]) 6. mi = i; 7. return mi; 8. }...
asked Dec 29, 2022 in Technology by JackTerrance
0 votes
    What is the time complexity for a given pancake sort given it undergoes “n” flip operations? a) O(n) b) O(n2) c) O(n3) d) O(2n)...
asked Dec 28, 2022 in Technology by JackTerrance
0 votes
    When we realize a specific implementation of a pancake algorithm, every move when we find the greatest of the ... b) Exponential functions c) Logarithmic functions d) Permutations...
asked Dec 29, 2022 in Technology by JackTerrance
0 votes
    Pancake Sorting appears in which of the following? a) Frequency Scaling b) Storage Virtualization c) Parallel Processing d) Neural Networking...
asked Dec 28, 2022 in Technology by JackTerrance
0 votes
    Which operation is most essential to the process of pancake sort? a) Flip the given data b) Find the largest of ... least of given data d) Inserting something into the given data...
asked Dec 28, 2022 in Technology by JackTerrance
0 votes
    In a computational complexity theory, a problem with decision making is said to be NP-complete when it is both ... c) Non-deterministic Polynomial time d) Non Probabilistic time...
asked Dec 29, 2022 in Technology by JackTerrance
0 votes
    How many flips does the simplest of pancake sorting techniques require? a) 3n−3 flips b) 2n-4 flips c) 2n-3 flips d) 3n-2 flips...
asked Dec 28, 2022 in Technology by JackTerrance
0 votes
0 votes
    So the scenario is the following: I have multiple instances of a web service that writes a blob of data to ... other unknown issues? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    Which of the following model model include a backwards elimination feature selection routine? (a) MCV (b) MARS ... and answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    Which of the following model model include a backwards elimination feature selection routine? (a) MCV (b) MARS (c) MCRS (d) All of the mentioned...
asked Oct 7, 2021 in Technology by JackTerrance
0 votes
    Suppose that while writing the R code that consists of multiple functions. While executing the code, there is an error ... you use to find the function that is facing problem?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    Which one of the following principles of cyber security refers that the security mechanism must be as small and ... Economy of the Mechanism Least privilege Fail-safe Defaults...
asked Mar 6, 2021 in Technology by JackTerrance
0 votes
    Simran write a code print: (“hello friends”)but when she executed there comes an error what was the error and why did it occur Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
...