void TimeComplexity::union_tracktime(string listname1, string listname2, string listname3) { time_actual = 0; long n_1 = all_lists->getN(listname2); long n_2 = all_lists->getN(listname3); long n_low, n_hi; if(n_1 > n_2) { n_low = n_2; n_hi = n_1; } else { n_low = n_1; n_hi = n_2; } //union's algorithm 5*(n_low + n_low*n_low+ n_hi*n_hi) how I got 5 is in the README long tc_estimate = 5*(n_low + n_low*n_low+ n_hi*n_hi); long c = 8; long upper_bound = c*((n_hi*n_hi) + (n_low*n_low)); // n^2 is the upper bound or O(n^2), since bubble sort is used to alphabetize all_lists->union_initialize(listname3, listname2, listname1, "iterative"); // calling the actual union function to calculate the TIME_ACTUAL stringstream ss; //outputting all data in CSV format ss<<n_1<<","<<n_2<<","<<"union,"<<tc_estimate<<","<<time_actual<<","<<c<<",64,"<<upper_bound; string result = ss.str(); output(result, "append"); return; }
void StackContainer::postfixCalc(string listID) { Node* current = postfix_list->head; string s1, s2, itos; stringstream ss; int i = 0; while(current != NULL) { if(current->word == "+") { //creates a list named "union#" where # is an arbitrary iterator used to distinguish multiple unions in a single expression //pushes the name to the stack in order to use it for the next operation //However, if it is the last node in the list, it is the final operation which means the list should be instead named listID s1 = pop(); s2 = pop(); if(s1 == "" || s2 == "") { error("Stack underflow, not enough arguments for union for operation involving " +listID); break; } if(current->next == NULL) { all_lists->union_initialize(s1, s2, listID, "recursive"); break; } ss << i; itos = ss.str(); all_lists->union_initialize(s1, s2, "union"+itos, "recursive"); push("union"+itos); i++; current = current->next; ss.str(""); ss.clear(); continue; } if(current->word == "*") { //creates a list named "intersection#" where # is an arbitrary iterator used to distinguish multiple intersections in a single expression //pushes the name to the stack in order to use it for the next operation //however, if it is the last node in the list, it is the final operation which means the list should be instead named listID s1 = pop(); s2 = pop(); if(s1 == "" || s2 == "") { error("Stack underflow, not enough arguments for intersection for operation involving " +listID); break; } if(current->next == NULL) { all_lists->intersect_initialize(s1, s2, listID, "recursive"); break; } ss << i; itos = ss.str(); all_lists->intersect_initialize(s1, s2, "intersect"+itos, "recursive"); push("intersect"+itos); i++; current = current->next; ss.str(""); ss.clear(); continue; } //if not + or *, it must be an operand, and operands get pushed to stack push(current->word); current = current->next; i++; } while(pop()!=""); //clears the stack of anything left over if the expression was not legal }