• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Apriori algorithm C Code Data Mining

November 29, 2015 by Dhaval Dave

Apriori Algorithm  is an algorithm for data mining of frequent data set and association rule learning over transactional databases. It identifies the frequent individual items in the database for example, collections of items bought by customers. Lets take simple Example

Suppose you have records of large number of transactions at a shopping center as follows:

Transactions Items bought
T1 A, B, C
T2 A, B
T3 B, C, D
T4 A, B, F

For example in the above table you can see A and B are bought together frequently.

How Does This Algorithm works ?

Step 1 : Count each items occurrence  say A came 3, B – 3, C – 2, D – 1, F -1 time.
Step 2 : Remove entries which are very low in count say D,F.
Step 3 : Count Pair wise occurrence and Create table.
_PS : this step we can do for A,B,C or A,B the way clients or we need aggregation.
OP : AB-3, BC-2, AC-1,
Step 4 :  Declare highest occurring items as AB.

Clear your Java Concept with this top java books 

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
 FILE *fin;
 int i,cols,rows,*count;
 char val;
 if(argc!=2)
 {
  return 1; 
 }
 fin = fopen(argv[1],"r");

//finding the number of cols
 cols=0;
 fscanf(fin,"%c",&val);
 while(1)
 {
  if(val=='\n')
  break;
  if(val!=' ')
  cols++;
  fscanf(fin,"%c",&val);
 }
 printf("\nNumber of columns = %d\n",cols);
 fclose(fin);
 fin = fopen(argv[1],"r");
 //Generation of 1 item frequent items

 count = (int*)malloc(sizeof(int)*cols);

 for(i=0;i<cols;i++)
 {
  count[i] =0;
 }

 while(!feof(fin))
 {
  for(i=0;i<cols;i++)
  {
   fscanf(fin,"%c",&val);
   if(val=='1')
   count[i]++;
   fscanf(fin,"%c",&val);
  }
 }
 //Generation of 1-item frequent sets completed!!

 printf("\n1-item frequent item sets..\n");
 for(i=0;i<cols;i++)
 {
  printf("\n%d -> %d",i+1,count[i]);
 }
 fclose(fin);
 return 0;
}


Similar Articles

Filed Under: Algorithm, Data Mining, Interview Questions, problem Tagged With: c

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Circular Linked List

Find shortest distances between every pair of vertices ( Dynamic Programming Floyd Warshall Algorithm)

Test Cases for Round Function

Convert Decimal to Roman numbers / Romanizer HackerEarth Code

DFS (Depth First Search)

Get K Max and Delete K Max in stream of incoming integers

Find the element that appears once others appears thrice

Hackerearth : Counting Subarrays

Skiing on Mountains Matrix

C++ OOPs Part2

Binary Tree in Java

Password Predictor

Implement a generic binary search algorithm for Integer Double String etc

Knight Tour Problem (Graph – Breadth First Search)

Number of Islands BFS/DFS

Generate next palindrome number

Given Set of words or A String find whether chain is possible from these words or not

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

FizzBuzz Solution C C++

Templates in C++

Convert number to words java

Reverse a Linked List in groups of given size

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

25 horses 5 tracks Find 3 fastest puzzle

strtok()

Given a sorted array and a number x, find the pair in array whose sum is closest to x

write a c program that given a set a of n numbers and another number x determines whether or not there exist two elements in s whose sum is exactly x

Find loop in Singly linked list

Find next greater number with same set of digits

The Magic HackerEarth Nirvana solutions Hiring Challenge

Copyright © 2025 · Genesis Framework · WordPress · Log in