42 Matching Annotations
  1. Feb 2017
    1. Our notes:

      1. Iterator on keyset of Concurrent Hash Map does not use a separate snapshot copy of the map. So, you can witness some/none/all changes from other threads which are changing the same hashmap concurrently. It just reflects that this element existed in the hashmap at some point in time

      2. In copy on write arraylist, the iterator will never pick up parallel changes by other threads, as it creates a snapshot copy at the time of iterator creation.

    1. Integers are immutable, when you add two integers a new integer object is formed. Each integer internally keeps an int value which is final and can't be modified. + operator is compiler magic.

    1. Good example of how gof patterns are used in the JVM, Interger.valueOf keeps a configurable cache of Integer objects, note that integer objects are immutable.

    1. public static <T> List<T> asList(T... a)

      Example of adaptor pattern. Here's the array serves as the backing point for the list, all methods of list api will be driven on basis of operations on the underlying array.

    1. Prototype design pattern with warlord, beast and mage, orcs and elfs, we keep a hashmap of each object ready in the factory at time of factory construction or lazily. Then when a new Warlord is requested, an existing warlord is cloned and used.

    1. Here we can have two underlying data structure for a stack, an array or a list (similar to different platforms, example, unix, windows). An orthogonal set of hierarchy will be StackHanoi, which only allows to add an element if it is smaller than the top of the stack. Another hierarchy is FIFO implementation using stack. Now for each of the orthogonal implementation since we can choose a list or an array for the underlying implementation.

      So, the underlying implementation forms another interface hierarchy of StackImpl, and actual Stack will "have a" StackImpl.

      Now you may think it is similar to decorator-

      differences: ->in decorator , you try to add behaviour on top of original functionalities. (like keeping a count whenver you call original functionalities like pop, push etc) but in bridge, you are selectively calling the original functionality or else you override the original. ->decorator here will only have one class that encapsulates all original impl but in bridge , your platform independent things are kept via 'has a' relation inside your handle, and your orthogonal functionalities will be extending that handle .

    1. Good explanation of Clone, except doesn't cover the mandatory nature of Cloneable, one of the classes up our hierarchy should implement Cloneable, for you to call clone() on it, without encountering a runtime exception.

  2. Jan 2017
    1. int _bsearchForFO(int arr[], int left, int right, int elem) {<br> if(right - left <= 1) { if(arr[left] == elem) return left; else return right; } int mid = left+right/2; if(arr[mid] == elem) { return _bsearchForFO(arr,left,mid,elem); }else{ return _bsearchForFO(arr,mid,right,elem); }

      }

    1. The third tricky solution is same as Kadane, just that we can modify the original aray, we did Kadane with two variables, here we can use the diff array itself for storing the sums, so we check the sum of i-1 at i.

    1. if an element is not at its correct position, that means repetition has already ocured in the left if the element is at its correct position, there is possibility of repetition in the right side

    1. Brendan Gregg's flame graphs are the starting ground for this work. Tanel Poder has also published several original investigations of stack profiling for Oracle troubleshooting, notably this included the blog post "Peeking into Linux kernel-land using /proc filesystem for quick’n’dirty troubleshooting". Kevin Closson has also published work on stack profiling with perf and OProfile and he is the author of SLOB, used in Example 2 of this post.

      All things /proc !

    1. just apply regular kadane from front and backward and do fw[i-1]+b[i+1] sum in the same way. Also have to keep max_so_far in consideration for an all positive number scenario. note- indexes are not visible from any of these approaches

    1. int i = minvalue; i <= maxvalue; i++

      You have two options for the iteration in first loop:

      Either sort the array and iterate over the elements present only in the array. Or iterate from min_value to max_value which checks every number, irrespective of its presence in given array or not.

    2. mark[j]

      We can use the following condition as well:

      value[j] == 0 || value[j/i] == 0

      This is because in cases where value[j/i] =0 , the loop in doing redundant work.

    3. value[i] * value[j/i]

      If you can arrange left subtree in x ways and right subtree in y ways, then you can have total x*y combinations for their parent, each of which will be a full binary tree..

      1. if negative numbers are allowed, then the solution will fail because:

      -1 -2 3 4 5

      We would like to use -1,-2 for solution to 4.

      Also ,if we have to find the maximum this logic will not work, because then again we will like to keep all numbers, and not just one of them which is solution assumes.

      In general, if we have to minimize the result, then question will keep the restriction on skipping elements, but when we have to maximize the result, then question will put restriction on including the elements.

    1. We want cases where maximum > k only.

      9 8 7 1 2 3 4 19 12

      No. of subarrays = subarrays of size 1 + subarrays of size 2 + subarrays of size 3 + .... subarrays of size n

      = n + (n-1) + (n-2) + .... + 1 = n(n+1)/2

    1. recur[v] = false;

      This is like making the node black, so basically

         a
      b    c
      

      case 1: edges are a->b, a->c, c->b (not a cycle) case 2: edges are a->b, a->c, c->a (cycle)

      When we are exploring c, b is black, considering we have already visited b first during dfs from a, and any link to black nodes do not constitute a cycle.

      This is an overkill, as a node cannot have two neighbours in the given problem.