Question

In: Computer Science

Question 1) In a circular array implemented in Python: blockCapacity=100, dataStartIndex=88, dataCount=43. What is the index...

Question 1) In a circular array implemented in Python: blockCapacity=100, dataStartIndex=88, dataCount=43. What is the index of the last data item?

Answer:

Consider dynamic arrays with geometric expansion and no shrinking. Match operations to their complexity.

Always choose the most informative answer. For instance, if an operation is O(1) and O(n) choose O(1); if an operation is O(1) and O(1) amortized, choose O(1).

Options to choose from are: O(1), O(1) amortized or O(n)

addFirst :

len (length/size) :

deleteLast :

deleteFirst :

addLast (append) :

Solutions

Expert Solution

Data will start from index 88 and every next available space is filled with data. When end of array is reached, start from starting element. Here, started from 88 and went till 99, so total of 12 elements here. After that start from index 0 and fill the leftover data. Leftover data count is 31. So, starting from index 0, index 30 will have the last data item.

Python code:

n = int(input("Enter the blockSize: "))

a = [0]*n

start = int(input("Enter the startIndex: "))
data = int(input("enter the data count: "))

last = -1
for i in range(data):
index = (start + i)%n
a[index] = 1
last = index

print("Index of last data item is",last)
  

Output:


Related Solutions

What is an array data structure? What is an array index? What are the benefits of...
What is an array data structure? What is an array index? What are the benefits of array structures? What are the drawbacks of array structures? What is a grid structure? Give examples of when an array could be used. Give examples of when a grid could be used.
Python Question: Write a function that checks to see if an array of integers is sorted...
Python Question: Write a function that checks to see if an array of integers is sorted in an increasing fashion, returning true if it is, false otherwise. Test it with at least4 arrays - 2 sorted and 2 not sorted. Use a CSV formatted input file as described in the previous question to run your program through some tests, where again the filename is passed as an argument. Heres what I have so far: import sys # command line arguement...
Scores are 92, 68, 88, 96, 72, 88, 80, 64, 74, 92, 100, 84   What is...
Scores are 92, 68, 88, 96, 72, 88, 80, 64, 74, 92, 100, 84   What is the IQR? 19 19.5 20.5 20 6
On a circular array with n positions, we wish to place the integers 1, 2, ......
On a circular array with n positions, we wish to place the integers 1, 2, ... r in order, clockwise, such that consecutive integers, including the pair (r,1) are not in adjacent positions on the array. Arrangements obtained by rotation are considered the same. In how many ways can this be done? Give a combinatorial proof.
Question 1.) Discuss SBAR and how it is implemented.
Question 1.) Discuss SBAR and how it is implemented.
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...
1. An array has an index of [5] at the starting address of 200. It has...
1. An array has an index of [5] at the starting address of 200. It has 3 words per memory cell, determine loc[3],loc[4] and NE. (3 Marks: 1 mark for each) 2. A 2-D array defined as A[10 , 5] requires 4 words of storage space for each element. Calculate the address of A[4,3] given the base address as 250 • If the array is stored in Row-major form • If the array is stored in Column-major form 3. Write...
1.What is the circular flow of income? What are the four key markets of the circular...
1.What is the circular flow of income? What are the four key markets of the circular flow model? 2. Why is the aggregate demand curve for goods & services inversely related to the price level? What does this inverse relationship indicate? 3. What are the major factors that influence the quantity of goods & services a group of people can produce in the long run? 4. Why is the long run aggregate supply curve (LRAS) vertical? What does the vertical...
Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1...
Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console. In C++. Thank you!
1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT