Posts

Showing posts from November, 2022

DSA GRIND #9

Image
 INVERTING A BINARY TREE - AB  This weeks problem is similar to our earlier work on reversing a linked list data structure, but in this instance we're going to be inverting a binary tree. The following picture shows an example of what that means. Like our earlier work, I went about doing this recursively as well. So kept making calls back to the function within itself as we went about inverting the data structure node for node. The results/code is as follows.  The code was solid, though the memory management was pretty lacking, its resource intensive holding the same calls within the stack for execution. 

DSA GRIND #8

Image
 Kth Largest Element in the Stream : by A.B      We're back at it again this week and focusing on a problem involving the heap data structure. For those unfamiliar, a Heap is a tree-based data structure that is a complete binary tree in that for a given node B, if A is the "parent" node of B, the value of A is greater/equal to the value in B.     So our problem description and an example to help understand it is provided below.      I do have some experience with binary trees but this solution required way more work than I expected. The challenging part was not being familiar with methods unique to heap structures. It took a big of googling/studying to understand what I actually had to do in order to get my code to perform the way I had it lined up in my mind. In any case, I did what I sought to do and got a submission to pass all test cases. Admittedly, I'm ignorant to if I can optimize this better, I'll be looking into other solutions to se...