G And J Algorithm