var array = new Array(1000);
document.getElementById("click").onclick = function() {myFormSubmit()};
function myFormSubmit() { //O(1)
var index_entered = document.getElementById("index_value").value; //O(1)
var number_entered = document.getElementById("number").value; //O(1)
document.getElementById('updated-array').innerHTML = InsertIntoArray(array, index_entered, number_entered); //O(1)
}
function InsertIntoArray(array, index, number) { //O(1)
for(var a=0; a<array.length;a++){ // O(N) //do multiple times
//array[a] = a;
array[a] = Math.floor((Math.random() * 100) + 1); // O(1)
}
//accept user input as number
array[index] = number; // O(1)
//printing output
var updated_array = "";
for (i = 0; i < array.length; i++) { // O(N)
updated_array += array[i] + " = Value of array index " + i + "<br>"; // O(1) //1000
}
return document.getElementById('updated-array').innerHTML = updated_array; // O(1)
}
// Count the number of operations performed on the array and output this to the screen.
document.getElementById('operations1').innerHTML = "Number of Operations:7018";
// Time Complexity using Big O Notation
document.getElementById('operations2').innerHTML = "Big O Notation Time Complexity: O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(n) + O(n) justifies to: O(n)";
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.