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...
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...
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.
Implementing a health program Implementing a health program involves many challenges. Use the South University Online...
Implementing a health program Implementing a health program involves many challenges. Use the South University Online Library, the Internet, and personal interactions with your local health authorities to understand the various facets of implementing public health programs. Based on your research and understanding, respond to the following: Explain the four categories of information, which provide a useful framework for organizing a community health program. Describe the importance of assessing program implementation in a public health program. There are three levels...
Hey everyone I'm working through my homework which involves creating a ER diagram based of certain...
Hey everyone I'm working through my homework which involves creating a ER diagram based of certain business rules and I am stuck on this part: Updated info • Customers have a name, phone number, a credit card no, and a unique customer number. • Customers can attend many performances, and each performance can have many customers attending. • Each performance of a show is on at a specific date and time, at a venue. • Each performance has many actors...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT