WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Data Structures & Algorithms · Intermediate · question 27 of 100

What is a directed and undirected graph? Provide examples of each type.?

📕 Buy this interview preparation book: 100 Data Structures & Algorithms questions & answers — PDF + EPUB for $5

A graph is a data structure that consists of a set of vertices (nodes) and a set of edges that connect pairs of vertices. A directed graph, also known as a digraph, is a graph in which each edge has a direction, indicating that the edge connects one vertex to another in a specific direction. An undirected graph is a graph in which each edge has no direction, indicating that the edge connects two vertices without a specific direction.

Here are examples of directed and undirected graphs:

Directed graph: A social media platform that models friendships between users as directed edges. If user A is friends with user B, there is a directed edge from A to B. This graph is directed because the relationship between users is not necessarily mutual - user A can be friends with user B without user B being friends with user A.

Undirected graph: A map that models the connections between cities as edges. If there is a road that connects city A to city B, there is an undirected edge between A and B. This graph is undirected because the connection between cities is bidirectional - if there is a road from A to B, there is also a road from B to A.

In general, directed graphs are useful for modeling relationships that have a specific direction, such as the flow of traffic on a road network or the dependencies between tasks in a project. Undirected graphs are useful for modeling relationships that are bidirectional, such as the connections between nodes in a computer network or the relationships between items in a recommendation system.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Data Structures & Algorithms interview — then scores it.
📞 Practice Data Structures & Algorithms — free 15 min
📕 Buy this interview preparation book: 100 Data Structures & Algorithms questions & answers — PDF + EPUB for $5

All 100 Data Structures & Algorithms questions · All topics