Analysis of graphs and adjacency matrices question
A step-by-step solution to a computer science exam question: how to determine the number of populated areas in a graph diagram using an adjacency table and arrive at the correct answer.
This article explains a computer science problem involving graph analysis and adjacency matrices to determine the number of settlements on a road map. It describes both a brief algorithm for solving similar problems and a detailed solution to a specific problem from the various exams.
Questions (on graphs) in Computer Science test students’ skills in analyzing and interpreting information presented in the form of diagrams, tables, or adjacency matrices. These tasks may include:
- determining the correspondence between vertices and numbers in the table;
- calculating the sum of road lengths between points;
- Finding the number of edges, vertex degrees, routes, or other properties of a graph.
Problem statement: The figure shows a diagram of roads between settlements (a graph), and the table shows an adjacency matrix, where the rows and columns correspond to each settlement. An asterisk (*) or a numeric value in a table cell indicates the presence of a road or its length between two settlements.
Specified graph properties are required —for example, vertex numbers, road length, the sum of distances between points, or the number of connections. The result is written as a number, a set of numbers, or another format specified in the problem.
Key concepts needed for solution:
- Scheme (graph) – vertices denote points, edges denote roads between them.
- Table (adjacency matrix) – N × N table where a cell indicates the presence of a road or its length.
- Undirected graph – the road can be used in any direction; sometimes there are directed graphs where the direction matters.
For a successful solution, it is important to be able to:
- analyze relationships on a graph;
- compare the data in the diagram and table;
- perform calculations with numbers if road lengths are given.
How to solve such problems?
The approach to solving such problems can be divided into several steps:
1. Graph analysis:
- Determine the degree of each vertex – the number of connections to other points.
- If road lengths are given, write them down separately for each pair of vertices.
- Find unique peaks or roads – they will help you quickly compare the diagram and the table.
2. Comparison of the data in the diagram and the table:
- Compare the connections between the nodes in the diagram and the data in the adjacency table.
- For vertices connected to known points, determine the missing properties (vertex numbers in the table, length of roads, number of connections or routes).
3. Calculation of the required values:
- If you need the sum of the lengths, add up the lengths of the required edges.
- If you need to count routes, connections, or vertex degrees, mark all the edges you count to avoid mistakes.
- Use the adjacency table to check the correctness of your calculations.
4. Recording the answer. Record the result in the format specified in the problem statement:
- an integer (for example, the sum of road lengths);
- a set of numbers in ascending order (for example, vertex numbers);
- other formats, if specified in the task.
Tips for beginners:
- Start with unique vertices or edges to quickly identify mappings.
- Always double-check the data in the diagram and table to avoid errors.
- For problems with long paths or sums, use notes or a table to ensure you don’t miss any edges.
- This algorithm is universal: it is suitable for all graph tasks on the Unified State Exam, including matching vertices, calculating the sum of road lengths, and counting connections.
Graph and Diagram

Problem Description: The figure shows a road map between settlements, and the table shows an adjacency matrix, where the rows and columns correspond to each point. An asterisk (*) in a table cell indicates the presence of a road between two points. The task is to determine which numbers in the table correspond to points B and E on the map and write them as two numbers in ascending order, without spaces or punctuation.
The problems in this Computer Science question use undirected graphs, meaning graphs without directions on their edges. This allows students to navigate between vertices in any direction. The key skill for solving the problem is analyzing relationships in the graph and matching them with an adjacency table.
Solution algorithm. Problems of this type are solved in sequential steps, where the step numbers are determined based on the number of connections (vertex degrees) and their interrelations.
Step 1. Identify unique vertices based on their number of edges. First, let’s carefully examine the diagram and count the number of connections for each vertex. Vertices with a unique number of edges allow us to uniquely match them with their numbers in the table.
Vertex A is connected to three points. Since there are no other vertices with this number of edges, A corresponds to number 3 in the table.

Vertex D is connected to five points. Since there are no other vertices with this degree, D corresponds to the number 7.

Step 2. Determine the numbers for vertices C and G. Once the numbers of vertices A and D have been determined, let’s turn our attention to vertices C and G, which are connected to these two points:
- Each of them has two connections: one leads to A (with three edges), the other to D (with five edges).
- There are only two numbers left in the table that meet these conditions: 1 and 4.
- The mutual distribution between C and G is irrelevant, since it does not affect the solution.

Step 3. Determine the number for vertex F. Vertex F has two connections, but is not connected to D.
Since vertex D is already associated with number 7, we need to find among the remaining numbers one that has two connections but is not connected to D . The only number that fits these conditions is 5. Thus, vertex F corresponds to number 5.

Step 4. Determine the numbers for vertices B and E. After matching all the remaining vertices, the numbers remaining are 2 and 6 :
Since all other vertices already have numbers, the remaining numbers are 2 and 6, which correspond to vertices B and E. The order in which the numbers are assigned to B and E is irrelevant, as the problem only requires them to be listed in ascending order.

In your answer, write the numbers of vertices B and E in ascending order, without spaces or punctuation. Therefore, the correct answer is 26 .
A variant from the demo version
Question: The figure shows a road map of the N-sky District. In the table, an asterisk indicates the presence of a road from one settlement to another. The absence of an asterisk means there is no such road.

Each settlement on the map corresponds to a number in the table, but the exact number is unknown. Determine which numbers in the table might correspond to settlements B and C on the map. In your answer, write these two numbers in ascending order without spaces or punctuation.
Solution:
We are given a road map (graph), where the vertices are labeled with letters (A, B, C, D, E, F, G), and an adjacency table, where the vertices are numbered from 1 to 7. We need to figure out which letter corresponds to which number, and then determine what numbers vertices B and C might have.
Step 1. Determine the degrees of the vertices. The degree of a vertex is the number of roads that exit it. On the graph:
- peaks A, B, C have 2 roads each;
- peaks D, E, F, G have 3 roads each.
In the adjacency table:
- vertices 3, 6, 7 are connected to exactly two others → degree 2;
- vertices 1, 2, 4, 5 are connected to three others → degree 3.
Hence:
- A, B, C ⇔ {3, 6, 7}
- D, E, F, G ⇔ {1, 2, 4, 5}
Step 2. Analyze vertices of degree 3. Now we look not only at the number of roads, but also at the neighbors of each vertex.
- Vertex 1 is connected to 2, 3, and 4. Among its neighbors, two have 3 roads (2 and 4), and one has 2 roads (3). In the graph, this corresponds to vertices F and G. Therefore, 1 is either F or G.
- Vertex 2 is connected to 1 (3 roads), 3 (2 roads), and 6 (2 roads). Two neighbors have 2 roads each, corresponding to vertices D or E. Therefore, 2 is either D or E.
- Vertex 4 is connected to 1 (3 roads), 5 (3 roads), and 7 (2 roads). Two neighbors have 3 roads, and one has 2 roads. Therefore, again, F or G.
- Vertex 5 is connected to 4 (3 roads), 6 (2 roads), and 7 (2 roads). Two neighbors with 2 roads and one with 3 are either D or E.

Step 3. Analyze vertices of degree 2. Now let’s analyze vertices {3, 6, 7}.
- Vertex 3 is connected to 1 and 2, so it fits either B or C.
- Vertex 6 is connected to 2 and 5 (both in {D, E}). Therefore, it is A.
- Vertex 7 is connected to 4 (F or G) and 5 (D or E). Therefore, it fits B or C.
Step 4. Final comparison:
- A → 6;
- B, C → 3 and 7.
Since the problem asks about vertices B and C, they correspond to numbers 3 and 7. In ascending order: 37.
Answer: 37.
Explore More IT Terms
#
- Using an integrating factor
- Equations in total differentials
- Bernoulli's equation
- Linear differential equations of the first order
- 10 Mixed C++ Challenges to Test Your Skills
- 11 Tricky Non-Technical Questions to Ask in a Recruiting Interview
- 50 Terms Every Programmer Should Know
- 52 Java Thread Interview Questions
- 7 Levels of Using the Zip Function in Python
- 7 Python Code Bugs You Need to Fix
- 70+ Free Resources for Learning Programming
A
- A Comprehensive Guide to HTML and CSS
- A Comprehensive Guide to MODX CMS
- A computer science question tests your ability to work with IP addresses and network masks
- A Guide to SQL Query Formatting for Beginners
- A/B testing
- Abstract Data Type (ADT)
- AES Encryption Algorithm: How It Works and Where It's Used
- Agile
- Algorithm
- Algorithm Analysis
- Algorithm Complexity-Key Points
- Algorithm complexity: deep parsing O(log n)
- Algorithm vs. Program
- Algorithms and Data Structures in C#
- An overview of the C # programming language
- An overview of the Python programming language
- Anaconda Python
- Analysis of graphs and adjacency matrices question
- Android
- Android App Bundle
- Android SDK
- Angular
- Ansible
- Apache
- Apache Airflow
- Apache Kafka
- Apache Tomcat
- App Store
- AppCode
- Applications of microcontrollers: From simple circuits in electronics to complex systems
- Applications of the derivative
- Arduino: How to Program It: Basics for Beginners
- Array-based stack
- ArrayList
- ASCII
- ASP.NET
- Assembly Language Lessons
B
C
- C++ Lessons
- Cache
- Calculating Memory Capacity
- Character sets and encodings
- Characteristics of a good Algorithm
- Circular singly linked list
- Combinational Circuits Solved Questions
- Compiler
- Complexity of algorithms-Tutorial
- Constants
- Creating a Table in HTML
- Creating Forms in HTML
- Creating Lists
- Cybernetics and informatics
- Cycles
D
- Data Analytics: applications of data analysis in companies
- Data Engineer - Who is it, what does a data engineer do, and an overview of the profession
- Data modeling: what it is, types, and process steps.
- Data preprocessing: a complete guide for beginners and professionals.
- Data structure
- Data Structures and Algorithms (DSA)
- Data types vs. Data structures
- Database Tests with Answers
- Deep Learning
- Defining Aliases
- Defining Arrays
- Deque
- Detailed articles and tutorials on PHP
- Developing a Website from Scratch
- Differential Equations
- Differentiation of functions
- Digital data: understand the importance of this asset for businesses.
- Double integrals
- Doubly linked lists
- DSA Tutorial
E
F
G
H
- Handling errors and exceptions
- Heads or Tails? How Probability Theory Is Used in IT
- History of the development of computer science
- Homogeneous equations
- Homogeneous vs. non-homogeneous structures
- How to effectively organize your workflow
- How to Learn Java: Tips for Beginner Developers
- How to Learn PHP: A Beginner's Guide
- How to Use S3 Storage in Kubernetes with CSI
- HTML
- HTML and CSS: Definition, Application, and Operating Principles
- HTML and CSS. Layout from Scratch: What to Learn, Where to Learn, and How Long Will It Take?
- HTML Frame Structure
- HTML Link Formatting
I
- if..else construction
- Infinite sequences and series
- Information properties
- Inheritance in Java: A Complete Guide to Principles and Implementation
- Inserting an Image
- Integration of functions
- Interactive Python Tutorial – Learn Programming from Scratch
- Interpreter
- Interview Problem: Finding a Deleted Element in O(N)
- Interview Scare: The FizzBuzz Challenge
- Introduction to C++
- Introduction to Machine Learning
- Introduction to Networking | Network Fundamentals Part 1
- Introduction to Number Systems (Binary, Octal, Hexadecimal) | Math for CS Foundations #1
- IT Specialist Resume (CV)
J
K
L
M
- Machine Learning
- Machine Learning Basic Tool: NumPy
- Machine Learning Basic Tool: Pandas
- Machine Learning Mathematics
- Mathematics for programmers: what is really needed?
- MD5 encryption algorithm: What is it and why is it needed?
- Microcontroller and Microprocessor - what's the difference?
- ML Engineer: Who They Are, What They Do, How Much They Earn, and How to Become a Neural Network Specialist
- Monte Carlo Simulation: How It Works and What It's For
O
P
- PHP lessons
- Private DNS server and its configuration
- Program code
- Programmer's Dictionary
- Programming
- Programming with pseudocode
- Python Code Formatting Guide: PEP8
- Python for data analysis: how to do it and main libraries
- Python Lessons
- Python Superstar: 5 Ways to Use the * Operator
- Python vs. Julia: Should You Replace Python with Julia?
R
S
- SFML Graphics Library Tutorials
- Sorting Algorithms in Programming: Types, Descriptions, and Comparisons
- SQL commands: see what they are, what the main ones are + examples
- SQL Interview Questions and Tasks
- SQL Lessons
- SQL Stored Procedures
- SQL Syntactic Sugar: The COALESCE Function
- Stack
- Start in analytics: Python or R
- Static vs. dynamic data structures
- Statistical analysis: importance for decision making.
- String formatting in Python
- Structure of computer science
- Swift Lessons
- switch/match construct
- Syntax
T
- Terms in programming
- Text and paragraph formatting tags
- The Complete Guide to Bootstrap
- The Complete Guide to JavaScript
- The concept of information and its transmission
- The Future of Python: Key Trends and Insights from Global Researc
- The Infrastructure of Code: A Complete Guide to Repositories for Languages, Frameworks, and Compilers
- The pip package manager in Python
- The role of informatization in the development of society
- Transfers
- Tricky Java Questions Often Asked in Interviews
- Tutorials / Articles
- TypeScript: What It Is and Why Developers Need It
W
- What are databases, and why do they need DBMS and SQL?
- What do Linux distributions consist of?
- What is .NET and what is it used for?
- What is a data structure?
- What is a GPU in a computer, in simple terms?
- What is a quantum computer: 100,500 problems in one second
- What Is an Algorithm?
- What is Arduino: How it Works and the Platform's Capabilities
- What is Big Data? Introduction, Types, Characteristics, and Examples
- What is FizzBuzz Challenge?
- What is Golang and what is it used for?
- What is Haskell and what is it used for?
- What is Kotlin and what is it used for?
- What is Linux? The History of Linux
- What is machine learning, and how does it work?
- What is Power BI: everything about the data analytics software
- What is recursion, recursive and iterative process in programming?
- What is the C++ programming language?
- What is the OSI Model: A Complete Explanation of the Seven Layers and Their Role in Networking
- What's the difference between x86 and ARM processors?
- Where to start learning the C programming language?
- Which Linux distribution should you choose? A Linux distribution overview
