特定の行列がC++でハンケルであるかどうかを確認します
正方行列があるとすると、その行列がハンケル行列であるかどうかを確認することがタスクです。ハンケル行列は正方行列であり、左から右への各昇順スキュー対角要素は一定です。行列が次のようなものであると仮定します-
1 | 2 | 3 | 4 | 5 |
2 | 3 | 4 | 5 | 6 |
3 | 4 | 5 | 6 | 7 |
4 | 5 | 6 | 7 | 8 |
5 | 6 | 7 | 8 | 9 |
行列がハンケル行列であるかどうかを確認するには、mat [i、j] =a i + jであるかどうかを確認する必要があります。 か否か。 a i + j -
として定義できます
$$ a_ {i + j} =\ begin {cases} mat [i + j、0]
例
#include <iostream> #define N 5 using namespace std; bool isHankelMat(int mat[N][N], int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i + j < n) { if (mat[i][j] != mat[i + j][0]) return false; } else { if (mat[i][j] != mat[i + j - n + 1][n - 1]) return false; } } } return true; } int main() { int n = 5; int mat[N][N] = { { 1, 2, 3, 4, 5}, { 2, 3, 4, 5, 6}, { 3, 4, 5, 6, 7}, { 4, 5, 6, 7, 8}, { 5, 6, 7, 8, 9} }; if(isHankelMat(mat, n)) cout << "This is Hankel Matrix"; else cout << "This is not Hankel Matrix"; }
出力
This is Hankel Matrix
-
特定のツリーグラフが線形であるかどうかをC++で確認します
ここでは、ツリーグラフが線形であるかどうかを確認する方法を説明します。線形ツリーグラフは1行で表すことができます。これが線形ツリーグラフの例であると仮定します。 しかし、これは線形ではありません- グラフが線形であるかどうかを確認するには、2つの条件に従うことができます ノードの数が1の場合、ツリーグラフは線形です ノードの(n – 2)が次数2の場合 例 #include <iostream> #include <vector> #define N 4 using namespace std; class Graph{ p
-
与えられた二分木がAVL木であるかどうかをチェックするC++プログラム
AVLツリーは自己平衡二分探索木であり、左右のサブツリーの高さの差がすべてのノードで複数になることはありません。 これは、特定のバイナリツリーがAVLツリーであるかどうかを確認するためのC++プログラムです。 アルゴリズム Begin function AVL() returns true if the given tree is AVL otherwise false. if(root == NULL) return 1 leftheight = height(root->left) &nb