Questions
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses...

Please use Java language in an easy way with comments! Thanks!

Create a calculator that uses an array of buttons for numbers from 0-9, the . for decimals, and for operators +, -, * ,/ and = as well as a JTextfield that displays the current value or the result. Use ActionListeners and LayoutManagers appropriately.

The example below shows how to determine which button has been clicked.

ActionListener actionListener = new ActionListener()
 {
     public void actionPerformed(ActionEvent actionEvent) 
     {
        System.out.println(actionEvent.getActionCommand());
     }
 };

In: Computer Science

Due Thursday  (Normal late penalties apply for late submission.) Respond to the following in a minimum of...

Due Thursday  (Normal late penalties apply for late submission.)

Respond to the following in a minimum of 175 words (20 points):

Today's datacenters are populated with not only physical hardware but systems hosting virtual machines and containers. These systems communicate locally and around the globe over networks.

Discuss two different examples of threats to various parts of heterogeneous architectures and how they might manifest. Do not forget about the hardware, operating systems, applications, networks, and other integral parts. Discuss the threats in your classmates' posts.

In: Computer Science

Could you please write an article on Software Engineering Trends in about 300 words? Please, also...

Could you please write an article on Software Engineering Trends in about 300 words? Please, also provide appropriate references. Please, do not plagiarize your answer.

In: Computer Science

A)Given a generic array with ‘n’ items (not only integers). Give a solution for checking whether...

A)Given a generic array with ‘n’ items (not only integers). Give a solution for checking whether there are any duplicate elements in the array or not? You just need to return a boolean (true or false). State the complexity of your solution. Can you come up with another solution that has O(n logn) complexity? Explain.

B) Now consider the same problem as Question A, but this time you only have positive integer numbers ranging from 0 to (n-1) in the array. Can you find a duplicate in O(n) complexity? Implement the solution.

In: Computer Science

Explain virtualization as a key technology in cloud computing environments, as well as the purpose of...

Explain virtualization as a key technology in cloud computing environments, as well as the purpose of a virtualization environment.

In: Computer Science

A system is set up to take raw grading information from the console and calculate a...

A system is set up to take raw grading information from the console and calculate a consolidated grade. The information comes in as a single line with last name, first name, homework grade ( a total out of 20 ), lab grade ( a total out of 50 ), exam grade average, and a letter ( upper or lower ) indicating Audit, Passfail, or Grade.

Sample input:                    Mary(first name) Poppins(last name) g(indication) 17(homework grade) 28(lab grade) 87(exam grade)

A program should be written that takes the input data and calculates a consolidated grade based upon 10% Homework, 20 % Lab , and 70% Exams. The output should be formatted with no decimals.

first initial last name - final grade  

for a pass/fail student output should indicate only Pass or Fail . For an audit output should say not gradeable.

Using C++

In: Computer Science

I have an 8 by 8 array that has values ranging from 1-64. I am wanting...

I have an 8 by 8 array that has values ranging from 1-64. I am wanting to display the array evenly but due to some digits being single and others double, it displays lopsided. What would be the best way to get everything in the array to display in a nice even square?

In: Computer Science

Which business or industry sectors have the most startups companies that consider a small and medium...

Which business or industry sectors have the most startups companies that consider a small and medium enterprise (SME's)? To what extent the enterprise systems is important in this era? please support your answer by giving an example?

In: Computer Science

Explain how advances in technology can force a software subsystem to undergo change or run the...

Explain how advances in technology can force a software subsystem to undergo change or run the risk of becoming useless.

In: Computer Science

Look up and use each of these Linux commands. (Each command will have two parts) Summarize...

  1. Look up and use each of these Linux commands. (Each command will have two parts)
    • Summarize their function then use the command
    • Use the Command and document the output (<parameters of your choice>
    • Command Function
      info cat
      Demonstrate 'cat' in use  
      man cp
      Demonstrate 'cp' in use  
      man touch
      Demonstrate 'touch' in use  
      man mv
      Demonstrate 'mv' in use  
      man rm
      Demonstrate 'rm' in use  
      info wc
      Demonstrate 'wc' in use  
      man find
      Demonstrate 'find' in use  
      man chmod
      Demonstrate 'chmod' in use  
      man chown
      Demonstrate 'chown' in use
      Lookup append ">>" operator online
      Demonstrate '>>' in use  
      Lookup redirection ">" operator online
      Demonstrate '>' in use  
      Lookup another command not previously covered
      Use that command

PART B (50 total pts) - File Operations (Windows)

  1. Look up and use each of these MSDOS commands. (Each command will have two parts).
    • Summarize their function then use the command
    • Use the Command and document the output
    • Command Function
      help type
      Demonstrate 'type' in use  
      help copy
      Demonstrate 'copy' in use  
      help xcopy
      Demonstrate 'xcopy' in use  
      help move
      Demonstrate 'move' in use  
      help del
      Demonstrate 'del' in use  
      Demonstrate 'find' in use  
      Demonstrate 'find' with parameters to get Word Count
      help attrib
      Demonstrate 'attrib' with parameters to get Word Count
      help rmdir
      Demonstrate 'rmdir' with parameters to get Word Count
      Look append ">>" operator online
      Demonstrate '>>' in use
      Look redirection ">" operator online
      Demonstrate '>' in use  
      help whoami
      Demonstrate 'whoami' in use  
      Lookup another command not previously covered
      Use that command

In: Computer Science

Our next optimization comes from using the brilliant Rabin-Karp substring matching algorithm (RK for short), invented...

Our next optimization comes from using the brilliant Rabin-Karp substring matching algorithm (RK for short), invented in the eighties by two famous computer scientists, Michael Rabin and Richard Karp 3. RK checks if a given query string P appears as a substring in Y. At a high level, RK works by computing a hash for the query string, hash(P ), as well as a hash for each of the n − k + 1substrings of length k in Y, hash(Y [0...k − 1]), hash(Y [1...k]), ..., hash(Y [n − k...n − 1]). A hash function turns any arbitrary string into a b-bit hash value with the property that collision (two different strings with the same hash value) is unlikely. Therefore, by comparing hash (P) with each of the n − k + 1 hashes from Y, we can check if P appears as a substring in Y. There are many nice hash functions out there (such as MD5, SHA-1), but RK's magical ingredient is its "rolling" hash function. Specifically, given hash(Y [i...i + k − 1]), it takes only constant time instead of O(k) time to compute hash(Y [i + 1...i + k]). Now we explain how the rolling hash is computed. Let's treat each character as a digit in radix-d notation. We choose radix d = 256 since each character in the C language is represented by a single byte and we can conveniently use the byte value of the character as its digit. For example, the string 'ab' corresponds to two digits with one being 97 (the ASCII value of 'a'), and the other being 98 (the ASCII value of 'b'). The decimal value of 'ab' in radix-256 can be calculated as 256 ∗ 97 + 98 = 24930. The hash of a string P in RK is hash(P[0...k−1])=256?−1 ∗P[0]+256?−2∗P[1]+...+256∗P[k−2]+P[k−1]].

COMPLETE THE RABIN_KARP MATCH FUNCTION ONLY

Now let's see how to do a rolling calculation of the values for every substring of Y.

Let ?? = hash(Y [0...k − 1] and yi = hash(Y [i...i + k − 1]). We can compute ??+1 from ?? in constant time, by observing that

??+1 =256∗(?? −256?−1∗Y[i])+Y[i+k]

Note that we have to remember the value of 256?−1 in a variable instead of re-computing it for?? each time. Now we've seen how rolling hash works. The only fly in the ointment is that these radix-256 hash values are too huge to work with efficiently and conveniently. Therefore, we perform all the computation in modulo q, where q is chosen to be a ????? 4 ????? 5. Hash collisions are infrequent, but still possible. Therefore once we detect some ?? = hash(P ), we should compare the actual strings Y [i...i + k − 1] and P [0...k − 1] to see if they are indeed identical. Since RK speeds up substring matching to O(n) on average instead of O(n ∗ k) as in the simple algorithm. However, we still need to run RK [?? ] times for each of the [?? ] chunks of X to be matched in Y. Thus, our approximate matching algorithm using RK has an overall runtimeO ( ?? * n )

Your job: Implement the RK substring matching algorithm by completing therabin_karp_match for each chunk of X to bet matched. When calculating the hash values, you should use the given modulo arithmetic functions madd, mdel, mul

As with simple_match, our main procedure will invoke rabin_karp_match for each chunk of X to be matched. rabin_karp_match has the same interface as simple_match and should return 1 if the chunk appears as a substring in Y or 0 if otherwise.

Complete the following function:

* Match every k-character snippet of the query_doc document
   among a collection of documents doc1, doc2, ....

   ./rkmatch snippet_size query_doc doc1 [doc2...]

*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <strings.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>

#include "bloom.h"

enum algotype { SIMPLE = 0, RK, RKBATCH};

/* a large prime for RK hash (BIG_PRIME*256 does not overflow)*/
long long BIG_PRIME = 5003943032159437;

/* constants used for printing debug information */
const int PRINT_RK_HASH = 5;
const int PRINT_BLOOM_BITS = 160;

/* modulo addition */
long long
madd(long long a, long long b)
{
   return ((a+b)>BIG_PRIME?(a+b-BIG_PRIME):(a+b));
}

/* modulo substraction */
long long
mdel(long long a, long long b)
{
   return ((a>b)?(a-b):(a+BIG_PRIME-b));
}

/* modulo multiplication*/
long long
mmul(long long a, long long b)
{
   return ((a*b) % BIG_PRIME);
}

/* read the entire content of the file 'fname' into a
   character array allocated by this procedure.
   Upon return, *doc contains the address of the character array
   *doc_len contains the length of the array
   */
void
read_file(const char *fname, char **doc, int *doc_len)
{
   struct stat st;
   int fd;
   int n = 0;

   fd = open(fname, O_RDONLY);
   if (fd < 0) {
       perror("read_file: open ");
       exit(1);
   }

   if (fstat(fd, &st) != 0) {
       perror("read_file: fstat ");
       exit(1);
   }

   *doc = (char *)malloc(st.st_size);
   if (!(*doc)) {
       fprintf(stderr, " failed to allocate %d bytes. No memory\n", (int)st.st_size);
       exit(1);
   }

   n = read(fd, *doc, st.st_size);
   if (n < 0) {
       perror("read_file: read ");
       exit(1);
   }else if (n != st.st_size) {
       fprintf(stderr,"read_file: short read!\n");
       exit(1);
   }
  
   close(fd);
   *doc_len = n;
}


/* The normalize procedure examines a character array of size len
   in ONE PASS and does the following:
   1) turn all upper case letters into lower case ones
   2) turn any white-space character into a space character and,
   shrink any n>1 consecutive spaces into exactly 1 space only
           Hint: use C library function isspace()
   You must do the normalization IN PLACE so that when the procedure
   returns, the character array buf contains the normalized string and
   the return value is the length of the normalized string.
*/
int
normalize(char *buf,   /* The character array containing the string to be normalized*/
                   int len           /* the size of the original character array */)
{
   int start_index=0; //starting index
   int new_index=0; //index returning the new position

   //for loop iterating over the characters in the array
   for (start_index=0;start_index<len;start_index++)
   {
       //checks if the character is an uppercase
       if(isupper(buf[start_index]))
       {
           buf[new_index++]=tolower(buf[start_index]); //coverts the upper case character to a lower case and the new index changes position
       }
       else if (!isupper(buf[start_index])&& !isspace(buf[start_index])) //handles if its not an upper case and not a space
       {
           buf[new_index++]=buf[start_index];
       }

       //removes the consecutive spaces
       else if(isspace(buf[start_index])){
           if ((start_index>0) && (start_index < (len-1)) && !isspace(buf[start_index-1])){
               buf[new_index++]=' ';

           }

   }
}

//removes the trailing spaces at the end
if (isspace(buf[len-1])) //if the last character is a string
{
   return new_index-1; //returns the character before the last that is not a space
}

else{

   return new_index;
}
}

/* check if a query string ps (of length k) appears
   in ts (of length n) as a substring
   If so, return 1. Else return 0
   You may want to use the library function strncmp
   */
int
simple_match(const char *ps,   /* the query string */
                       int k,                    /* the length of the query string */
                       const char *ts,   /* the document string (Y) */
                       int n                       /* the length of the document Y */)
{
   int i;
   for (i=0;i<n;i++){ //for loop iterating
       if (strncmp(&ts[i],ps,k)==0) //library function that compares if the query string appears in the other document
       {
           return 1; //if it matches it will return 1
       }
   }
  
   return 0; //if it doesnt, it returns 0
}
      

/* Check if a query string ps (of length k) appears
   in ts (of length n) as a substring using the rabin-karp algorithm
   If so, return 1. Else return 0
   In addition, print the first 'PRINT_RK_HASH' hash values of ts
   Example:
   $ ./rkmatch -t 1 -k 20 X Y
   605818861882592 812687061542252 1113263531943837 1168659952685767 4992125708617222
   0.01 matched: 1 out of 148
   */

COMPLETE THIS FUNCTION ONLY
int
rabin_karp_match(const char *ps,   /* the query string */
                               int k,                    /* the length of the query string */
                               const char *ts,   /* the document string (Y) */
                               int n                       /* the length of the document Y */ )
{
   return 0;
}

/* Initialize the bitmap for the bloom filter using bloom_init().
   Insert all m/k RK hashes of qs into the bloom filter using bloom_add().
   Then, compute each of the n-k+1 RK hashes of ts and check if it's in the filter using bloom_query().
   Use the given procedure, hash_i(i, p), to compute the i-th bloom filter hash value for the RK value p.

   Return the number of matched chunks.
   Additionally, print out the first PRINT_BLOOM_BITS of the bloom filter using the given bloom_print
   after inserting m/k substrings from qs.
*/
int
rabin_karp_batchmatch(int bsz, /* size of bitmap (in bits) to be used */
int k, /* chunk length to be matched */
const char *qs, /* query docoument (X)*/
int m, /* query document length */
const char *ts, /* to-be-matched document (Y) */
int n /* to-be-matched document length*/)
{
   return 0;
}

In: Computer Science

Search the Internet to find (at least 2 websites) related to the general field of malware....

Search the Internet to find (at least 2 websites) related to the general field of malware. Please provide a brief synopsis of the website. Post the links

In: Computer Science

Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following...

Consider the following schema:

Suppliers(sid, sname, address)

Parts(pid, pname, color)

Catalog(sid, pid, cost)

write the following queries in SQL:

* Find the names of all suppliers who supply a green part.

*Find the names of all suppliers who are from Illinois.

*Find the names of all suppliers who sell a red part costing less than $100.

*Find the names and colors of all parts that are green or red.

In writing these queries you may make the following assumptions:

a. Each part has only one color.
b. A cost field is a real number with two decimal places (e.g., 100.25, 93.00).
c. The sid field in Suppliers and the sid field in Catalog refer to the same field.
d. The
pid field in Parts and the pid field in Catalog refer to the same field.

In: Computer Science

CS2123 Data Structures - Fall 2019 Assignment 1: Function Runtimes Table Due 9/11/19 by 11:59pm Completing...

CS2123 Data Structures - Fall 2019 Assignment 1: Function Runtimes Table Due 9/11/19 by 11:59pm Completing the Program (15 points) This program prints a table of runtimes (these are displayed in seconds) for given functions on arrays. The program tests different array sizes to establish a relationship between input size and runtime. It tests each array size multiple times and then takes an average of the times. Here are example calls to the timing functions: int sizes[] = { 1000, 2500, 5000, 7500, 10000}; char str1[] = "Insertion Sort"; char str2[] = "quicksort (uses insertion sort when sorting <30 numbers)"; fRT = timeAlgorithm(str1, 10, 5, sizes, insertionSortInitial ); printRuntimeTable(fRT); freeFunctionRuntimes(fRT); fRT = timeAlgorithm(str2, 10, 5, sizes, quickSortOptInitial ); printRuntimeTable(fRT); freeFunctionRuntimes(fRT); This results in following table: Note your runtimes may vary since the test data is randomly generated. The runtimes are stored in a functionRuntimes struct. You are completing a program to create and fill data in this struct, print the data of this struct, and free this struct. You are given a partial implementation in the fle “cs2123HW1-LastName.c”. Specifically you are tasked to complete the funtctions below the heading “Functions for finding and printing runtime”. No other functions should be changed. Using the Program (5 points) After you have the program completed, you should use it to help determine the asymptotic runtimes of the three mystery functions (i.e., mysteryRuntime1, mysteryRuntime2, mysteryRuntime3). Be sure to also examine the code of the mystery functions to confirm/improve your estimations. Fill in the following table in the provided file: /* TODO: Give your asymptotic estimates for the runtimes of the following 3 functions: mysteryRuntime1: O( ) mysteryRuntime2: O( ) mysteryRuntime3: O( ) */ Deliverables: Your solution should be submitted as “cs2123HW1-LastName.c” where “LastName” is replaced with your last name. Be sure to fill in the table of runtimes described above: Upload this file to Blackboard under Assignment 1. Do not zip your file. To receive full credit, your code must compile and execute. You should use valgrind to ensure that you do not have any memory leaks.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

const char DATA_FILE_NAME[] = "TestData.txt";

typedef struct functionRuntimes
{
    char *szName;             //name of the function being tested
    double **arrRuntimes;         //run times
    double *arrAvg;            //average runtime
    int iNumRepeats;       //number of times to repeat each test size
    int iNumTestCaseSizes;   //number of test case sizes
    int *arrTestSizes;     //array containing the test case sizes
} functionRuntimes;

//Functions used to test the runtimes
functionRuntimes timeAlgorithm( char*, int, int, int[], void (*f)(FILE *) );
FILE *generateTestInput( int, int, int );
void computeAvg( functionRuntimes fRT );
void printRuntimeTable( functionRuntimes fRT );
void freeFunctionRuntimes( functionRuntimes fRT );

//Functions whose runtime will be tested (and helper functions)
void insertionSortInitial( FILE* input );
void insertionSort( int* points, int low, int high );
void quickSortOptInitial( FILE* input );
void quickSortOpt( int* points, int low, int high );
int partition( int* points, int low, int high );

void mysteryRuntime1( FILE* input );
void mysteryRuntime2( FILE* input );
void mysteryRuntime3( FILE* input );

/*
 * Provided code - DO NOT CHANGE THIS METHOD
 * (if you make alterations plan to revert them before submission)
 */
int main( int argc, char *argv[] )
{
    functionRuntimes fRT;

    int sizes1[] = { 2000, 4000, 8000, 16000, 32000, 64000, 128000};

    srand(time(0));

    fRT = timeAlgorithm("Insertion Sort", 10, 3, sizes1, insertionSortInitial );
    printRuntimeTable(fRT);
    freeFunctionRuntimes(fRT);

    fRT = timeAlgorithm("quicksort (uses insertion sort when sorting <30 numbers)", 10, 6, sizes1, quickSortOptInitial );
    printRuntimeTable(fRT);
    freeFunctionRuntimes(fRT);

    fRT = timeAlgorithm("Mystery 1", 5, 6, sizes1, mysteryRuntime1 );
    printRuntimeTable(fRT);
    freeFunctionRuntimes(fRT);

    fRT = timeAlgorithm("Mystery 2", 5, 4, sizes1, mysteryRuntime2 );
    printRuntimeTable(fRT);
    freeFunctionRuntimes(fRT);

    fRT = timeAlgorithm("Mystery 3", 5, 4, sizes1, mysteryRuntime3 );
    printRuntimeTable(fRT);
    freeFunctionRuntimes(fRT);

    return 0;
}

/*************************************** Functions to have their runtimes tested *********************************************/

/* provided code - DO NOT CHANGE
 */
void mysteryRuntime1( FILE* input )
{
    int temp;
    int size;
    int i=0;
    int *array;

    if( fscanf( input, "%d", &size ) != 1 )
    {
        exit(-1);
    }
    array = (int *) malloc( size*sizeof(int) );
    if( array == NULL )
    {
        exit(-1);
    }

    while( fscanf( input, "%d", &temp ) == 1 && i<size)
    {
        array[i] = temp;
        i++;
    }

    while( size>1 )
    {
        size = size/2;
        array[size/2] = array[size];
    }

    free(array);
}

/* provided code - DO NOT CHANGE
 */
void mysteryRuntime2( FILE* input )
{
    int temp;
    int size;
    int n;
    int i=0;
    int *array;

    if( fscanf( input, "%d", &size ) != 1 )
    {
        exit(-1);
    }
    array = (int *) malloc( size*sizeof(int) );
    if( array == NULL )
    {
        exit(-1);
    }

    while( fscanf( input, "%d", &temp ) == 1 && i<size)
    {
        array[i] = temp;
        i++;
    }

    for( i=0; i<size; i++ )
    {
        for( n=size-1; n>1; n/=1.01 )
        {
            array[n-1] = array[n];
        }
    }

    free(array);
}

/* provided code - DO NOT CHANGE
 */
void mysteryRuntime3( FILE* input )
{
    int temp;
    int size;
    int i=0, j=0;
    int *array;

    if( fscanf( input, "%d", &size ) != 1 )
    {
        exit(-1);
    }
    array = (int *) malloc( size*sizeof(int) );
    if( array == NULL )
    {
        exit(-1);
    }

    while( fscanf( input, "%d", &temp ) == 1 && i<size)
    {
        array[i] = temp;
        i++;
    }

    i=0;
    while( j<size )
    {
        array[j] = array[i];

        i++;
        if( i>=size )
        {
            j++;
            i=0;
        }
    }

    free(array);
}


/*
 * Provided code - DO NOT CHANGE THIS METHOD
 */
void insertionSortInitial( FILE* input )
{
    int i;
    int size;
    int *array;

    fscanf( input, "%d", &size );
    array = (int *) malloc( size*sizeof(int) );

    for( i=0; i<size; i++)
    {
        fscanf( input, "%d", &array[i] );
    }

    insertionSort( array, 0, size-1 );

    //Error check to verify the array is sorted
    /*for( i=1; i<size; i++)
    {
        if(array[i-1]>array[i])
        {
            printf("Not sorted!");
            exit(-1);
        }
    }*/

    free(array);
}

/*
 * Provided code - DO NOT CHANGE THIS METHOD
 */
void insertionSort( int* points, int low, int high )
{
    int i, j;
    double temp;

    for( i = low+1; i <= high; i++)
    {
        for( j = i; j > low && points[j]<points[j-1]; j--)
        {
            temp = points[j];
            points[j] = points[j-1];
            points[j-1] = temp;
        }
    }
}

/*
 * Provided code - DO NOT CHANGE THIS METHOD
 */
void quickSortOptInitial( FILE* input )
{
    int i;
    int size;
    int *array;

    fscanf( input, "%d", &size );
    array = (int *) malloc( size*sizeof(int) );

    for( i=0; i<size; i++)
    {
        fscanf( input, "%d", &array[i] );
    }

    quickSortOpt( array, 0, size-1 );

    //Error check to verify the array is sorted
    /*for( i=1; i<size; i++)
    {
        if(array[i-1]>array[i]){
            printf("Not sorted!");
            exit(-1);
        }
    }*/

    free(array);
}

/*
 * Provided code - DO NOT CHANGE THIS METHOD
 */
void quickSortOpt( int* points, int low, int high )
{
    if( high < low+30 )
    {
        insertionSort( points, low, high );
    }
    else
    {
        int pivot = partition( points, low, high );

        quickSortOpt( points, low, pivot-1 );
        quickSortOpt( points, pivot+1, high );
    }
}

/*
 * Provided code - DO NOT CHANGE THIS METHOD
 */
int partition( int* points, int low, int high )
{
    int pivot = rand() % (high - low + 1) + low;
    int pivotValue = points[pivot];
    int i = low+1;
    int j = high;
    int temp;

    points[pivot] = points[low];
    points[low] = pivotValue;

    while( i<j )
    {
        while( i<=high && points[i] <= pivotValue )
        {
            i++;
        }
        while( j>=low && points[j] > pivotValue )
        {
            j--;
        }
        if(i<j)  //swap out of order elements
        {
            temp = points[i];
            points[i] = points[j];
            points[j] = temp;
        }
    }
    if( i<=high && points[i] <= pivotValue )
    {
        i++;
    }

    points[low] = points[i-1];
    points[i-1] = pivotValue;

    return i-1;
}

/*************************************** Functions for finding and printing runtime *********************************************/

/*
TODO: Give your asymptotic estimates for the runtimes of the following 3 functions:

mysteryRuntime1:  O(   )
mysteryRuntime2:  O(   )
mysteryRuntime3:  O(   )
*/


/* TO BE COMPLETED BY YOU
 * Fill in the missing parts of the code (see TODOs below)
 */
functionRuntimes timeAlgorithm( char *szName, int iNumRepeats, int iNumTestCaseSizes, int arrTestSizes[], void (*f)(FILE *) )
{
    /* Call and calculate the runtime of the provided function f */
    clock_t start, end;
    int i, j;
    FILE *testData;

    //create functionRuntimes variable to return
    functionRuntimes fRT;

    //TODO: copy passed data into the fRT variable.  Specifically do the following:
    /* fill szName in fRT with the variable szName */
    /* fill iNumRepeats in fRT with the variable iNumRepeats */
    /* fill iNumTestCaseSizes in fRT with the variable iNumTestCaseSizes */
    /* malloc space for arrTestSizes in fRT to hold iNumTestCaseSizes number of ints */
    /* fill arrTestSizes in fRT with the variable arrTestSizes (hint: use a loop) */



    //TODO: malloc an array with iNumTestCaseSizes variables of type double* (on next line)
    fRT.arrRuntimes = NULL; /* replace NULL with your code */
    for( i=0; i<iNumTestCaseSizes; i++ )
    {
        //TODO: malloc an array with iNumRepeats variables of type double (on next line)
        //fRT.arrRuntimes[i] = NULL; /* replace NULL with your code and uncomment the line */

        for( j=0; j<iNumRepeats; j++ )
        {
            //Generate test data for the function f
            testData = generateTestInput( 0, arrTestSizes[i], arrTestSizes[i] );

            //Run f on the generated test data
            start = clock();
            f( testData );
            end = clock();
            fclose(testData);

            //Enter the elapsed number of seconds into the arrRuntimes array for fRT
            //TODO: uncomment the next line line after you've malloc-ed memory for fRT.arrRuntimes
            //fRT.arrRuntimes[i][j] = (double)(end - start) / CLOCKS_PER_SEC;
        }
    }

    //TODO: Calculate the average runtimes (malloc space for fRT.arrAvg and call computeAvg here)

    return fRT;
}

/*
 * Provided code - DO NOT CHANGE THIS METHOD
 */
FILE *generateTestInput( int min, int max, int size )
{
    int i;
    FILE *data = fopen( DATA_FILE_NAME, "w" );

    if( data==NULL )
    {
        printf("Failed to create file %s\n", DATA_FILE_NAME);
        exit(-1);
    }

    //add size to start of file
    fprintf( data, "%d ", size );
    //Fill the file with random data
    for( i=0; i<size; i++ )
    {
        fprintf( data, "%d ", rand()%(max-min+1)+min );
    }
    fclose(data);

    data = fopen( DATA_FILE_NAME, "r" );
    if( data==NULL )
    {
        printf("Failed to create file %s\n", DATA_FILE_NAME);
        exit(-1);
    }
    return data;
}

/* TODO: TO BE COMPLETED BY YOU
 * Calculate and insert the average runtime for each set of test data into fRT
 */
void computeAvg( functionRuntimes fRT )
{

}

/* TODO: TO BE COMPLETED BY YOU
 * Print the information in fRT as a 2d table.  Display 3 digits after the decimal point.  You can assume all of the runtimes are <= 99.999 seconds.
 */
void printRuntimeTable( functionRuntimes fRT )
{

}

/* TODO: TO BE COMPLETED BY YOU
 * Free all of the dynamically allocated memory in fRT
 */
void freeFunctionRuntimes( functionRuntimes fRT )
{

}

In: Computer Science

Question 2. Design a 16-1 MUX using any number of lower MUXs, such as 8-1 or...

Question 2.

Design a 16-1 MUX using any number of lower MUXs, such as 8-1 or 4-1 only. No other gates are allowed.

In: Computer Science