Sunday, November 29, 2020

Java Maze Solver

 

Wednesday, November 18, 2020

AVL TREE LEFT RIGHT DOUBLE ROTATIONS, DEPTH FIRST SEARCHs, BREADTH FIRST SEARCH, RECURSIVE and ITERATIVE TRAVERSALS, HEIGHT, DEPTH, SIZE, LEAF, NODE FINDERS, ROOT to LEAF NODE PATHS




SINGLE ROTATION
DOUBLE ROTATION



Suppose the node to be rebalanced is X. 
There are 4 cases that we might have to fix (two are the mirror images of the other two):

  • An insertion in the left subtree of the left child of X,
  • An insertion in the right subtree of the left child of X,
  • An insertion in the left subtree of the right child of X, or
  • An insertion in the right subtree of the right child of X.

Balance is restored by tree rotations.

Case 1 and case 4 are symmetric and requires the same operation for balance. 
Cases 1,4 are handled by single rotation.

Case 2 and case 3 are symmetric and requires the same operation for balance.
Cases 2,3 are handled by double rotation

Sunday, February 9, 2020

REDIS STREAM - CLI

DOCKER
docker run -it --rm --net host --name redis1  redis
docker exec -it redis1 redis-cli

XREADGROUP
XGROUP CREATE mystream mygroup $ MKSTREAM
XADD mystream * message apple
XADD mystream * message orange
XADD mystream * message strawberry

XGROUP CREATE mystream grp1 0
XREADGROUP GROUP grp1 Bob COUNT 2 STREAMS mystream >

XGROUP CREATE mystream grp2 0
XREADGROUP GROUP grp2 Bobiy COUNT 2 STREAMS mystream >

The special ID >. This special ID is only valid in the context of consumer groups, and it means: messages never delivered to other consumers so far.




XREAD
XADD mystream * message newcoronavirus
XADD mystream * message nextvirus

XREAD BLOCK 0 STREAMS mystream $
 The special ID $. This special ID means that XREAD should use as last ID the maximum ID already stored in the stream mystream, so that we will receive only new messages, starting from the time we started listening. This is similar to the tail -f Unix command in some way.


Use ConsumerGroups for FANOUT
Use XREAD for P2P