some corrections done
uploading working algorithm and graphic