# Four types of blockchain technology (BT) networks:
public
private
consortium
hybrid
# Four types of blockchain technology (BT) networks:
public
private
consortium
hybrid
Leetcode:
Geeks:
Create custom Connection Pool class:
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));
}
}
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/