Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
152 views

Purpose of sizeof(book)/sizeof(string) in lectures' binary sort?

string book[] = { "Chen", "Kernighan", "Leitner", "Lewis", "Malan", "Muller", "Seltzer", "Shieber", "Smith" } int main(...
Davis's user avatar
  • 144
0 votes
1 answer
38 views

find problem with my code - CPU overload

I cannot figure out what is wrong with my code. /** * Returns true if value is in array of n values, else false. */ bool search(int value, int values[], int n) { // ensures that the n is non ...
koko loko's user avatar
0 votes
1 answer
118 views

pset3 find less comfortable if else expression result unused

I do not understand why I get an errors: error: expected ';' after expression else (value > values[l]) and helpers.c:40:21: error: expression result unused [-Werror,-Wunused-value] ...
koko loko's user avatar
0 votes
1 answer
57 views

CS 50 - pset3 find helpers: Why do binary search and selection short not work?

the command line yells at me but I cannot find out why. Any ideas what could be wrong? Here is my code: /** * helpers.c * * Helper functions for Problem Set 3. */ include include "helpers.h" /...
AlexL's user avatar
  • 5
0 votes
2 answers
246 views

PSET3 find having trouble. Can someone help?

For some reason bubble sort is not working. Can someone help. binary search bool search (int target, int array[],int length) { int end = length-1; int start = 0; while (array[start] < ...
user20243's user avatar
0 votes
1 answer
72 views

pset3: sort and search work in separate files, but my helpers.c doesn't work

I dealt with sorting in a separate file first, and then I dealt with searching in another file. They seem to work okay or at least worked for the numbers I feed in, but when I put them in helpers and ...
Chris's user avatar
  • 19
0 votes
0 answers
26 views

For pset3 binary search will this code work?

Here is the code . bool binary_search (int target, int array[],int length) { int end = length-1; int start = 0; while ( array[end_num]- array[start_num] > 0) { ...
Tom55555's user avatar
0 votes
1 answer
35 views

do I need recurson for binary search?

Also do I need recursion for any of the pset3 solutions? If yes any good sources on recursion. There was a quick example in lecture 3. Will that suffice? Preferably a video. I realize I could just ...
Tom55555's user avatar
0 votes
1 answer
68 views

Find.c - Binary Search probable integer overflow

Here's the gist: https://gist.github.com/Securiteru/a83e4f1a028acd0b1013def793b5dcdc And the output: ... 60697 61151 61190 61275 61460 61608 61618 61746 61750 61822 62111 62178 62183 62311 62448 ...
Securiter's user avatar
0 votes
1 answer
419 views

Pset3, Find, search

In "Find" problem, something seems wrong with my binary search Algorithm, because in check50, helpers.c wouldn't compile, I tried to compile it, then it gave me this weird error: clang -fsanitize=...
Raw's user avatar
  • 9
0 votes
2 answers
66 views

pset 3 binary search help

I am working on pset 3 for cs50 on edx, and I'm having quite a bit of trouble with the binary search problem. My program worked fine when I tested it with a linear search (so I think the problem isn'...
ParzivalBlade's user avatar
0 votes
2 answers
193 views

Pset3 helpers.c

i'm stuck in binary search. Check50 doesn't pass all the checks and it doesn't find the needle, I feel like the algorithm i have implemented is correct but it doesn't work. I've been stuck in this for ...
Ishark Felician's user avatar
0 votes
2 answers
163 views

Binary Search for helpers.c

so as the title suggests I am having some trouble with my implementation of binary search. So based on the logic shown in the lecture, I think my implementation is fine, indeed it works for the cases ...
Anza Khan's user avatar
1 vote
2 answers
104 views

Binary Search Pset 3 help

As my question is titled, I would appreciate help with my binary search, shown below. Currently, the search will always return false. I am almost certain that my sorting algorithm is correct, as it ...
Jason_V's user avatar
  • 182
0 votes
2 answers
161 views

Segmentation Fault pset3 for Find

I'm getting a segmentation fault error and I can't figure out why. void sort(int values[], int n) { // TODO: implement a sorting algorithm for (int i = 0; i<n; i++) { if ((n!=i+...
Alex Durante's user avatar
0 votes
0 answers
51 views

Result doesn't match expected output

I just finished the helpers.c pset, where you have to implement a counting sort and then a binary search. I havent made it recursive yet but it works in all of my own test cases. I also ran the ./...
Tod Lazarov's user avatar
0 votes
1 answer
76 views

pset3: search (am I in the right track??)

bool search(int value, int values[], int n) //search for middle lists if (value == values [n / 2]) { return 1; } //number greater search left else if ( value > values[n / 2 ]) { search(int ...
RedRabbit's user avatar
0 votes
1 answer
109 views

Pset 3 Recursive Binary Search problems - Always returns true

I have tried almost everything and edited my code a hundred times in search of an answer. It seems that whenever I run the program (find.c) the result always resolves to true. Not sure where the ...
Mo Amer's user avatar
0 votes
1 answer
680 views

cs50x pset3 find - Need help with the counting sort

can someone please look at my code and tell me where I went wrong with my counting sort algorithm (Or binary search algorithm, if that's where the problem lies...?). Please and thank you. Binary ...
Milad's user avatar
  • 7
0 votes
1 answer
59 views

please help me with this binary search

for some reason this binary search code keeps returning true, when providing the haystack from generate.c, even if the "needle" isnt there. when manually inputing the haystack, the code runs perfectly....
David Rosenberg's user avatar
0 votes
0 answers
218 views

PSET3 \ expected an exit code of 0, not 1 (find.c)

I successfully built my program and went on to check it using check50 only to discover this :) helpers.c exists :) helpers.c compiles :) finds 42 in {42,43,44} :) finds 42 in {41,42,43} :) finds 42 ...
Ubuntu NutCracker's user avatar
0 votes
1 answer
95 views

Pset3 Find - Not sure what is wrong with helpers.c code

I am not sure what is wrong with the code. It seems to work on some of the criteria when using cs50's check50, but does not work on others. There also does not seem to have a pattern about the wrong ...
KayZee's user avatar
  • 3
0 votes
1 answer
39 views

Recursive function problem - return value

I am getting the following error below. It has to do with my binarySearch function. helpers.c:149:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ However I have a ...
Salamit's user avatar
  • 231
0 votes
1 answer
48 views

Pset3 helpers.c while loop exiting unexpectedly

I am trying to implement a binary search algorithm. However, my while loop isn't working as expected. Having used printf and debug50 with a list of 100 numbers, it seems that the while loop only gets ...
An_antelope's user avatar
0 votes
1 answer
103 views

Binary Search pset3

bool search(int value, int values[], int n) { int found = 0; int notfound = 0; int minindex = 0; int maxindex = n; int midindex = 0; do { midindex = (minindex + maxindex) / 2; if (minindex &...
helprequest's user avatar
0 votes
1 answer
340 views

PSet 3, binary search implementation

I'm struggling with implementation of binary search in PSet 3, and my code can't quite get past check50. Here's my code: bool search(int value, int values[], int n) { // TODO: implement a ...
Athena's user avatar
  • 1
0 votes
1 answer
168 views

helpers.c passes check50 but fails ./generate 1000 50 | ./find 128

check50 gives me all smiles, but when I run the test code ./generate 1000 50 | ./find 127 or 128 they both return "Found needle in haystack". How is that possible? And also, can I be sure my code is ...
Lele's user avatar
  • 67
0 votes
1 answer
55 views

pset3 binary search , shows errors in check50

i don't understand acc. to the algorithm it should work correctly , but it doesn't
Ketan Verma's user avatar
0 votes
1 answer
101 views

pset3 binary search , problems with check50

i have tried a lot but cannot find the meaning of the last two errors of check50 please help
Ketan Verma's user avatar
0 votes
1 answer
32 views

pset3: When testing binary search code, how do I print when needle is found?

I would like to test if my binary search function is working correctly. I have created an array that is passed into a working bubble sort function. Printing the sorted array works just fine, all I ...
Kgotso Koete's user avatar
0 votes
1 answer
81 views

Pset3 recursive binary search function - check50 gives me four :( and I don't know why

I would be really grateful if someone could offer me a hint as to where I'm going wrong with this - I've been stuck for a couple of days now. When I work through the code step by step on paper it ...
J M COOPER's user avatar
0 votes
1 answer
50 views

return -1 does not end function execution

This is my code. 65 int BinarySearch(int key, int array[], int min, int max) 66 { 67 int mid; 68 69 if (max < min) 70 { 71 return -1; 72 } 73 else 74 ...
Alexis's user avatar
  • 25
0 votes
1 answer
167 views

How do I set a pointer to access the left half of an array? [PSET 3 - Binary search]

I'm having trouble accessing only the left half of an array, doing the same for the right half works fine for now, at least I'm not getting any errors. I figured accessing the array using pointers ...
Martin Kleiven's user avatar
0 votes
1 answer
178 views

Segmentation fault in find.c

I've been working on find.c for a long time now and I've managed to get to the point where it will return the correct output when the needle is in the haystack, but when it isn't I get a segmentation ...
Danielle R's user avatar
0 votes
2 answers
73 views

find.c compiles but fails check50 - I believe binary search is to blame

Why does my code fail check50? This is the code of my binary search. I know it's buggy, and I spent the last hours reading answers to similar questions, the information I found doesn't quite cut it ...
Iury Sikorsky's user avatar
0 votes
1 answer
105 views

Check50 is claiming that it's recieving an exit code of 0 rather than 1 (different scenario)

I know this question has been answered before (pset 3 "search": expected an exit code of 0, not 1), but I took a look at it, and it seems that the scenario in which the person asked the ...
jayfeather31's user avatar
0 votes
1 answer
308 views

Stuck in loop on Binary Search

I have some problems with my Binary search and would greatly apprecaite help in this. I've debugged it and it seems that my "mid" variable doesn't change. As such, if "value" doesn't equal value[mid] ...
Domoman's user avatar
0 votes
1 answer
576 views

Pset 3 - Binary Search - clang: error: linker command failed with exit code 1

When I compile, with "make find", the following code: I get: So, if I'm interpreting this correctly, there's an undefined reference to search on line 58 of find.c, which is -- if (search(needle, ...
cignal's user avatar
  • 15
0 votes
1 answer
42 views

why doesn't my implementation to binary search correctly handle not finding an element?

I was practicing to write the code for binary search after watching its short, before starting on pset3. The code that I wrote asks for the length of array, then sorts it and asks for the number to ...
Furrukh Jamal's user avatar
0 votes
1 answer
325 views

Need help with recursive binary search

Here is my helpers.c file, I have been scouring the message boards and nothing is making sense. I use the pset3 input of ./generate 1000 50 | ./find 127. I get a Didn't find needle in haystack ...
Ian Sullivan's user avatar
0 votes
1 answer
148 views

check50 fails to compile helpers.c - throws implicit function declaration error

I put my recursive binary search function prototype inside helpers.h file, and the function definition inside helpers.c file. (search calls binarysearch) This decision caused compilation failure of ...
Pooja's user avatar
  • 139
0 votes
1 answer
143 views

Odd bug for Find

I've been working of the find (problem set 3) for 2 weeks and I'm just stuck. I already have the design etc worked out but there is a bug that I seem to be missing. So the problem is that when I run ...
Caffae's user avatar
  • 1
0 votes
2 answers
62 views

Error with Check50 on Binary search

I have some problems with Binary search. Check50 works fine for every case except this one: :( finds 42 in {42,43,44} \ expected an exit code of 0, not 1 I got no clue why this happens :( I ...
Jerez's user avatar
  • 3
0 votes
1 answer
270 views

Having trouble with pset3 helpers.c binary search

bool search(int value, int values[], int n) { int midpoint = n / 2; int startpoint = 0; int endpoint = n - 1; // if the midpoint doesn't equal the vales we're looking for, repeat this ...
Russell C.'s user avatar
0 votes
1 answer
411 views

Bug in my Pset3 Binary Search helpers.c

When I run check50 check50 2015.fall.pset3.find helpers.c This is the terminal result :) helpers.c exists :) helpers.c compiles :( finds 42 in {42,43,44} \ expected an exit code of 0, not 1 :) ...
Kazaky's user avatar
  • 3
0 votes
1 answer
33 views

Do While loop not executing for pset3

I am working on Pset3 for a binary search algorithm. Below is my code (NOTE: the logic is not finished): bool search(int value, int values[], int n) { //binary search algorithm int min = 0; int max = ...
jaguar's user avatar
  • 70
0 votes
1 answer
91 views

What's wrong with my binary search code?

I thought I got everything right but when I checked my code with check50 it shows the following errors: :( finds 42 in {42,43,44} \ killed by server :( finds 42 in {40,41,42} \ expected an ...
Kiwi's user avatar
  • 179
0 votes
1 answer
63 views

Recursive find.c - not returning

The following code will enter an endless loop when my needle is 1 and my haystack consists of the array [1,2,3]. /** * Returns true if value is in array of n values, else false. */ bool search(int ...
Brendan Rafferty's user avatar
0 votes
1 answer
167 views

Pset3 - Function returns both true and false in while loop

In my code, after successfully searching the element, the function is returning true and false both to the main function. I have questions as follows -> 1 - Why the sm() function is returning true ...
Priyanshu Kumawat's user avatar
0 votes
1 answer
116 views

pset3 Control reaches end of non void function

I don't know where I'm wrong in my binary search and compiler is showing me this error in both functions. Can you help me find out where I'm getting wrong. bool s(int key, int elm[], int low , int ...
Priyanshu Kumawat's user avatar