Questions tagged [binary-search]

The tag has no usage guidance.

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

pset3 binary search , shows errors in check50

i don't understand acc. to the algorithm it should work correctly , but it doesn't
0
votes
2answers
54 views

binary search pset 3 pointer to integer error

I am trying my hands on binary search. I get those pointer to integer errors :( Can sonmeone more experience give me a hand ? bool search(int value, int values[], int n) { int first=0; int last=n-1; ...
0
votes
1answer
331 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
1answer
81 views

Recursive Binary Search Exit Code Errors

I wrote the following recursive binary search function. No matter which exit codes I use (e.g., true, false, 1, 0, -1, "Swedish Chef"), I fail at least two of the checks I need to pass. The code ...
0
votes
1answer
97 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
1answer
172 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
1answer
190 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
1answer
78 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
2answers
362 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
1answer
139 views

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

string book[] = { "Chen", "Kernighan", "Leitner", "Lewis", "Malan", "Muller", "Seltzer", "Shieber", "Smith" } int main(...
2
votes
2answers
119 views

how effective would it have been to use an array for the dictionary?

I just completed pset5 using a trie, but I'm curious about other methods. How effective would it have been to load the dictionary into an array and then use a binary search function to locate words ...
0
votes
1answer
24 views

Code won't progress unless user inputs a number

I was writing a binary search function before finishing lecture 3 because I wanted to do some practice on my own. I was using scanf, which I had looked up, as I wanted to learn how to code without the ...
0
votes
1answer
31 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
1answer
75 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
1answer
43 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
2answers
239 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
1answer
69 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
0answers
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
1answer
34 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
1answer
59 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
1answer
417 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
2answers
63 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
2answers
157 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
1answer
104 views

PSET3 Binary Search Function Infinite Loop

When I try running find.c inputting: ./generate 1000 50 | ./find 127 it should return that the value (127) was found, however when I do it with my code, it seems to create an infinite loop. Also, ...
0
votes
2answers
183 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
2answers
110 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
2answers
103 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
0answers
50 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
1answer
73 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
1answer
98 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 ...
1
vote
1answer
13k views

Question about binary search. Please help!

https://www.youtube.com/watch?v=5xlIPT1FRcA&t=200s I am struggling to understand how to implement binary search. According to the video, there are 14 numbers in the array. Then he goes on to ...
0
votes
1answer
140 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
1answer
665 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
2answers
29 views

C: Binary Search searches and finds but incorrect exit code

This code is finding all the numbers correctly. Only problem is it's throwing error of "\ expected an exit code of 1, not 0" when the number is not present. Help would be appreciated. bool search(int ...
0
votes
1answer
28 views

Advice re: Binary search - various issues

I need advice as to what to change in this code to make it work. I am new at this so I need specifics, please. Please, no opinions on whether it's trash or what mark you would give if grading it. That ...
1
vote
2answers
36 views

C: Pset 3: Binary Search - 'expected an exit code of 0, not 1' (not finding n)

This is an attempt at binary search. n is the user input (from main script). This code compiles but doesn't find the needle in the haystack. I'm a bit lost and would welcome assistance. bool ...
0
votes
1answer
47 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
1answer
94 views

Pset 3: Find (more comfortable) - child exited with status 255 & exits with wrong code

I ambitiously decided to try the more comfortable version of this task, although I'm very much "less comfortable" with regard to any computer skills... Before I give up, I'd like to ask you what's ...
0
votes
0answers
214 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
1answer
93 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
1answer
35 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
1answer
47 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
1answer
97 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
1answer
161 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
1answer
26 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
1answer
75 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
1answer
89 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
1answer
51 views

binary search algorithm

Many sources say that you need to put "int l = n" the element next to last instead of "int l = n - 1"(int f = 0; int l = n - 1; int mid;) in my example. I am not sure why? Moreover it seems my code ...
1
vote
2answers
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
2answers
88 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" /** * ...