[Solved] In a square matrix, where each cell is black or white. Design an algorithm to find the max white sub-square [closed]

First note that your solution is NOT O(n^2), it is more like O(n^4), because for each cell, you look for the largest matrix that can be of size up to O(n^2) itself, so it is totalling to O(n^4). It can be done however in O(n^2): First, define 2 auxillary functions (implemented as matrices): whitesLeft(x,y) = … Read more

[Solved] How do i get the reference to the last (yet unfilled) element in a binary tree? [closed]

In the discussion below, I demonstrate using a min-heap. A max-heap works the same way, except the root is the largest node rather than the smallest, and parents are larger than their children. Things work the same way, except that you reverse the sense of the comparisons. Insertion into a binary heap follows these rules: … Read more

[Solved] How to cover a range using a set of ranges with minimal overlap?

Here is the greedy algorithm – always the best place to start. allocate all teams IF not all sections covered output -1 stop mark all teams non-critical flag_improved = true WHILE( flag_improved == true ) flag_improved = false find most expensive section find most expensive non-critical team on most expensive section IF team found that … Read more

[Solved] My linked list code in c++ is only appending one value

Think very carefully about the code you have for stepping through the list looking for where you can append your new value, especially the last line inside that loop body: while(nodeptr->next){ nodeptr=nodeptr->next; nodeptr->next=newNode; } Were you to actually single-step your code through a debugger, examining the list after each statement, you would see the problem … Read more

[Solved] Why my output isn’t correct?

I commented the changed portion and explained why. I didn’t change your code, so that you can understand easily. Try this : #include <stdio.h> #include <stdlib.h> #include <string.h> struct AdjListNode { char *dest; struct AdjListNode* next; }; struct AdjList { struct AdjListNode *head; // pointer to head node of list }; struct Graph { int … Read more

[Solved] python mapping that stays sorted by value

The following class is a quick and dirty implementation with no guarantees for efficiency but it provides the desired behavior. Should someone provide a better answer, I will gladly accept it! class SortedValuesDict: def __init__(self, args=None, **kwargs): “””Initialize the SortedValuesDict with an Iterable or Mapping.””” from collections import Mapping from sortedcontainers import SortedSet self.__sorted_values = … Read more

[Solved] heap sort may be considered as insertion sort or selection sort done on a heap data structure instead of a list? Which one will it be?

heap sort may be considered as insertion sort or selection sort done on a heap data structure instead of a list? Which one will it be? solved heap sort may be considered as insertion sort or selection sort done on a heap data structure instead of a list? Which one will it be?