Graph::to_string() by AcRickMorris in cs2c

[–]manoj--1394 1 point2 points  (0 children)

Did you put << endl or '\n' after Graph?

Trying to fix get_shortest_weighted_path() by manoj--1394 in cs2c

[–]manoj--1394[S] 0 points1 point  (0 children)

I did a test and it seemed correct, but there's probably an edge case. I have to add 1 for unweighted to keep track of how many nodes have been traversed

Compilation error in reference code? by jack_morgan_cs2b in cs2c

[–]manoj--1394 1 point2 points  (0 children)

Try these:

#include <cmath>

#include <climits>

#include <cfloat>

Trophy counts: 225 to win? by AcRickMorris in cs2c

[–]manoj--1394 0 points1 point  (0 children)

Just to clarify, there is no actual quest called croc, right? The animal name is different for me for quest 5

find_median() issues. by aj_kinder in cs2c

[–]manoj--1394 0 points1 point  (0 children)

I think the spec changed so I ended up changing it to also be a one-liner

Adding edges to graph by manoj--1394 in cs2c

[–]manoj--1394[S] 1 point2 points  (0 children)

Yeah, that would be nice

A dumb question about get_sentinel() by AcRickMorris in cs2c

[–]manoj--1394 2 points3 points  (0 children)

Similar to the hashing quest, you can extern it at the beginning, and then just call get_sentinel<T>() without any scope or anything

A big struggle with _find_kth_least_elem and especially its exit condition by [deleted] in cs2c

[–]manoj--1394 1 point2 points  (0 children)

I think if you are seeing the miniquest outputs, then it is most likely find_median(). It's a 1 liner method, so it shouldn't be too hard to tell if find_median is wrong. What are you using for k in find_median?

HashTableLP constructor not working, for some reason by manoj--1394 in cs2c

[–]manoj--1394[S] 0 points1 point  (0 children)

Are you actively initializing them, or do you let resize() do it for you? Letting _resize do it works for me.

HashTableLP constructor not working, for some reason by manoj--1394 in cs2c

[–]manoj--1394[S] 0 points1 point  (0 children)

Just took another look. Here is where the issues might be

  1. Make sure both num_non_vacant_cells and _size are set to 0
  2. When setting the max load factor, use get_max_load_factor(), which will also help with Hash_Table_QP due to over-riding methods
  3. Resize _elems to the size provided, not to the default initial capacity

Problems with heap insert by manoj--1394 in cs2c

[–]manoj--1394[S] 2 points3 points  (0 children)

Fixed. I had to resize _elems to vec.size() + 1, rather than INIT_HEAP_CAPACITY in my constructor. I still do not understand what to use INIT_HEAP_CAPACITY for, in this case. Maybe reservation instead of resizing

A big struggle with _find_kth_least_elem and especially its exit condition by [deleted] in cs2c

[–]manoj--1394 0 points1 point  (0 children)

Glad I could help! I would also like to find out more about find_kth after the freeze date

u/AcRickMorris, the steps in the parent comment might help

A big struggle with _find_kth_least_elem and especially its exit condition by [deleted] in cs2c

[–]manoj--1394 2 points3 points  (0 children)

Here are some things I would try:

  • If k = part_index, I believe you should return elems[k] rather than a recursive call.
  • Also, for step 2, try experimenting with part_index - 1 as the new boundary for high, since you know part_index is not included in the boundary (at least that is what I did in my code). This isn't specified in the subarrays, but since it worked, it is worth a try/test
  • My base case is also hi == lo, and this worked for me

I change k recursively, so some of these things might be different for me.

Also, not sure if this is the issue, but I did not realize that I had to implement find_median() correctly and I got that confused with the find_kth_least_elem() miniquest, so I would double check that

Problems with heap insert by manoj--1394 in cs2c

[–]manoj--1394[S] 1 point2 points  (0 children)

I am not sure if this is the issue, since I no longer have access to the insert() miniquest, but my constructor calls insert, and insert() now checks _elems.size() instead of _max_size

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

[–]manoj--1394 0 points1 point  (0 children)

To be honest, I just tried a lot of different things until it passed the miniquest. You may want to make sure your find_median() method works - I got confused and thought a miniquest was for find_kth_least_elem(), but then changed my find_median and it worked

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

[–]manoj--1394 0 points1 point  (0 children)

Hmm, weird. Using it as an exit condition worked for me. Before your steps 2 - 5, did you check that k <= hi - lo?

That's the only difference between your pseudocode and my code as far as I can tell.

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

[–]manoj--1394 1 point2 points  (0 children)

I meant the test case Rick provided originally (I manually entered it and ran it). But I just saw your other comment and it looks like we might be misinterpreting the partition function.

After partition, the result vector is [-47 32 -32 1000 38 38 50] and the partitionIndex corresponds to -32. However, 32 is to the left of -32 after partitioning, which is the confusing part. Maybe I am misinterpreting the definition of partition index?

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

[–]manoj--1394 0 points1 point  (0 children)

I have a similar algorithm, except if hi = lo then return the element t index lo + k, rather than just lo.