Question

In: Computer Science

1a) If I'm writing a program which involves many insertion and deletion operations, and memory is...

1a) If I'm writing a program which involves many insertion and deletion operations, and memory is not a concern, which of the following should I choose to hold my data?

A: linked list

B: fixed-size array

C: dynamic array

D: any of the above

1b) What about if I'm writing a program and I want the program to be flexible on the data with various sizes, and the program also needs to provide fast access to the data? Which of those should I choose to hold my data?

Solutions

Expert Solution

1.)
a)
A - Linked List

- We will use linked list in this case where insertion and deletion are frequent as time complexity for inserion and deletion for a Linked List is O(1).
- Whereas, in case of array, both static and dynamic, in case of deletion and insertion, we need to copy elements from one array to other to perform either deletion or insertion. It will cost us time complexity of O(N) where N is number of elements already present in the array. (As we need to traverse all elements to perform copy)


1.)
b)
I will use Dynamic Array in such a case,

- It is so because, in case of dynamic array, I am being flexible on the data. I can add new data also if the size is more.
- As stated, we need a fast access to data. It means searching operation is the priority. As we know that array elements are accessed via known indexes, so element with in a array list can be searched / accssed in O(1) time complexity.
- So, we will prefer dynamic array for this use case


* Here O() means the Big O notation to find the running time of an algorithm.


Kindly upvote if this helped


Related Solutions

Binary Tree Develop algorithms for performing various operations of binary tree like insertion and deletion of...
Binary Tree Develop algorithms for performing various operations of binary tree like insertion and deletion of elements, finding an element in the binary tree. Analyse time and space complexity of the designed algorithm Write C++ program to implement binary tree
a) Which lines of code contain operations that change the contents of memory in this program?...
a) Which lines of code contain operations that change the contents of memory in this program? b) What are those operations? int main ( void ){             double dScore1;             double dScore2;             double dScore3;             double dAverage;             printf("Enter score 1: ");                                             //line 1             scanf("%lg", &dScore1);                                           //line 2             printf("Enter score 2: ");                                             //line 3             scanf("%lg", &dScore2);                                           //line 4             printf("Enter score 3: ");                                             //line 5             scanf("%lg", &dScore3);                                           //line 6             dAverage = (dScore1 + dScore2...
I'm writing a program that requires that I use the check sum technique with a for...
I'm writing a program that requires that I use the check sum technique with a for loop. A student enters their seven digit ID number. The seventh digit is determined from the other digits by this formula: 7th digit = (1 *(1st digit) + 2 * (2nd digit) + ... + 6 * (6th digit)) %10. The program should prompt users to enter a 7-digit number, and print valid if the actual 7th digit matches the computed 7th digit. Basicaly,...
This project involves writing a program to calculate the terms of the following sequence of numbers:...
This project involves writing a program to calculate the terms of the following sequence of numbers: 0 1 1 3 5 11 21 43 … where each term is twice the second previous term plus the previous term. The 0th term of the sequence is 0 and the 1st term of the sequence is 1. The example below shows how to calculate the next sequence term: Current sequence: 0 1 Calculate next term: 2 * 0 + 1 = 1...
I'm writing a program using EasyReader class. The program wil give me the how much money...
I'm writing a program using EasyReader class. The program wil give me the how much money is left. e.g. someone paid 50 pounds for their 20 pounds worth of groceries so the output will be 30 pounds. my question is, I want it to print out how the change should be made up. how many 10 pounds, 5 pounds, 2 pound and so on, is in the change. how should I write the program
The sixth assignment involves writing a Python program to read in the temperatures for ten consecutive...
The sixth assignment involves writing a Python program to read in the temperatures for ten consecutive days in Celsius and store them into an array. The entire array should then be displayed. Next each temperature in the array should be converted to Fahrenheit and the entire array should be again be displayed. The formula for converting Celsius to Fahrenheit is °F = (°C × 1.8) + 32. Finally, the number of cool, warm and hot days should be counted and...
This involves writing a Python program to determine the body-mass index of a collection of six...
This involves writing a Python program to determine the body-mass index of a collection of six individuals. Your program should include a list of six names. Using a for loop, it should successively prompt the user for the height in inches and weight in pounds of each individual. Each prompt should include the name of the individual whose height and weight is to be input. It should call a function that accepts the height and weight as parameters and returns...
The second assignment involves writing a Python program to compute the price of a theater ticket....
The second assignment involves writing a Python program to compute the price of a theater ticket. Your program should prompt the user for the patron's age and whether the movie is 3D. Children and seniors should receive a discounted price. There should be a surcharge for movies that are 3D. You should decide on the age cutoffs for children and seniors and the prices for the three different age groups. You should also decide on the amount of the surcharge...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want to plot a 3D animated orbit which is a 60 by 58 nautical miles orbit. Can you provide a code or some idea of how to plot an orbit like this in 3D?
How many bits are required to address the program memory of PIC16F887? What is PCLATH? For...
How many bits are required to address the program memory of PIC16F887? What is PCLATH? For PC absolute addressing, describe how to write assembly program to jump to code located in a different program memory page.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT