Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For assignments 1 and 2 your Big-O notation and justification will be written in

ID: 665013 • Letter: F

Question

For assignments 1 and 2 your Big-O notation and justification will be written in the html section of JSFiddle.

Assignment 1 - Using your JSFiddle account and JavaScript you will create a program that will instantiate an integer array of size 1000. Fill each array element with a random integer between 1 and 100. You will need to research the random function to do this.

You will write a function with 3 arguments. The name of the function will be InsertIntoArray. Argument 1 is the array, argument 2 is the index of where you are going to insert a new number, argument 3 is the number to insert. The program should insert the new number at the index given and shift all the previous entries index up by 1. Count the number of operations performed on the array and output this to the screen.

Experiment with different sized arrays and inserting into a different index in the array. State using Big O Notation your time complexity and be prepared to justify your answer.

Assignment 2 - Using your JSFiddle account and Javascript you will create a program that will instantiate an integer array of size 1000. Fill each array element with a random integer between 1 and 100. You will need to research the random function to do this.

You will write a function with 2 arguments. The name of the function will be SearchArray. Argument 1 is the array, argument 2 is the value you are searching for within the array. Each time the program compares 2 numbers you must count it as an operation. Output the total number of operations. State using Big O Notation your time complexity and be prepared to justify your answer. Please include screenshots or links to the Fiddle for reference. Thank you!

Explanation / Answer

a)

var array = [];
for(var i=1; i<=1000; i++) {
   array.push(Math.random()*100);
}

function InsertIntoArray(array,index,number){
   array[index]=number;
   var count=0;
   for(var i=number;i>0;i--){
       array[index-1]=array[index];
       count+=1;
   }
   document.write(count);
}


b)

var array = [];
for(var i=1; i<=1000; i++) {
   array.push(Math.random()*100);
}

function SearchArray(array,number){
   var count=0;
   for(var i=0;i<1000;i++){
       if(array[i]==number){
           document.write("Found");
           count+=1;
       }
   }
   document.write(count);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote