Hot answers tagged

6

To spot what's wrong with your algorithm, given the following sorted array {1, 2, 3} try with a pen and a paper finding these values value = 1 value = 2 value = 3 value = 4 And try to figure out why your algorithm returns false every time. The algorithm is actually way simpler than that, but let's talk about recursion a little bit first. A recursive ...


2

Your question is: When this assignment is graded, are they planning to deliberately test it with an unsorted list of words that they are calling a "dictionary"?! You can assume that the 'dictionary' list of words given to you is sorted. As the pset says: You may assume that any dictionary passed to your program will be structured exactly like ours, ...


2

Think of it this way. The unsorted list of n elements is broken into n lists of 1 element each. A one-element list is, by definition, sorted. Now, the merging begins. Pairs of lists are merged by taking the first element of each list, comparing them, and choosing the smallest of those two. A new list is build from those two lists. Process repeats until ...


2

The main problem is in the following statements: string answer = 0; answer[i]= min_value; Let's see if I can explain it clearly; a variable of type string is really a typedef (an alias in other words) of char *, that is, a pointer to a char, the first of the previous statements assigns a null (zero) pointer to answer, the second statement tries to ...


1

check50 doesn't care about how you implemented add_pairs when it's testing sort_pairs, so it doesn't initialize the winsize property. You'll need to remove that property, and access it in sort_pairs. In the problem directions it says You should not modify anything else in tideman.c other than the implementations of the vote, record_preferences, ...


1

If you array is declared with 65536 buckets, then aux_list[65536] is outside the bounds (remembering that arrays are zero-indexed). So what happens in your loop when i == 65536?


1

the answer is definitely to use the correct format specifier for a value of type int.


1

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 Programming devotes more than half of one of its book for sorting. The power of sorting can be recognized by the fact that lookup in an unsorted list takes O(n) ...


1

Apparently, you need to access the constant global int namely MAX which is defined in find.c from other source files. You could do something similar to that mod1.c #include <stdio.h> extern int MAX; // declare MAX to be used externally in mod1.c void foo(void) { printf("MAX from foo is %i\n", MAX); // access MAX from mod1.c } mod1.h void foo(...


1

To me, calling an unsorted list of words a dictionary is as ridiculous as calling a random list of numbers a phone directory or calling a random list of cities a map. It strikes me as rather deliberately perverse -- perverse, here, in the sense of "obstinately opposing what is reasonable" -- to claim your file is a "dictionary" if it is really a ...


1

The question was, why would we need to sort our linked lists, when dictionaries, by nature, are already sorted? I assume because your program can accept an optional dictionary which might not be sorted as you want. When this assignment is graded, are they planning to deliberately test it with an unsorted list of words that they are calling a "...


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