2.3.5 Path finding Algorithms

Cards (18)

  • Dijkstra’s algorithm finds the shortest path between two nodes in a weighted graph.
  • Graphs are used as an abstraction for real life scenarios, which means nodes and edges can represent different entities. For example, graphs can model networks, with nodes representing locations and lines between nodes representing distances in miles
  • Dijkstra’s algorithm is commonly implemented using a priority queue, with the smallest distances being stored at the front of the list.
  • The A* algorithm is a general path-finding and has two cost functions: an approximate cost and an actual cost.
  • The cost function is the actual cost between two nodes in a network.
    The approximate cost is a heuristic method, and aims to make the shortest path finding process more efficient.
  • Heuristics are used in A* Algorithms to find the shortest path between the starting node and the final node. This makes finding the shortest node more approximate
  • A disadvantage of using an A* Algorithm is that the algorithm speed is constrained by the accuracy of the heuristic
  • Variables can be defined with either global or local scope. Scope refers to the section of code in which the variable is available.
  • Local variables have limited scope which means that they can only be accessed within the block of code in which they were defined. Lets say a local variable is defined within a subroutine, it can only be accessed within that subroutine.
  • Using local variables is considered to be good programming practice because it ensures subroutines are self-contained, with no danger of variables being affected by code outside of the subroutine.
  • Global variables, on the other hand, can be accessed across the whole program. All variables used in the main body of a program are automatically declared to be global. These are useful for values that need to be used by multiple parts of the program.
  • Global variables aren't recommended because they can be unintentionally overwritten and edited. As global variables are not deleted until the program terminates, they require more memory.
  • In the event that a local variable exists within a subroutine with the same name as a global variable, the local variable will take precedence.
  • A base case is another name for a stopping condition
  • For any other input values other than the stopping condition, the routine must call itself (recursion)
  • Modular programming is a programming technique used to split large, complex programs into smaller, self-contained modules.
  • A modular design also makes it easier to divide tasks between a team and manage, whilst simplifying the process of testing and maintenance, as each component can be dealt with individually. This improves the reusability of components, as once a module has been tested, it can be reused with confidence
  • A Technique used to modularise programs is called the top-down approach, in which the problem is continually broken down into sub-problems, until each can be represented as an individual problem that can be solved.