Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
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
0 votes
1 answer
199 views

Trouble with binary search

Using gdb, I found the problem is when the left_values is not there because if I try print left_values right after declaring it, it tells me No symbol "left_values" in current context. after ...
0 votes
1 answer
82 views

binarysearch no errors from compiler, but only spews out gibberish , anyone got an idea?

To make it more readable i thought this time i will just post the link to my helpers.file. The bubblesort worked and the linary search before too. Maybe i did something wrong in the implementation of ...
0 votes
2 answers
367 views

Binary search algorithm only works for smaller arrays

I can't figure out what I'm doing wrong. My algorithm works for smaller arrays, but once the number of values increases, the program stops and I have to hit Ctrl + C. I thought maybe it was an issue ...
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
1 vote
2 answers
4k views

Pset3 Binary Search problems

I have tested the code presented in the picture and find this function always returns false no matter what number you search.There must be a problem in it but I can not see it!! Can anyone help me ? ...
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, ...
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(...
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 ...
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] ...
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" /...
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] < ...
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 ...
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) { ...
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 ...
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 ...
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=...
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'...
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+...
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 ...
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 ...
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 ...
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 ./...
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 ...
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 ...
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 ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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 &...
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 ...
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 ...
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 ...
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 ...
0 votes
2 answers
89 views

My binary sort function cannot find the needle in the haystack. Can anyone see the bug in this code?

I am testing by using ./generate 1000 50 | ./find 127. The needle should be found but isn't. #include <stdio.h> #include <cs50.h> #include <string.h> #include "helpers.h" /** * ...
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 ...
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 ...
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 ...
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 ...
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 ...
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] ...
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 ...
0 votes
1 answer
42 views

Array Initialization Problems

I am getting this error from my code: helpers.c:56:28: error: expected expression binsearch(value, values[], j, n, end); Here is the code in question: binsearch(value, values[], j, n, end); ...
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 ...
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 ...
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 ...