Table of Contents Preface Breadth-first traversal (BFS) 1.Basic concepts 2. Algorithm process Breadth-first traversal of the graph 1. Adjacency matrix 2. Adjacency list 3. Algorithm comparison Foreword In the last issue, we learned the depth-first traversal of the graph, (depth-first traversal: graph traversal —- depth-first (DFS) traversal – CSDN blog), then in this issue we […]
Tag: traversal
Graph Theory 03-[Unweighted and Undirected]-Depth-first DFS traversal of graphs-path problem/detection cycle/bipartite graph
Article directory 1. Code warehouse 2. Single source path 2.1 Ideas 2.2 Main code 3. All point-pair paths 3.1 Ideas 3.2 Main code 4. Optimization of path problem-end recursion early 4.1 Ideas 4.2 Main code 5. Detection loop 5.1 Ideas 5.2 Main code 6. Bipartite graph 6.1 Ideas 6.2 Main code 6.2.1 Traverse each connected […]
Binary tree traversal algorithm and use of stack
Foreword Before starting to talk about this issue, everyone needs to know how the stack is used. Many people will say, “It’s just the last in, last out.” Then I will start today’s explanation with a problem that everyone should have encountered in the data structure class: using the stack, input [A, B, C] ( […]
[Data structure] Linear list (4) Various operations of doubly linked list (insertion, deletion, search, modification, traversal and printing)
Table of Contents The definition of linear tables and their basic operations (sequential table insertion, deletion, search, modification) 4. Linked storage structure of linear table 1. Single linked list 2. Circular linked list 3. Doubly linked list a. Doubly linked list node structure b. Create a new node c. Insert node at the end of […]
Graph traversal-depth-first (DFS) traversal
Table of Contents Preface Depth-first traversal (DFS) 1. Basic concepts 2.Algorithmic thinking 3. Depth-first traversal of binary trees (example) Depth first traversal of graph 1. Depth-first traversal of graph adjacency matrix Idea analysis Code 2. Depth-first traversal of graph adjacency list Idea analysis Code recursive code non-recursive code 3. Comparison between adjacency matrix and adjacency […]
Binary tree-detailed explanation of binary tree traversal (C language version)
Foreword I have not found time to update due to academic reasons, because the binary tree part is still difficult for beginners, and the school teacher also teaches it relatively quickly. Many students have learned very little. I hope this article can provide some information for everyone’s learning. help. Pre-order traversal of a binary tree […]
Graph Theory 02-[Unweighted and Undirected]-Depth-First Traversal DFS of Graphs
Article directory 1. Code warehouse 2. Depth-first traversal diagram 3. Main code 3.1 The main code of dfs recursion – pre-order traversal and post-order traversal 3.2 dfs non-recursive main code – using stack 3.3 The order of recursive and non-recursive traversal is inconsistent 3.4 Marking different connectivity components 4. Complete code 4.1 CC.java 4.2 Graph.java […]
Three traversal methods of ordinary binary trees: front, middle and back
What is a binary tree? Binary Tree is a tree-like data structure in which each node has at most two child nodes, usually called left child node and right child node. Each node contains a value or data element and can contain references to its child nodes. The structure of a binary tree is composed […]
Binary trees; pre-order, in-order, post-order traversal and search of binary trees; sequential storage of binary trees; threaded binary trees
Analysis of array, linked list and tree storage methods For tree structures, whether it is searching for modifications or additions and deletions, the efficiency is relatively high. It combines the advantages of linked lists and arrays, such as the following binary tree: 1. The first element of the array is used as the first node […]
Several traversal methods of HashMap? How to choose which one to use?
There are many HashMap traversal methods, and different JDK versions have different writing methods. Among them, JDK 8 provides 3 HashMap traversal methods, and breaks the embarrassment of “very bloated” previous traversal methods in one fell swoop. 1.Traversal before JDK 8 Before JDK 8, EntrySet and KeySet were mainly used for traversal. The specific implementation […]