FP tree 算法 C++ 实现

本文详细介绍了如何使用C++实现FP树算法,通过示例展示了如何处理交易数据,生成条件模式基,并通过递归生成频繁模式。文章涵盖了FP树的构建、条件树生成及其在单路和多路径情况下的应用。
摘要由CSDN通过智能技术生成
// FP.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <list>

using namespace std;


const int kMinSupport = 2;
map<list<string>, int>  FreqPattern;



struct TreeNode {
  int count;
  string tag;
  map<string, TreeNode*> children;
  TreeNode* parent;
  TreeNode* Sibling;

  TreeNode(string tag, TreeNode* parent, int count = 1) : tag(tag), parent(parent), count(count) {
    Sibling = NULL;
    children.clear();
  }

  bool IsRoot() {
    return (parent == NULL);
  }

  void dump(int k) {
    for(int i = 0; i < k; i++) {
      printf("--------");
    }
    if (IsRoot()) {
      printf("\nRoot \n");
    } else {
      printf("%s:%d \n", tag.c_str(), count);
    }
    map<string, TreeNode*>::iterator  it;
    for(it = children.begin(); it != children.end(); it++) {
      printf("|");
      it->second->dump(k+1);
    }
  }
};



void GenConditionalTree(map<vector<string>, int>& Task, 
                        map<string, TreeNode*>& head,
                        TreeNode& root,
                        map<string, int>& FreqTable,
                        vector<string>& rank,
                        bool prune);



map<string, int>* gFreqTable = NULL;
bool Compare(string a, string b) {
  int aw = (*gFreqTable)[a];
  int bw = (*gFreqTable)[b];
  return (aw > bw);
}



void GenPermutation(vector<string>& prefix_set, int start, list<string>& result, int freq, int suffix_len) {



  // last one;
  if (sta
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值