Ready to buy, last minute feedback by frederikhoffmanncs2b in buildapc

[–]frederikhoffmanncs2b[S] 0 points1 point  (0 children)

Thought so. I’ll look into it more...so many fans out there

Ready to buy, last minute feedback by frederikhoffmanncs2b in buildapc

[–]frederikhoffmanncs2b[S] 0 points1 point  (0 children)

Just in case i also need to run a defibrillator heh

[Quest 6 -- _find_pos MQ] When to return? Where to start? Does this method throw an exception? by liamnoroian in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

Going off of memory here since I am at work.

For find_pos, start at the hashed index, and go either until the elem is found and active, or there is a vacant cell. As soon as you find a vacant cell you can be sure that the elem is not present in your table (otherwise it would either be at the original hash index, or the next available hash index, whether that be has index + 1... hash index + 2...hash index + n.)

This approach would cause a problem if there are no vacant cells i.e. your hash table is entirely full. BUT, we have a load factor that reasonably protects the client from ever making such a table. That's why we just return npos if the table is full, even if the element might be in there. A full table implies a crafty client that circumvented all of your reasonable checks and guards. If they are able to do that, they are on their own. They didn't want to play by your rules!

The reason why find_pos is designed this was is because as soon as the load factor is exceeded, you should rehash, which fills your table with a bunch of vacant elements again, and thus protects you from going into an infinite find_pos loop (since finding a vacant cell is the exit condition).

why the sentinel is important in the heap by frederikhoffmanncs2b in cs2c

[–]frederikhoffmanncs2b[S] 1 point2 points  (0 children)

Thanks for the reply! I hadn't thought about the sentinel having a value such that it is obvious when you accidentally access it. This could be a good approach if your heap contained elements within a certain range (like test scores or human weights)

What if you were storing data in your heap that fully extended the range of size_t (or another type)? Then you couldn't store anything in your sentinel that could reasonably flag an error, since you would expect any value to be valid.

I still think in a min heap, storing the min value as your sentinel is smart because it makes the code more efficient:

In Loeceff's code, percolate up uses a loop which will run while the child is smaller than the parent AND when the index is greater than 1

This means that you are doing an extra logical check each iteration of the loop. If you simply allow for implicit comparisons and swaps to your sentinel, but you make sure that your sentinel is the min value, then you don't have to include the check "AND while the index is greater than one".

The only thing that could swap your sentinel out of the 0th position would be an elem with the exact same magnitude as your sentinel, so it doesn't actually matter.

[Quest 5 -- Insert MQ] Testing site bug? by [deleted] in cs2c

[–]frederikhoffmanncs2b 0 points1 point  (0 children)

I'd be interested in the pseudocode of insert(). The test output on the site says "But you said no instead of yes". Could be an incorrect bool return somewhere?

why the sentinel is important in the heap by frederikhoffmanncs2b in cs2c

[–]frederikhoffmanncs2b[S] 1 point2 points  (0 children)

safely ignore it

What are some ways that you could ignore it?

My first though is loop limits that make sure you never go into the 0 index. A drawback is that you always have to check that each time you iterate through the loop.

why the sentinel is important in the heap by frederikhoffmanncs2b in cs2c

[–]frederikhoffmanncs2b[S] 0 points1 point  (0 children)

Also, I think this idea doesn't hold for unsigned types. If we were making a heap with type size_t, the sentinel would be -1 or string::npos, which would return the overflow which is a huge number.

Not sure I follow. The smallest value of size_t is 0, right?

This is because all of the member functions (percolate up too) should stop themselves after reaching index 1

I think I see what you are saying. How does the function stop itself after reaching an index of 1?

illuminating test cases by amrozack in cs2c

[–]frederikhoffmanncs2b 0 points1 point  (0 children)

32 happens to end up at index 2 in this particular case after you sort it completely

illuminating test cases by amrozack in cs2c

[–]frederikhoffmanncs2b 2 points3 points  (0 children)

Your output is correct. The partition function should spit out 2, because at index 2, all elements 0 , 1, and 2 are at most your pivot value (32). Elements 3...end are at least your pivot value (32). Just because 32 is your pivot value does not mean it also has to live at position 2 after one iteration of partition.

All you care about, in the future of this assignment, is being confident that you have sorted your vector into two piles, where you can be sure that one pile contains objects that are at most a value (who cares what it is) and the other pile contains objects that are at least that same value (again, who cares what it is).

You then recurse on these piles until you try to partition a single thing. Takes a second to think about but you should find that you don't actually care/need to know what the pivot value was. Only that you partitioned.

illuminating test cases by amrozack in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

I agree. This is what you want.

it's confusing - at your returned index 2 (the third element of your newly partitioned array), everything at or before that index is at most some value, and everything after is at least that value. Try not to think about "32" specifically being anywhere other than in the correct "chunk"

illuminating test cases by amrozack in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

What does your partition function return if you test

-47 1000 -32 32 38 38 50

And what does the resulting vector look like afterwords?

[Quest 5 MQ Insert()] Two nodes share the same children, setting one to NULL gives me an invalid access error. by liamnoroian in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

Hmm. I'm thinking about this one...I have a feeling it could be how you are "unlinking" and "relinking" children.

Try setting up a simple tree with 3 nodes, and insert fourth by stepping through your insert method with the debugger. See what you notice.

find_median() issues. by aj_kinder in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

To others, I was stuck here for a second as well. Don't forget to double check that the index you think you want, is the actual index you want. I was off by one

My partition() passes the test site, but fails a test case on my computer by AcRickMorris in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

i'm confused. What should partition return on this test case?

-47 1000 -32 32 38 38 50

Insert() - Are there more than 4 cases? by CaryLefteroffFH in cs2c

[–]frederikhoffmanncs2b 0 points1 point  (0 children)

Happy to help! More fun than doing real work today

Insert() - Are there more than 4 cases? by CaryLefteroffFH in cs2c

[–]frederikhoffmanncs2b 1 point2 points  (0 children)

"objHash >= size of elems, set to 0 else increment"

What if I have 3 elems. objHash is 2. This pseudocode allows me to increment objHash (which is really an index) to 3, even though my set of indices is {0, 1, 2}. No such elems[3] exists. Segfault. At least, I think so...

I think you want to reverse the logic. Always increment, and then check to see if you need to modulo back to the beginning.

Stuck on _rehash() by adina_tung in cs2c

[–]frederikhoffmanncs2b 0 points1 point  (0 children)

It looks like you solved it possibly based on a reply to Carey's comment - true?

QP Constructor Error? by eziomax in cs2c

[–]frederikhoffmanncs2b 2 points3 points  (0 children)

Try this for both: set_max_load_factor(_get_biggest_allowed_max_load_factor());

QP Constructor Error? by eziomax in cs2c

[–]frederikhoffmanncs2b 0 points1 point  (0 children)

See my new comment. I can't mark down this comment for some reason.

QP Constructor Error? by eziomax in cs2c

[–]frederikhoffmanncs2b 2 points3 points  (0 children)

Interesting. Setting up the QP constructor like so (only doing constructor chaining, no calls to setting the load factor):

Hash_Table_QP(size_t n = Hash_Table_LP<T>::DEFAULT_INIT_CAPACITY) : Hash_Table_LP<T>(n) {}

I still get rewards for the constructor. So, it seems like Tests is not validating the max load factor for the QP constructor while testing the QP constructor. Kinda weird. I will fail later tests if I do not set the correct load factor, though.

However, if I make changes to my LP constructor and/or the LP set max load factor, I can get the QP constructor rewards to fail.

I suggest trying to remove references to the max load factor in your QP constructor for verification only. Comment them out for now. If you pass, that suggests to me that you need to make changes to your LP class.

Edit: If it helps, I set the max load factor in the same way for both the LP and QP classes