In a sidescrolling video game a character moves through an e
     In a side-scrolling video game, a character moves through an environment from. say. left-to-right. while encountering obstacles, attackers, and prizes. The goal Ls to avoid or destroy the obstacles, defeat or avoid the attackers, and collect as many prizes as possible while moving from a starting position to an ending position. We can model such a game with a graph, G. where each vertex Ls a game position, given as an (x, y) point in the plane, and two such vertices, v and w, are connected by an edge, given as a straight line segment, if there is a single movement that connects v and w. Furthermore, we can define the cost, c(e), of an edge to be a combination of the time, health points, prizes, etc., that it costs our character to move along the edge e (where earning a prize on this edge would be modeled as a negative term in this cost). A path. P. in G Ls monotone if traversing P involves a continuous sequence of left-to-right movements, with no right-to-left moves. Thus, we can model an optimal solution to such a side-scrolling computer game in terms of finding a minimum-cost monotone path in the graph, G, that represents this game. Describe and analyze an efficient algorithm for finding a minimum-cost monotone path in such a graph.    
 
  
  Solution
ALGORITHM:
PSEUDOCODE:
| 1: | function Algo(Graph, source): | |
| 2: | for each vertex v in Graph: | // Initialization | 
| 3: | dist[v] := infinity | // initial distance from source to vertex v is set to infinite | 
| 4: | previous[v] := undefined | // Previous node in optimal path from source | 
| 5: | dist[source] := 0 | // Distance from source to source | 
| 6: | Q := the set of all nodes in Graph | // all nodes in the graph are unoptimized - thus are in Q | 
| 7: | while Q is not empty: | // main loop | 
| 8: | u := node in Q with smallest dist[ ] | |
| 9: | remove u from Q | |
| 10: | for each neighbor v of u: | // where v has not yet been removed from Q. | 
| 11: | alt := dist[u] + dist_between(u, v) | |
| 12: | if alt < dist[v] | // Relax (u,v) | 
| 13: | dist[v] := alt | |
| 14: | previous[v] := u | |
| 15: | return previous[ ] | 

