Monday, 31 January 2022

Blockchain quick view

 

# Four types of blockchain technology (BT) networks:

public

private

consortium

hybrid

Thursday, 2 September 2021

Useful questions for CSE Students

Leetcode:

  • https://leetcode.com/problems/bulb-switcher-iii/
  • https://leetcode.com/discuss/interview-question/406031/

Geeks:

  • https://www.geeksforgeeks.org/max-count-of-unique-ratio-fraction-pairs-in-given-arrays/

Create custom Connection Pool class:

  • https://www.baeldung.com/java-connection-pooling (point 4)

Graph DFS on real life scenario: 

Implement the class User, representing a person in a social network, with the following functionalities: 

Each user has a name. Provide a public constructor accepting that name.

 Users can befriend each other with the following method:

 public void befriend(User other)

Friendships are symmetric: a.befriend(b) is equivalent to b.befriend(a).

·       Clients can check whether two users are direct friends or indirect friends (friends of friends), using the following two methods,

public boolean isDirectFriendOf(User other)

public boolean isIndirectFriendOf(User other)

Solution:

Solution

import java.util.*;


public class User {

    private String name;

    private Set<User> friends = new HashSet<>();


    public User(String name) {

        this.name = name;

    }


    public void befriend(User other) {

        friends.add(other);

        other.friends.add(this);

    }


    public boolean isDirectFriendOf(User other) {

        return friends.contains(other);

    }


    //DFS

    public boolean isIndirectFriendOf(User other) {

        Set<User> visited = new HashSet<>();

        Stack<User> stack = new Stack<>();


        stack.push(this);

        while (!stack.isEmpty()) {

            User user = stack.pop();

            if (user.equals(other)) {

                return true;

            }

            if (visited.add(user)) {

                stack.addAll(user.friends);

            }

        }

        return false;

    }


    public static void main(String...args) {

        User a = new User("A"), 

             b = new User("B"),

             c = new User("C"),

             d = new User("D"),

             e = new User("E");


        a.befriend(b);

        a.befriend(c);

        d.befriend(c);

        e.befriend(a);


        System.out.println(b.isDirectFriendOf(c));

        System.out.println(b.isIndirectFriendOf(c));

        System.out.println(b.isIndirectFriendOf(d));

        System.out.println(b.isIndirectFriendOf(e));

    }

}




Thursday, 4 March 2021

Useful Commands

 Very useful commands:

mvn dependency:tree -Dverbose > dependencyGraph.txt

 

Thursday, 3 September 2020

Attention ALL PROGRAMMERS

Read this article if your application deals with usernames: 

https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/


Read this article if your application deals with time on computer:

https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time

Now read this if its a JAVA Application:

https://yawk.at/java.time/


Tuesday, 23 June 2020

Microsoft SQL quick help


--Describe table in MS SQL
exec sp_columns My_Table;

--Check for indexes on given table
Select 
    SysIndex.object_id As ObjectId, 
    SysIndex.index_id As IndexId, 
    SysIndex.name As IndexName, 
    type As IndexType, 
    type_desc As IndexTypeDesc, 
    is_unique As IndexIsUnique, 
    is_primary_key As IndexIsPrimarykey, 
    fill_factor As IndexFillFactor, 
    SysIndexCol.column_id, 
    SysCols.name 
From 
    sys.indexes As SysIndex
    Inner Join sys.index_columns As SysIndexCol On SysIndex.object_id = SysIndexCol.object_id And SysIndex.index_id = SysIndexCol.index_id 
    Inner Join sys.columns As SysCols On SysIndexCol.column_id = SysCols.column_id And SysIndexCol.object_id = SysCols.object_id 
Where 
    type <> 0 
    And SysIndex.object_id in (Select systbl.object_id from sys.tables as systbl Where systbl.name = 'My_Table');

Thursday, 26 July 2018

Priority Queue Using Doubly Linked List (Custom Implementation)


package com.vzt.Test.PQ;

public class PQUsingDLL {
public static void main(String[] vj) {
PriorityQUsingDLL obj = new PriorityQUsingDLL();

System.out.println("INSERTING...");
obj.enqueue(2, 3);
obj.enqueue(3, 4);
obj.enqueue(4, 5);
obj.enqueue(5, 2);
obj.enqueue(6, 7);
obj.enqueue(1, 1);

obj.displayQ();

System.out.println("REMOVING...");
obj.dequeue();
obj.dequeue();

obj.displayQ();
}
}

class PriorityQUsingDLL {
private DoublyLinkList list;

public PriorityQUsingDLL() {
list = new DoublyLinkList();
}

public void enqueue(int x, int p) {
list.insert(x, p);
}

public void dequeue() {
list.remove();
}

public void displayQ() {
System.out.println("PRINTING...");
list.display();
}
}

class DoublyLinkList {

private Node first = null;
private Node last = null;

public DoublyLinkList() {
first = null;
last = null;
}

public boolean isEmpty() {
return (first == null);
}

public void insert(int n, int p) {
Node newNode = new Node(n, p);
if (first == null) {
first = newNode;
last = newNode;
} else {
if (p <= first.priority) {
newNode.next = first;
first.prev = newNode.next;
first = newNode;
}
else if (p > last.priority) {
last.next = newNode;
newNode.prev = last.next;
last = newNode;
}
else {
Node start = first.next;
while (start.priority > p)
start = start.next;
start.prev.next = newNode;
newNode.next = start.prev;
newNode.prev = start.prev.next;
start.prev = newNode.next;
}
}
}

public Node remove() {
if (first == null) {
last = null;
return null;
}
Node temp = first;
first = first.next;
temp.displayNode();
return temp;
}

public void display() {
Node current = first;

while (current != null) {
current.displayNode();
current = current.next;
}

System.out.println(" ");
}
public int peek() {
return first.info;
}
}

class Node {
int info;
int priority;
Node prev, next;

Node(int x, int p) {
info = x;
priority = p;
prev = null;
next = null;
}

public void displayNode() {
System.out.println("Data = " + info);
}
}