
use code below in part with bts
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct node_struct {
int item;
struct node_struct *next;
} node;
/**
* 10->NULL
* We want to insert 20
* First call ([10], 20) [not complete]
* {10, {20, NULL}}
To compute the conditional probabilities you need to determine unigram and
bigram counts first (you can do this in a single pass through a file if you do things
carefully) and store them in a Binary Search Tree (BST). After that, you can compute
the conditional probabilities.
Input files
Test files can be found on (http://www.gutenberg.org/ebooks/). For example,
search for “Mark Twain.” Then click on any of his books. Next download the “Plain
Text UTF-8” format.
In addition, you should test your
can hand-compute the correct answer.
Output files
Your program must accept the name of an input file as a command line argument.
Let's call the file name of this file fn. Your program must then produce as output the
following set of files:
• Your program must write the unigram counts to a file named fn.uni in which
each unigram is listed on a separate line, and each line contains just the
unigram and its count (an integer), separated by a single space.
• Your program must write the bigram counts to a file named fn.bi in which
each bigram is listed on a separate line, and each line contains just the
bigram and its count (an integer), separated by a single space.
• Your program must write the conditional probabilities to a file named fn.cp,
reported in the form P(WORD(k)|WORD(k-1)) = p, where p is the conditional
probability of WORD(k) given WORD(k-1).
Notes
• You may use any BST implementation found online at your own risk
(provided the source of this code is cited properly). 50 marks bonus would
be given if you implemented the BST yourself (only the functionalities
needed to complete your project).
• Your program should accept file name(s) as command line argument(s) (no
hard-coded file names in your code).
• Your code will be tested using the latest version of the GNU C compiler on a
Unix-based
may want to use Windows Subsystem or a Virtual Box under your own
responsibility!
• Your code must be well commented. When writing your comments, you
should focus on what the code does at a high level; for example, describe the
main steps of an
• A ReadMe.txt file (including instructions on how to compile and how to run
your program along with any known problems) must be submitted
*
![Submission details: Make a directory and name it, using your first and last names,
applying the camel notation, for example haniGirgis. Please name the main file,
where execution starts, as hw2.cpp. Compress your directory by the zip utility, and
submit the compressed file using Blackboard.
Introduction
Suppose you had a document (perhaps a newspaper article, or an unattributed
manuscript for a book), and you were interested in knowing who wrote it. One way
to try to determine the authorship of the anonymous document is by comparing
properties of the anonymous document with properties of known documents, and
seeing if there is enough similarity to make a judgment of authorship.
Some simple properties one might use to distinguish different authors include:
Vocabulary (ie. the set of words an author uses).
• Word frequencies (i.e. the frequencies with which an author uses words).
Bigram frequencies (i.e. the frequencies of two consecutive words).
Bigram probabilities (i.e. the probability that one word follows another
word).
Terminology
A unigram is a sequence of words of length one (i.e. a single word).
• A bigram is a sequence of words of length two.
• The conditional probability of an event E2 given another event E1, written
p(E2|E1), is the probability that E2 will occur given that event E1 has already
occurred.
We write p(w(k)]w(k-1)) for the conditional probability of a word w in position k,
w(k), given the immediately preceding word, w(k-1). You determine the conditiona
probabilities by determining unigram counts (the number of times each word
appears, written c(w(k)), bigram counts (the number of times each pair of words
appears, written c(w(k-1) w(k)), and then dividing each bigram count by the
unigram count of the first word in the bigram:
p(WORD(k)|WORD(k-1)) = c(WORD(k-1) WORD(k}) / {WORD(k-1))
For example, if the word "time" occurs seven times in a text, and "time of" occurs
three times, then the probability of "of occurring after "time" is 3/7.
Project description
In this project, you will be determining conditional probabilities of bigrams. To do
this, you will write a C program, which reads in a file of text and produces three
output files, as described below.](https://content.bartleby.com/qna-images/question/157e66f5-e794-4af2-988e-1885b818a80a/dd08679a-84d9-4f01-a19c-0902ccbe11ac/lrf6pg_thumbnail.jpeg)

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images

- please go in to the detail and explain in detail the purpose and function to each line & function of code listed below. #include <stdio.h>#include <stdlib.h> struct node{int data;struct node *next;}; struct node *head, *tail = NULL; void addNode(int data) {struct node *newNode = (struct node*)malloc(sizeof(struct node));newNode->data = data;newNode->next = NULL; if(head == NULL) {head = newNode;tail = newNode;}else {tail->next = newNode;tail = newNode;}} void removeDuplicate() {struct node *current = head, *index = NULL, *temp = NULL; if(head == NULL) {return;}else {while(current != NULL){temp = current;index = current->next; while(index != NULL) {if(current->data == index->data) {temp->next = index->next;}else {temp = index;}index = index->next;}current = current->next;}}} void display() {struct node *current = head;if(head == NULL) {printf("List is empty \n");return;}while(current != NULL) {printf("%d ", current->data);current =…arrow_forwardhello. This is my code: #include <stdio.h>#include <stdlib.h>#include <string.h> typedef struct HuffmanNode { int character; float frequency; struct HuffmanNode* left; struct HuffmanNode* right;} HuffmanNode; typedef struct HeapNode { HuffmanNode* node; struct HeapNode* next;} HeapNode; HuffmanNode* create_huffman_node(int character, float frequency) { HuffmanNode* node = (HuffmanNode*)malloc(sizeof(HuffmanNode)); node->character = character; node->frequency = frequency; node->left = NULL; node->right = NULL; return node;} HeapNode* create_heap_node(HuffmanNode* node) { HeapNode* heap_node = (HeapNode*)malloc(sizeof(HeapNode)); heap_node->node = node; heap_node->next = NULL; return heap_node;} HeapNode* insert_into_heap(HeapNode* heap, HuffmanNode* node) { HeapNode* heap_node = create_heap_node(node); if (heap == NULL) { return heap_node; } // Compare nodes based on probability and…arrow_forwardBelow is the C++ codes for traversing a linked list. Re-arrange them in proper order. Drag and drop the C++ statements to their proper order. Make sure you use proper indentions. Drag from here nodePtr nodePtr->next; }}} cout value previous; }}} cout << "The List is empty!" << endl;arrow_forward
- please go in to the detail and explain the purpose and function to each line & function of code listed below. Dsecribe each line. #include <stdio.h>//including headers#include <string.h>#include <stdlib.h> struct node{//structure intialization int data; struct node *next; }; #include <assert.h> typedef struct Info_ { char name[100]; } Info; typedef struct Compar_ { Info info; struct Compar_* next; } Compar; void print_comparisons(Compar* CP)//comparison method { assert(CP); Compar* cur = CP; Compar* next = cur->next; for (; next; cur = next, next = next->next) { if (strcmp(cur->info.name, next->info.name) == 0) printf("Same name\n"); else printf("Diff name\n"); } } struct node *head, *tail = NULL; void addNode(int data) {//adding node method struct node *newNode = (struct node*)malloc(sizeof(struct node)); newNode->data = data; newNode->next = NULL; if(head == NULL) { head = newNode; tail = newNode; } else { tail->next =…arrow_forwardint tryMe(int x[], int size); void main() { int list[75]; cout<< tryMe (list, 75); } valid invalidarrow_forwardWrite a user defined function named as “length_list” function that finds the length of a list of list_node_t nodes. This code should fit with the following code.Partial Code: #include <stdio.h> #include <stdlib.h> /* gives access to malloc */ #define SENT -1 typedef struct list_node_s { int digit; struct list_node_s *restp; } list_node_t; list_node_t *get_list(void); int main(void) { list_node_t *x;int y; x=get_list(); printf("%d\n",x->digit); printf("%d\n",x->restp->digit); printf("%d\n",x->restp->restp->digit); // your length_list function should be called from here printf("Length is: %d",y); } /* * Forms a linked list of an input list of integers * terminated by SENT */ list_node_t * get_list(void) { int data; list_node_t *ansp; [20]scanf("%d", &data); if (data == SENT) { ansp = NULL; } else { ansp = (list_node_t *)malloc(sizeof (list_node_t)); ansp->digit = data; ansp->restp = get_list(); } return (ansp);arrow_forward
- // FILL IN THE BLANKS (LINKED-LISTS CODE) (C++)#include<iostream>using namespace std; struct ________ {int data ;struct node *next; }; node *head = ________;node *createNode() { // allocate a memorynode __________;temp = new node ;return _______ ;} void insertNode(){node *temp, *traverse;int n;cout<< "Enter -1 to end "<<endl;cout<< "Enter the values to be added in list"<<endl;cin>>n; while(n!=-1){temp = createNode(); // allocate memorytemp->data = ________;temp->next = ________;if ( ___________ == NULL){head = _________;} else {traverse = ( );while (traverse->next != ________{traverse = traverse-> ___________;} traverse->next= temp;} cout<<"Enter the value to be added in the list"<<endl;cin>>n; }} void printlist(){node *traverse = head; // if head == NULLwhile (traverse != NULL) { cout<<traverse->data<<" ";traverse = traverse->next;}} int main(){int option; do{cout<<"\n =============== MAIN…arrow_forwardHow to write reporting function on this question This program implements the buying and selling of stocks. It starts by printing a welcome message Welcome to mystocks.com Then a main menu of choices for the user is output. Reporting, buying or selling? (0=quit, 1=report, 2=buy, 3=sell): The program ends with a goodbye message. Thank you for trading with mystocks.com Use doubly linked list of stock_t structures. stock_t structure looks like: #define MAX_TICKER_LENGTH 6 typedef struct stock_t { char ticker[MAX_TICKER_LENGTH]; date_t date; // date bought int numShares; double pricePerShare; } stock_t; date_t structure looks like: typedef struct date_t { int month, day, year; } date_t; Create the following files in a directory: date.h: contains the above date_t structure • stock.h and stock.c: contain the stock structure and any constants and stock function prototypes. Eg: a print stock function. • node.h, node.c: contain at least the node typdef and initNode function •…arrow_forward#include <iostream>#include <list>#include <string>#include <cstdlib>using namespace std;int main(){int myints[] = {};list<int> l, l1 (myints, myints + sizeof(myints) / sizeof(int));list<int>::iterator it;int choice, item;while (1){cout<<"\n---------------------"<<endl;cout<<"***List Implementation***"<<endl;cout<<"\n---------------------"<<endl;cout<<"1.Insert Element at the Front"<<endl;cout<<"2.Insert Element at the End"<<endl;cout<<"3.Front Element of List"<<endl;cout<<"4.Last Element of the List"<<endl;cout<<"5.Size of the List"<<endl;cout<<"6.Display Forward List"<<endl;cout<<"7.Exit"<<endl;cout<<"Enter your Choice: ";cin>>choice;switch(choice){case 1:cout<<"Enter value to be inserted at the front: ";cin>>item;l.push_front(item);break;case 2:cout<<"Enter value to be inserted at the end:…arrow_forward
- Exercise 1 Write a function called nested_sum that takes a list of lists of integers and adds up the elements from all of the nested lists. For example: >>> t = [[1, 2], [3], [4, 5, 6]] >>> nested_sum(t) 21arrow_forwardHAPTER 5: Lists and Dictiona st membership > 51621 O WorkArea Instructions eadline: 03/ 11:59pm EDT Given that k contains an integer and that play_list has been defined to be a list, write a expression that evaluates to True if the value assigned to k is an element of play_list. Additional Notes: play_list and k should not be modifiedarrow_forward#ifndef NODES_LLOLL_H#define NODES_LLOLL_H #include <iostream> // for ostream namespace CS3358_SP2023_A5P2{ // child node struct CNode { int data; CNode* link; }; // parent node struct PNode { CNode* data; PNode* link; }; // toolkit functions for LLoLL based on above node definitions void Destroy_cList(CNode*& cListHead); void Destroy_pList(PNode*& pListHead); void ShowAll_DF(PNode* pListHead, std::ostream& outs); void ShowAll_BF(PNode* pListHead, std::ostream& outs);} #endif #include "nodes_LLoLL.h"#include "cnPtrQueue.h"#include <iostream>using namespace std; namespace CS3358_SP2023_A5P2{ // do breadth-first (level) traversal and print data void ShowAll_BF(PNode* pListHead, ostream& outs) { cnPtrQueue queue; CNode* currentNode; queue.push(lloLLPtr->getHead()); while (!queue.empty()) { currentNode = queue.front(); queue.pop(); if…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





