Questions tagged [binary-search]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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 ...
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 ? ...
1
vote
1answer
163 views

pset3 - recursive binary search not compiling

I wrote a recursive function for binary search in pset" and I keep getting the same error from clang: "control may reach end on non-void function" it is driving me crazy... some help would be very ...
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 ...
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 ...
1
vote
2answers
206 views

Binary Search Problems

When attempting to implement binary search, I have run into problems when compiling. If you see any problems in sort, please point them out as well. Any help would be appreciated. Here are the errors: ...
1
vote
1answer
180 views

Pset3, After haystack values typed, just blank on the Command line

I am almost done with my Binary Search and yet when I test it, it does this strange thing. I run ./find (some number) and it prints out the haystack[] values one by one as I enter numbers for those, ...
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
2answers
675 views

What's wrong with this binary search implemented using recursion?

This is pset3 and I've tried making it work for numerous hours. It always returns false whether the 'needle' is found in the 'haystack' of arrays or not. When typing this in the command window: ./...
0
votes
1answer
901 views

Implementation of Search Function

I am having trouble understanding why the bool search function is working the way it does. I had gone through the Section for Week 3. While I understand the logic of binary search, I don't understand ...
0
votes
1answer
72 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
1answer
272 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
1answer
319 views

Pset3: Helpers.c Binary Search Fails on checks that have 42 entered last

For some reason my implementation of binary search for Pset3 fails to work correctly whenever the last number added to the "haystack" is 42. During use of GDB, I found that this is due to the part of ...
0
votes
1answer
764 views

Pset3 Segmentation Fault

Where is the segmentation fault occurring in this program? Thanks! /** * helpers.c * * Computer Science 50 * Problem Set 3 * * Helper functions for Problem Set 3. */ #include <cs50.h> #...
0
votes
1answer
579 views

Pset3 Search/Find problems

I have no idea what the problems are with this code, so any help would be appreciated. The code compiles, but the output is skewed. It only sorts after a certain amount of characters, and then sorts ...
0
votes
3answers
622 views

pset 3 binary search

I know the logic behind binary search is simple but my code isn't compiling. I went along the lines of week 3's section. I am still getting compilation errors. int beginning = 0; int ending = n - 1; ...
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
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 ...
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
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
44 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
2answers
67 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
1answer
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 = ...
0
votes
1answer
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 ...
0
votes
1answer
142 views

pset3 Binary search error message : Control may reach end of non-void function

can someone help me figure out what's wrong with this piece of code? I keep getting this error Control may reach end of non-void function. I can avoid this compilation error by adding a return value (...
0
votes
1answer
523 views

Slice a list for recursive function in pset3 search

I'm using a recursive function for pset3's binary search. How do you call the same function again giving half the list as an argument?
0
votes
1answer
102 views

Is it okay to check my code against a reference book?

Alright, so I've been having trouble making binary search (I think I either made an asymptote, or it degrades too quickly.), so I decided to see if my reference book had anything on Binary Search. It ...
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(...
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
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
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
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 ...
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
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
177 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
1answer
98 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
1answer
238 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
1answer
141 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
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
264 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 ...
0
votes
1answer
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 :) ...
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
164 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 ...
0
votes
1answer
114 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 ...