Languages with graph data structures and algorithms in standard library

I am trying to improve my knowledge and ability with graphs and graph algorithms and have noticed something curious: as far as I can tell no “mainstream” language contains support for graphs in its standard library. Trees yes, graphs no. The only language that comes even remotely close is C++ with Boost (which isn’t technically a “standard library”)

I’m not sure exactly why this is, but it’s got me wondering: are there any programming languages out there that come with solid support for graphs as part of their standard library?

Edit: To clarify: by “graph” I mean a network of nodes and edges; the sort of thing you’d run Dijkstra’s algorithm on, not a “graph” in the sense of “graphical display of data”.

11

One way of looking at this is that any time you have a data structure that references another data structure, you have some form of object graph. On that level, any object-oriented language supports a graph. Some languages are not object oriented and instead use a map to store related data structures. This also creates graphs of related maps, so any language with an associative array (PHP) or hashMap (Clojure, perl, etc) can make graphs with maps.

But I think you are asking why there aren’t more tookits that have something like

Node {
    Iterator<Node> getAdjacentNodes();
}

Graph {
    void putNode(Node n);
    Iterator<Node> getAllNodes();
}

Look at Datomic. Also triple-stores use something like this. Similarly, cross-reference (xref) tables in relational databases can be used to create arbitrary graphs of relationships.

Having said that, I might restate your question as “Why don’t more programming languages and tool-kits take a graph-based approach to problem decomposition?”

I think the answer is that efficient generic graph traversal is an NP-Hard problem lacking both a universal, efficient way to process graphs, and also a universal, efficient way to prove that a single solution is the most efficient one (e.g. the Travelling Salesman problem).

Graphs are absolutely essential for every CS student to learn because they deal with the most general relationships between data. Yet for that same reason, they should be your last choice for how to represent relationships. Most relationships are more specific. A car should only have one driver and one position on a given road at a time. There is generally no reason to join all cars with all possible drivers and all possible roads. Doing so would invite unnecessarily difficult problems. The more specific you can make the relationships between your objects or functions in your program design, the more you can optimize those relationships and the easier it is to understand and test them.

Finally, how do you traverse graphs? There is depth-first and breadth-first. Most programming languages make breadth-first traversal easy:

select * from passenger where car_id = 3;

myCar.getCurrentPassengers();

When you look at depth-first search, there is no one right way to do it. What’s the best road from New York to San Francisco? It’s solvable, but only by a fairly brute-force approach. If intersections are nodes and roads are edges, that doesn’t help you solve this problem. Far better is it to know something about the roads – which ones are interstates, have traffic lights or stop-signs, are under construction, are prone to traffic, are closed, or not built yet? Your NYC to San Fran route search might start with just interstates, then examine the angles of intersection where you change roads, or the maximum distance from a straight (well, curved around the globe) line. These are footholds to finding an optimal solution efficiently. They hint at places to check for more local roads that work around a less-than-ideal interstate solution. The details of the problem are exactly what makes real-time, real-world route finding possible. Yet the details are precisely the aspect of graph traversal that a generic API would not capture.

There could be myNode.setWeight(double d) and myNode.getWeight() methods, but they still don’t define an iteration order in a way that’s any better than you just adding a weight entry to your hashMap or weight field on your object. Also, there might be different weights for bicycle routes or public transit, or whatever. Would you have a set or hash of weights for every node? I guess I don’t see the use of a generic graph data structure because only the non-generic aspects of your data can make a graph traversable in anything close to polynomial time.

1

SWI Prolog includes support for W3C RDF, which is based on a graph data model (RDF triples can be considered to be a vertex-edge-vertex representation of graphs, a form of an adjacency list). There is support for transactions and on-disk storage. RDF seems to be the only model and a set of formats for storing and exchanging graph data that is in (relatively) common use today.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật