Question

In: Computer Science

Which of the following operations for an array takes the mosttime to complete?Setting the...

Which of the following operations for an array takes the most time to complete?



Setting the value of an element at a given index



inserting an element at a given index



Returning the size of the array



Returning the value of an element at a given index

Solutions

Expert Solution

b) inserting an element at a given index

inserting an element at a given index takes a time complexity of O(n)

all other operations only takes a constant time of O(1)


Related Solutions

Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output of longestMorseCodeWords should be an array of the strings that were passed in, but ordered by the length of their Morse Code equivalent in descending order. If the length of Morse Code is equal, order the words alphabetically.For convenience, the full table for the 26 letters of the English alphabet is given below: [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] let words = ["gin", "zen", "gig", "msg"] longestMorseCodeWords(words) The Morse...
In C++ Write a function which takes two parameters: an array of ints and an int...
In C++ Write a function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. As an example, if the array has the following 10 elements: 2 5 8 9 7 1 0 2 6 3, your function should print out 8 9 7 6. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void...
Using Javascript, complete the following /************************************************************************** * * Array callback filtering * **************************************************************************/ /** * Write...
Using Javascript, complete the following /************************************************************************** * * Array callback filtering * **************************************************************************/ /** * Write and export a function named "everyEven" which takes an array and a test * function for checking individual elements of the array. The "everyEven" * function should test the even elements of the array and return true only * if at least one of the even elements passes the test. * * @param arr An array whose even elements should be tested * @param...
Which row has the largest sum? Write a method that takes a 2D int array and...
Which row has the largest sum? Write a method that takes a 2D int array and prints: of The index of the row that has the largest sum The sum of elements in that row java
Write a C++ function which takes an int array and its size as parameters. It returns...
Write a C++ function which takes an int array and its size as parameters. It returns an int indicating how many multiples of 3 are contained in the array. For example, if the array contains {2, 6, 8} your function should return 1. If the array contains {3, 10, 5, 6} your function should return 2. Here is the function prototype: // int array[]: array to search // size: number of elements in the array int countMult(const int array[], int...
Two individuals invest in a project which takes two periods to complete. At the start of...
Two individuals invest in a project which takes two periods to complete. At the start of period one, individual A invests 4.5 and individual B invests 1.5. At the end of period one, each of the investors has a chance to withdraw her investment. The decisions whether to withdraw from the project or not are made simultaneously. If either investor withdraws, the project is scrapped and the scrapped value is 4. If both investors withdraw, they shared the scrapped value...
Explain the following:( I ) Complete elimination of corruption. ( II ) Setting practical goals with...
Explain the following:( I ) Complete elimination of corruption. ( II ) Setting practical goals with achievable targets. ( III ) Emphasis on development of human capital in the country as well as awareness amongst the masses about the development plans. ( IV ) Decentralization of execution and accountability to be entrusted to the masses for local execution of the plans. ( V ) Development plans should be designed after widespread consultation with important stakeholde
Complete the following C# code that declares an array of 7 integers. The application allows the...
Complete the following C# code that declares an array of 7 integers. The application allows the user three options: l. to view the elements of array in reverse order, from the last to first position, 2. to choose a specific position to view, 3. quit the program
Write a complete C program to do the following:(i) Define a function Nodeptr CreateDLL(char str[])which takes...
Write a complete C program to do the following:(i) Define a function Nodeptr CreateDLL(char str[])which takes a string as parameter and creates a Doubly Linked List of characters and returns the pointer to the first node. (ii) Define a function int IsPalindrome(Nodeptr first)to check whether the string represented by the above doubly linked list pointed to by first, is a palindrome or not and return 1/0 accordingly. Do not use any additional data structure.Write a main function to read a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT