3

In Big O notation and Omega notation the constants are not computed. Say you have an array with 1000 places. It's not that different to say 1000 than 999. So the n-1 becomes n. Also let's say that you have to traverse an array, that is to read all of its elements. If the array is 1000 places, ti has an Ω(1000), but we still say that it is constant time as Ω(...


2

My sincere recommendation is ... start again. You have two nested loops, each time the DO-WHILE loop begins, the min and max values are set to zero, as the end-of-cycle condition for while is values[min] > values[max] can occur at any time or never happen, so we can have an infinite loop, also you are changing the values of the array itself so that your ...


2

you're defining repeater twice, once outside of the do..while loop and the other one is inside. the one defined inside shadows the one defined outside in the scope of the body of do. the one defined inside also goes out of scope as the closing brace of the do is reached. the one while (repeater > 0) sees is actually the one declared outside which ...


2

You have such a little mistake, but that mistake ruins all your work. Look here: tmp = values[i]; values[i] = values[i+1]; values[i] = tmp; The last line values[i] = tmp should be values[i+1] = tmp if you want to switch those two variables. I'm sure you knew this and this is just a typo. I don't know why was your question downvoted. To me in looks like a ...


2

why do you use int* array[n]; and not int array[n];? you aren't calling your sort() function.


2

preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i+1].winner][pairs[i+1].loser] This condition swaps the elements in ascending order while check50 checks for the pairs array for descending order.


2

When evaluating time complexity, it's about order of magnitude estimates, not exact precision. For this reason, n - c, where c is a constant, are generally treated the same It's the order of magnitude that counts, so n, n-1, n-2,...,n-c are all treated as being n for purposes of estimation of time complexity. Take it further. n * (n-1) evaluates to n^2 or ...


1

You never update m or k, so the loop will go on. Move the l = (m + k) / 2; into the loop. And instead of calculating a different l in your actions, change m or k, and let l re-calculate on next iteration. Your condition in while matches a version where you initialise k to n-1, not n.


1

There are two problems with the code. Both are truncating the sort prematurely. First, the inner loop is being wound down too fast by incrementing k within the loop. It should not be decremented within the inner loop. Instead, try using j. Second, you are testing whether a swap has occurred within the inner loop. If the first two elements are in order, ...


1

The var swaps is used to detect whether any swaps occur, not to control whether the code displayed on the screen is allowed to run. Here's how it works. You want to know if any swaps ever occur. At the beginning, you set int swaps = 0; because so far, there have been no swaps. If at the end, it is still 0, then it means that no swaps were made and the ...


1

Your search function never returns true. Ever. if (value == values[m]) { return 0; } return 0 is the same as return false. It should be return 1 or return true.


1

you have this problem because you are storing this large number in an integer variable. You should use some other data type for such large values like long int or long long int, which can store the values you want to sort. I hope this helps, please mind my english as it is not my primary language. Feel free to ask in case of any doubt in my answer. Please ...


1

To review, the bubble sort TODOs (according to the less-comfortable walkthrough) are as follows: iterate over list compare adjacent elements swap elements in the wrong order largest elements will 'bubble' to the end the list is sorted once no elements have been swapped The bubble sort pseudocode according to the Bubble Sort Short is: ...


1

void sort(int values[], int n) { void bubble(int values[], int n); } Here you just declare bubble function, but don't call it. Strange that you do not get an error like "unused parameter" while compiling. Try this: void sort(int values[], int n) { void bubble(int values[], int n); bubble (values,n); } and you do not lose this last element, ...


1

Much better now. Your Binsearch works fine, but sort doesn't. Segmentation fault comes from here values[i+1] = values[max] As max is a value in haystack, not an index of haystack[]; Correct it and segmentation fault should disappear. But there is another mistake that would prevent your sort from working as it should. for() loop is designed to "blindly" ...


1

You have two problems here: First is that your sort function does not sort. Just look here, for example: if ((n<i+1) && (n>1)) This condition will NEVER be true as you loop for i < n. There are also other deficiencies. To correct all I just need to put the whole correct code for sort here, that is against the rules. I would advise you to ...


1

In your swap part, you assign to values[j] twice, second should be values[j+1]


1

You have two problems with the last element, or the one just behind the array. In code for(i = 0; i < n && no_swap == false; i++) { no_swap = true; for(j = 0; j < n - i; j++) { if (values[j] > values[j + 1]) { tmp = values[j]; values[j] = values[j + 1]; values[...


1

First of all the do{} while loop and the sorted variable are redundant, you should remove them. Then, the for loops aren't properly initialized. What they should do is for i decreasing from n to 1 for j increasing from 0 to i if... Well that's just one way of phrasing it, there are others too. What your code does is for i increasing from 0 ...


1

The simple approach works. Just before the return, create a for loop and print out the array in order. Having said that, your sort isn't working. You do a great job of swapping j and k. The problem is that you need to swap values[j] and values[k]. Also, since k always equals j+1, you could simply use j+1 instead. If this answers your question, please ...


1

The problem here is that the code only makes one pass through the list. It will bubble the largest element to the end of the list, but then stops. It needs to come back to the beginning and repeat the process to sort the next largest item up, and again for the 3rd largest, 4th, 5th, etc. If this answers your question, please click on the check mark to ...


1

The condition for your for loop to begin running is that swab != true. However, when you initialized swab at the beginning of the value, you set its value to true. Under those conditions, the loop will never begin.


1

the answer is definitely to use the correct format specifier for a value of type int.


1

You have a single for loop in your bubble sort. This will have the effect of moving only the single largest element to the end of the list, but it will stop there. The second and third largest elements (and so on) may get moved, but won't necessarily get fully sorted. You need a second for loop surrounding it to repeat the process over and over until you ...


1

I am sorry this pset has been such a struggle for you. I think you are really close to the finish line. Take a deep breath and let's go through this step by step. The most important thing is that you do not lose the code you have worked so hard on. The plan: Backup your work. There is no such thing as too much backup. Restore Makefile, find.c and helpers....


Only top voted, non community-wiki answers of a minimum length are eligible