Hot answers tagged

5 votes
Accepted

pset3 search and sort

In this pset, the file find.c has the statement #include "helpers.h" which will cause helpers.c to be incorporated into the final executable program find. The file find.c has main, so no, you don't ...
user avatar
  • 63.5k
3 votes
Accepted

Pset3 search: can't seem to find the last number

In the search function, try replacing if (values[middle] == value) by if (values[middle] == value || values[middle+1] == value). Because middle is an integer and middle = (lower + upper) / 2; works ...
user avatar
  • 3,316
3 votes
Accepted

Pset3 Search/Find problems

I don't want to sound cruel here, but your sort routine has serious problems. It is incomplete, it has code that appears to serve no purpose ( an if statement with no code to process if true), and ...
user avatar
  • 63.5k
3 votes
Accepted

Pset 8 search and configure functions

According to the spec [emphasis added]: Complete the implementation of /search in such a way that it outputs a JSON array of objects, each of which represents a row from places that somehow matches ...
user avatar
2 votes
Accepted

(pset8) Search.php FULLTEXT minimum character length

I'm not so sure you should create distinctive indexes for each column. What I did was to create a FULLTEXT index for 3 columns together, and then search using that. If you want to create different ...
user avatar
  • 7,326
2 votes
Accepted

Pset3 linear search. Please help me!

In your for loop you have for (n = 0; n < values[n]; n++) The values[n] has the value of the nth element in the values array. So on the first iteration you have n == 0 and you check, is 0 < ...
user avatar
  • 7,326
2 votes
Accepted

Linear search true/false vs 0/1

The problem with that is that true is 1, not 0, so return true is the same as return 1. If the return type really is bool, then you're returning the exact opposite of what you want to return. You ...
user avatar
  • 63.5k
2 votes
Accepted

pset3 search: expected an exit code of 0 not 1

It's because you pass the address of midpoint as the third parameter of comparer(), instead of values[]. Try int result = comparer(midpoint, value, values); instead of int result = comparer(...
user avatar
  • 7,326
2 votes
Accepted

2017 pset8 mashup: Slow search - how to improve search performance?

1: The more columns you are searching the more results you return. For example as you start to type the word "Boston" the search query takes 'B' and looks for every word in the column with a 'B' in it....
user avatar
  • 96
1 vote

Pset3 - Code sorts, but does not find the needle using generate

Your sort is flawed, causing it to eject the largest value and add 0 to the list. Look at the printout of the list to confirm. In the first pass through the outer for loop, k=0. This allows i to ...
user avatar
  • 63.5k
1 vote
Accepted

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

This code will never find anything unless value == midpoint. On each pass through the loop, it updates the min or the max, but it never updates midpoint. Since midpoint never changes, the loop will ...
user avatar
  • 63.5k
1 vote
Accepted

Why am I generating the following errors with this code if it says it's compiled correctly?

One of the lessons of this pset is how to build an executable from multiple source files using a makefile. The link error is happening because you are trying to make helpers. Because there are no ...
user avatar
  • 63.5k
1 vote
Accepted

"make all" for linear search when changing helpers.c results in "error: control may reach end of non-void function"

Compilers are dumb. They won't do exhaustive logic analysis of a function, but they will check to see if they think there's a path through the code that doesn't end with a return statement, assuming ...
user avatar
  • 63.5k
1 vote
Accepted

Iterative binary search only returns false (may be because of sort)

I ran your code and commented out the break statement and it ran perfectly. Why are you getting an infinite loop? Did you change something that you weren't supposed to elsewhere? Is there more to ...
user avatar
  • 63.5k
1 vote
Accepted

Pset3 - Function returns both true and false in while loop

The sm() function recursively calls itself, but fails to recursively return the result. For a detailed discussion, check out Pset3 Binary Search problems The break in this while loop forces the loop ...
user avatar
  • 63.5k
1 vote
Accepted

PSET8 search empty JSON

I've just realised I had to put $places instead of $alpha_match. I should've paid more attention to the code below of how the JSON is created. facepalm
user avatar
  • 97
1 vote
Accepted

PSET8 - search.php, admin_code1

You are missing something, but it is not obvious. There is a mysql setting called ft_min_word_len (the minimum length of words to be indexed), which defaults to 4. MySQL doc is here. See this post for ...
user avatar
1 vote
Accepted

Pset8 Search.php

I got it, the correct syntax would be: SELECT * FROM `places` WHERE MATCH (`place_name`,`admin_name1`,`admin_name2`,`postal_code`) AGAINST (`+Cambridge +Massachusetts` IN BOOLEAN MODE);
user avatar
1 vote

There is something wrong with my keyformula in vigenere cipher, and error message: expected expression

New answer, based on new information. There's something wrong with your parentheses. That "else" has no "if" preceding it. It isn't with the outer if because it is inside that code block. It isn't ...
user avatar
1 vote
Accepted

There is something wrong with my keyformula in vigenere cipher, and error message: expected expression

Hint only: if (n < 1) is the problem. Review the arguments to search.
user avatar
1 vote
Accepted

Please. I need some help. When I use Makefile (make) it wont work

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 ...
user avatar
1 vote
Accepted

Week 3 Binary Search Video Short question

in case we have a single element left in the array, max and min would be equal. the midpoint is calculated, and we check whether array[midpoint] is equal to the value we're looking for. if the ...
user avatar
  • 17.4k
1 vote

Concatenation values to array

Say your array is 3,2,1 On the first pass of your loop (i = 0) your array will become: 2,3,1 Then i becomes 1 and on the second pass it will become: 2,1,3 This is good, as now the 3 is in the right ...
user avatar
  • 264
1 vote
Accepted

Pset 3 Search what am i suppose to do?

First of all, the code you have written, is supposed to implement a linear search O(n), which means it traverses the whole values array and if it finds the value in there, it returns true, otherwise ...
user avatar
  • 7,326
1 vote

Cannot find the needle 127 in the haystack of 1000 random numbers using linear search . Any ideas on what I may have done wrong?

Asked and answered in comments. Except for a minor flaw, the search code appears correct. It should be finding 127. More likely, there's a problem with the code that loads the numbers in the array. ...
user avatar
  • 63.5k
1 vote

pset3 fail right in the beginning with linear search, somehow "may reach end of non-void function@

You don't need: else { return false; } If we have return true the loop will end, so just put a return false at the very end of the function.
user avatar
  • 146
1 vote

How to search in effective manner?

Sorting is one of the technique that is used in solving MANY problems(by MANY, I mean literally many), and that is why, one of the most prestigious book of computer science, The Art of Computer ...
user avatar
  • 3,316
1 vote

How can I implement binary search without changing the search() declaration?

OK, so this was the code that didn't work in my recursive binarysearch(): // search bottom half of list if (value < values[mid]) { max = mid - 1; binarysearch(value, values, min, ...
user avatar
1 vote
Accepted

Linear Search not working

Turns out that I just needed to re-compile find.c. So, I guess if your code should work in theory and syntax is correct, recompile what your working on and see if that works.
user avatar
1 vote
Accepted

Search function always false, haystack doesn't print a value

Consider what would happen the first time the loop executes. For example, if the first item in the list is not the number you are looking for, then when the code reaches the 'if' condition, the ...
user avatar
  • 2,625

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