Showing posts with label bfs. Show all posts
Showing posts with label bfs. Show all posts

Sunday, October 30, 2016

Codeforces problem B Two Buttons analysis

Problem Type : BFS , math , greedy , shortest path

Problem link: Two Buttons


this was a very interesting for me.


This problem asks us what is the minimum steps we need to reach from one given number to another given number by multiplying by 2 or  subtracting 1


i have found 2 ways to solve this problem 

       1) using bfs (hard way)
       2) simple mathematics

The hard way:


let us try to analyze 2 given test cases 


1)  4 ->6  minimum steps: 2

2) 10 ->1 minimum steps: 9

let us make a graph using the 2 test cases



Thursday, September 8, 2016

Breadth-first search implementation

I learned bfs from my friend and from this blog shafaetsplanet . In shafaetsplanet the algorithm is explained very easily. There the bfs code was implemented using adjacent metrix. Here we will implement it using adj list.

from safaet's blog I will take few lines to show everyone how bfs works

     01. A node can't be visited more than once.
     02. The source node is always level 0.
     03. All nodes directly connected to level 0 or source node are level 1.
     04. All nodes directly connected to level 1 are level 2.And this is how level will keep on rising one by one.
     05. Level of each node is the shortest path distance from its source node


Basic Graph:

















Football Player Transfer Prediction

Football Player Transfer Prediction Using Different Classifiers Project Report :  Football Player Transfer Prediction Report ...