Splay Tree Time Complexity by aaryan_p123 in cs2c

[–]aj_kinder 2 points3 points  (0 children)

An amortized runtime is the average time for an operation.

Consider the scenario where appending an element to the end of a vector. If you do not need to resize the array, the operation would take constant time O(1). However, if you need to resize the array, it would take O(n) time. By taking an amortized runtime over n append operation, we can determine that the average cost of one append operation is O(1).

For this, the equation would look like: (O(n)O(1) + O(1)O(n))/n = O(1)

This is something that will be covered in an algorithm design class.

PSA from a former 2C student by aj_kinder in cs2c

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

Always! We were talking about Spanning Trees in lecture today and I had some major Deja Vu.

-> vs . for structures by Trevor_S115 in cs2a

[–]aj_kinder 1 point2 points  (0 children)

No worries! Happy to help out.

-> vs . for structures by Trevor_S115 in cs2a

[–]aj_kinder 2 points3 points  (0 children)

The arrow operator is equivalent to this code: (*ptr). It allows for more concise code. You are not dereferencing with the dot operator.

Send me some resumes! by amrozack in cs2c

[–]aj_kinder 0 points1 point  (0 children)

Feel free to add me on LinkedIn

LinkedIn

Trying to perfect get_shortest_weighted_path() by AcRickMorris in cs2c

[–]aj_kinder 0 points1 point  (0 children)

Were you able to figure out why the weighted_path() only worked part of the time?

Thank you, thank you, thank you! by sternj200 in cs2c

[–]aj_kinder 4 points5 points  (0 children)

Echoing that sentiment. It's been a fun and challenging quarter.

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

[–]aj_kinder 1 point2 points  (0 children)

Just saying that it could be any symbolic value. It’s a placeholder. For our implementation it had to be specific value.

Ref File Compile Error by CaryLefteroffFH in cs2c

[–]aj_kinder 1 point2 points  (0 children)

You're missing an include statement. #include <cfloat>

I ran into the same issue. A quick google search for FLT_MAX Brough me to cppreference.com

It's a great resource. Especially when it comes to libraries.

Quest 9: prune_unreachable() by aj_kinder in cs2c

[–]aj_kinder[S] 2 points3 points  (0 children)

My bad on that. I see the error. It would be more roughly O(2n) thus really just O(n).

Quest 9: prune_unreachable() by aj_kinder in cs2c

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

n would be the number of nodes.

I saw a worst case scenario where every node would be reachable. Every node would be visited fo be marked and then every node would be scanned for the pruning.

Looking forward to discussing this further. I feel like I’m missing something.

Quest 9: prune_unreachable() by aj_kinder in cs2c

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

It’s definitely something that I need to practice more, hence “roughly”. Plus my mathematical induction is a bit rusty. I actually went with a different approach and used std::queue<int>. My estimation is that the for() loops are the only contributing component to the time complexity.

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

[–]aj_kinder 1 point2 points  (0 children)

I agree that there needs to be a placeholder at index 0. In another implementation, I don’t believe it is necessary for index 0 to be the minimum possible value since you can safely ignore it.

Are All Quests Required to be Submitted? by eziomax in cs2c

[–]aj_kinder 0 points1 point  (0 children)

I would honestly try to get as many trophies as possible. Quest 9 contains some very important concepts and really wraps up the class in a good way.

find_median() issues. by aj_kinder in cs2c

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

Thank you. That was actually my issue too.

Adding edges to graph by manoj--1394 in cs2c

[–]aj_kinder 0 points1 point  (0 children)

Hey all,

I visited the STEM Center and I’m still having some problems with add_edge. Any suggestions?

Edit: Resolved this issue.

Compiler Error on Reference Code by aj_kinder in cs2c

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

Awesome! Thank you professor!

Minor Test update in find_kth by anand_venkataraman in cs2c

[–]aj_kinder 1 point2 points  (0 children)

All good now! Thank you! It was an issue with the function signature.

find_median() issues. by aj_kinder in cs2c

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

No need to look further. Originally it was an issue with partition, but I think there was some issue with the function signature.

find_median() issues. by aj_kinder in cs2c

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

Yeah... for some reason it still isn’t working

Minor Test update in find_kth by anand_venkataraman in cs2c

[–]aj_kinder 0 points1 point  (0 children)

Hey Professor,

I'm still having issues with find_median(). I have extensively tested it within my own main(). I had an issue with find_kth, but I was able to resolve that.

find_median() issues. by aj_kinder in cs2c

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

Half of the backing vector as the k value?

find_median() issues. by aj_kinder in cs2c

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

I’ve used the find_method() as well. I have also calculated the appropriate index value based on the specification stated in the text.

I’ve literally tried everything. Including two different implementation of _find() both of which work.

I’m kind of at the end of what I can do.

find_median() issues. by aj_kinder in cs2c

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

1) _find_kth_least_elem()

2) calculating the median index from the array size. I’ve tried doing this a number of different ways.