Home > Backend Development > C++ > Applications, advantages and disadvantages of charts

Applications, advantages and disadvantages of charts

WBOY
Release: 2023-08-29 18:13:06
forward
987 people have browsed it

Applications, advantages and disadvantages of charts

Diagrams are used in different disciplines. They are used in biology to represent gene interactions, for route optimization in transportation, and for analysis of user connections in social networks. A chart's visual representation of complex relationships and its ability to observe patterns and trends are two of its strengths. However, working with large data sets can make charts unwieldy and difficult to understand. Additionally, creating charts can take time and knowledge. Despite these shortcomings, graphs remain an effective tool for interdisciplinary data analysis and decision-making.

usage instructions

  • Setting representation

  • Link representation

  • Sequential representation

Setting representation

Each vertex in a graph is associated with a set containing its surrounding vertices, which represents the graph. In this approach, the edges of the graph are stored in an adjacency set or hash table containing the set. The set of each vertex ensures that there are no duplicate adjacent vertices, and it manages sparse graphs efficiently. Adding and removing edges is easier and memory utilization is reduced compared to other representation methods. This technique is very helpful when dealing with networks with varying degrees of connectivity, as it can efficiently perform operations such as checking edges and iterating nearby vertices.

  • Adjacency sets: In the set representation of graphs, adjacency sets use sets to record the neighbors of each vertex, preventing duplication and facilitating efficient processing of edges.

  • Hash tables: Hash tables are used in the context of set representations of graphs, connecting each vertex to the set containing its neighboring vertices.

algorithm

  • The vertices of the graph should be represented by a class or data structure. Each vertex object needs to have a collection containing its adjacent vertices, and it also needs to have an ID or label.

  • Create an empty storage space to hold the vertices of the graph (such as an array, vector, or hash table).

  • For each vertex in the graph:

    Creates a new vertex object with the specified ID or label for each vertex in the graph.

    Add its adjacent vertices to the adjacency set.

  • Add edges between vertices using the following technique:

    Collect vertex objects for source and target vertices.

    Include the target vertex in the adjacency set of the source vertex.

  • Implement the following edge removal techniques:

    Collect vertex objects for source and target vertices.

    Remove the target vertex from the adjacency set of the source vertex.

  • Implement other techniques required for graph operations, such as determining whether an edge exists and obtaining the neighbors of a vertex.

Example

#include <iostream>
#include <unordered_map>
#include <unordered_set>

class Graph {
private:
    std::unordered_map<int, std::unordered_set<int>> adjacencySets;

public:
    void addEdge(int source, int destination) {
        adjacencySets[source].insert(destination);
        adjacencySets[destination].insert(source); // If the graph is undirected, add both edges
    }

    void removeEdge(int source, int destination) {
        adjacencySets[source].erase(destination);
        adjacencySets[destination].erase(source); // If the graph is undirected, remove both edges
    }

    void printNeighbors(int vertex) {
        std::cout << "Neighbors of vertex " << vertex << ": ";
        for (int neighbor : adjacencySets[vertex]) {
            std::cout << neighbor << " ";
        }
        std::cout << std::endl;
    }
};

int main() {
    Graph graph;

    graph.addEdge(1, 2);
    graph.addEdge(1, 3);
    graph.addEdge(2, 3);
    graph.addEdge(3, 4);
    graph.addEdge(4, 5);

    graph.printNeighbors(1);
    graph.printNeighbors(3);

    graph.removeEdge(2, 3);

    graph.printNeighbors(1);
    graph.printNeighbors(3);

    return 0;
}
Copy after login

Output

Neighbors of vertex 1: 3 2 
Neighbors of vertex 3: 4 2 1 
Neighbors of vertex 1: 3 2 
Neighbors of vertex 3: 4 1
Copy after login

Linked list representation

Each vertex in the linked representation of the graph is represented as a node in a linked list. The structure of the graph is formed by these nodes, which are connected to each other through pointers or references and hold data about the vertices. Each node also has a linked list or other dynamic data structure that stores the adjacent vertices of the edge. This approach effectively depicts sparse graphs with different connectivity levels. It supports dynamic graph architecture and allows simple addition and removal of edges. However, it may have a slightly larger memory burden than other representations. There are advantages to using linked representations when memory flexibility and efficiency are primary considerations.

algorithm

  • Find the graph node corresponding to vertex 1 in the tree.

  • If the node cannot be found, create a new node for vertex1 and add it to the graph.

  • In the graph, find the node corresponding to vertex 2.

  • If the node cannot be found, create a new node for vertex2 and add it to the graph.

  • To represent an edge, add vertex2 to the linked list of nodes corresponding to vertex1.

  • In the undirected graph, link vertex1 to the linked list of vertex2.

Example

#include <iostream>
#include <unordered_map>
#include <list>

void AddEdge(std::unordered_map<int, std::list<int>>& graph, int vertex1, int vertex2) {
    graph[vertex1].push_back(vertex2);
    graph[vertex2].push_back(vertex1);
}

int main() {
    std::unordered_map<int, std::list<int>> graph;

    AddEdge(graph, 1, 2);
    AddEdge(graph, 1, 3);
    AddEdge(graph, 2, 3);

    for (const auto& entry : graph) {
        std::cout << "Vertex " << entry.first << " is connected to: ";
        for (int neighbor : entry.second) {
            std::cout << neighbor << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}
Copy after login

Output

Vertex 3 is connected to: 1 2 
Vertex 2 is connected to: 1 3 
Vertex 1 is connected to: 2 3 
Copy after login

app

  • Charts are used to simulate user connections on social media platforms so that social interactions can be studied and communities identified.

  • Graphs are very useful in route optimization, shortest path calculation and designing efficient transportation networks.

  • The topology of a network is represented graphically, which is very helpful for network design, analysis, and troubleshooting.

  • Diagrams model metabolic pathways, protein interactions, and gene connections to aid in the study of biological systems.

  • Graphs are used in recommendation engines to provide recommendations for products, movies, or other materials based on user preferences and item relationships.

  • They make intelligent search and question-and-answer systems possible by structuring and connecting information.

  • Fraud detection, risk assessment and portfolio optimization all use graphics.

  • Graph-based techniques are used for problems including link prediction, classification, and grouping.

  • Diagrams make it easier to understand the links between IoT devices and data flows, thereby facilitating analytics in IoT applications.

  • Improved medical insights with charts that support medical research on drug interactions, patient monitoring, and disease modeling.

Advantage

  • Charts provide a simple and easy-to-understand visual representation of data, making complex associations and relationships easier to understand.

  • Through charts, pattern recognition, trend analysis and anomaly detection can be achieved, thereby improving decision-making and problem-solving capabilities.

  • To efficiently process and interpret data, charts display a variety of data structures that accurately simulate complex real-world situations.

  • When working with interconnected data in databases, graph-based topologies enable the retrieval and traversal of data.

  • Graphs are often used in social network analysis to understand social interactions and identify prominent nodes or users.

  • Charts are extremely useful in determining the fastest or most efficient routes in transportation and logistics.

  • Graph-driven recommendation engine provides recommendations for products, services or information based on user behavior and preferences.

  • Graphs can represent knowledge and information in a hierarchical manner, which makes them very useful in applications of artificial intelligence and semantic networks.

  • In structured data, use graph-based machine learning techniques to perform tasks such as clustering, classification, and link prediction.

  • Finding the best match or efficiently scheduling work are just two examples of many challenges that graph algorithms can help solve.

shortcoming

  • When dealing with large data sets or the presence of large numbers of nodes and edges, graphs can become unmanageable and complex. Because of this complexity, it can be difficult to fully analyze and understand the data.

  • Storing a graph can consume a lot of memory, especially for dense graphs with many nodes and edges. As graphics get larger, memory usage can become an issue.

  • Finding the shortest path in a large graph, for example, can be a time-consuming and computationally intensive task. This can cause performance issues, especially in real-time applications.

  • Graphs can have various structures, with some nodes being significantly more connected than others. Because of this inhomogeneity, it can be difficult to use common techniques or draw useful inferences from the data.

  • When working with high-dimensional graphs, visualizing complex graphs can be challenging, and the underlying data may not be clearly represented.

  • Missing or incorrect data can cause inconsistencies in charts, affecting the quality and reliability of your analysis.

in conclusion

Diagrams are flexible and frequently used tools in various disciplines, such as biology, transportation, and social networks. They are useful tools for data analysis because they can visualize complex relationships and find patterns. However, processing large data sets can become complex and require more memory. Additionally, creating charts requires time and knowledge. Despite these shortcomings, diagrams are still a useful tool for problem solving and decision-making. By using appropriate representations (such as set and link representations) and implementing efficient algorithms, diagrams can continue to provide useful insights and support in a variety of applications across multiple disciplines.

The above is the detailed content of Applications, advantages and disadvantages of charts. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template