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

There's an array named score, 90, 98, 92, 88, 100, 80 are the elements in this...
There's an array named score, 90, 98, 92, 88, 100, 80 are the elements in this array. Please write a Java program to declare and sort this array (use selection sort).
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.
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
In C++, cstring is implemented as an array of characters. What is the difference between cstring...
In C++, cstring is implemented as an array of characters. What is the difference between cstring and a regular array of characters? In other words, how do you distinguish them?
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...
The question: Write a program in Python that writes four random integers in range 1-100 on...
The question: Write a program in Python that writes four random integers in range 1-100 on a file named 'num.txt'. Write try-except block to handle at least two standard python error (any two errors). Hints: import random def main(): # Local variables # Open output file. # Write random numbers to the file. # Write it on to the file. # Close the file. # Call the main function. main() Here is my answer: please let me know if anything...
Question 1.) Discuss SBAR and how it is implemented.
Question 1.) Discuss SBAR and how it is implemented.
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.
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...
Write a Python function that will return the index of an element in a list.1- The...
Write a Python function that will return the index of an element in a list.1- The function will receive a list of at least 5 numbers as a single argument when the function is called. 2. The function will ask the user to input a number and will find and return the index of that number in the list.3. If the number is not an element of the list, the function returns the string "unknown."
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT