Sunday, 27 April 2025

[Graph] - DAG : An important observation

In a DAG, a mutually unreachable pair (s,t) can exist if and only if there exists at least one topological level with at least two nodes

Read the post at Notion : https://www.notion.so/DAG-Directed-Acyclic-Graph-1d8d32fa6ba880e7aea2d3eb59ad46e1

Sunday, 16 March 2025

Leetcode Weekly Contest 441 Q2. Closest Equal Element Queries

Q2. Closest Equal Element Queries

Important learnings wrt 🔁Circular Array🔁  : 

 The two distances between elt at i & j  : 

  • forward_dist  = (j-i+n) % n;
  • backward_dist = (i-j+n) % n; 
How to get the two indexes `d` distance away from a given index, i ?
  • next_d_idx = ( i + d) % n ;
  • prev_d_idx = ( i - d + n) % n ;
As a special case when d=1, we can get next & prev elements as : 
  • next_idx = (i+1) % n 
  • prev_idx = (i-1+n ) % n
Alternatively, the +1 for forward should be thought as +(n-1) for backward or more generally, +d should be thought as +(n-d) when marching in backward direction.

Sunday, 9 March 2025

"Mastering Power Set Generation: A Deep Dive into Recursion” from a Java ☕ programmer’s perspective

Motivation for the notes :

  1. Leetcode#78. Subsets 
  2. G4G Power Set 

There are broadly two approaches :

  1. Bit Masking (iterative) 😷{not focus of this blog}
  2. Backtracking (recursive) ⭐
    1. Include-Exclude paradigm : here we see two variants & why we should use one over other
    2. For-loop paradigm : prefer this (reason at the end)

Continue reading my latest blog compiled at notion.so by clicking here :  "Mastering Power Set Generation: A Deep Dive into Recursion” from a Java ☕ programmer’s perspective



Friday, 22 March 2024

SUNY Buffalo : MS Tracks and Specializations (Graphic Representation)

Graduate degree options provided by Departement of CSE at SUNY Buffalo can be graphically represented as : 

 


(Click on the images for enlarged view 🔍)

The graphic representation of the semester wise breakdown of programm can be depicted as : 




Please comment below if you find anything wrong in the representations. Or, if you want to add more in this.


Thursday, 4 January 2024

LineRandomizer in Python : Utility Function

While Memorizing vocab for GRE, I decided to jumble up my word list in random order. This small python utility program helped me achieve that. Hope it helps you as well. 


'''
Author: Kunal Krishna
Date: 30/05/2023
'''

'''
Programme Purpose : Given a text file containing N lines,
    return a new file which has reorder those lines in random order.
    This has many utilities e.g. in memorizing a list of vocabulary.
Input: File1.text :
    >a
    >b
    >c
Output: File2.text : Random ordering
    >c
    >a
    >b
'''

import os
import re
import random
import numpy as np

# 1. Open file.txt : https://docs.python.org/3/library/functions.html#open
inpFile= open("D:\[win.kunal]\Desktop\Diff_Words.txt","r")
linesList = inpFile.readlines() #list of lines
# for line in linesList :
#     line = line.strip("\n")

# 2. Create an output file
resPath= "D:\my_codes\py_code\LineRandomizer"
resFileName = 'Difficult_Words.txt'
file_result = open(os.path.join(resPath,resFileName), "w") # w : creates/overrides existing
# alternatively
# file_result = open("Difficult_Words.txt", "w")

count = 0
# 3.Process the lines : randomize
while (len(linesList) > 0) :
    #chose a random word from the list
    random_word = np.random.choice(linesList)

    validWordExpression = "[~\*\#\w\s]"
    if( len(random_word.strip()) >0
            and re.match(validWordExpression, random_word) ) :
        # write the random word in the new file
        print(str(count+1)+". inserting..." + random_word.upper())
        file_result.write(random_word.upper())
        count +=1

    #also remove the word from linesList to avoid repetation
    linesList.remove(random_word)

# 4. Close the file
inpFile.close()
file_result.close()
if count>0 :  
    print(str(count)+" words inserted successfully!!!")
else :  
    print("No word(s) inserted.")