Skip to content
Pramod Nepal edited this page Apr 3, 2017 · 14 revisions

Java Snippets

Disucssion about some algorithms

  • Recursion using subset problem (Combination)

    1. Create a list only once, by making index reach to size of list
    2. Recursively get the global list and loop through it and add current item to each items of the list to create a new list
    3. Add the newely created list back to global list and return to the previous caller
  • Another Recursion Solution using Permutation

    1. Start with full list and empty prefix
    2. When the list becomes empty prefix is full (same size as original list), print the prefix (Ordering matters)
    3. At each stack frame (when the list is not empty), loop through each item of the list, create a new list without the current item in the list, but attach current item to suffix of prefix
  • Another permutation/combination discussion

Clone this wiki locally