Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ SHORT ANSWER SECTION - Provide in depth answers in your own words. 1. Compar

ID: 3842790 • Letter: C

Question

C++

SHORT ANSWER SECTION - Provide in depth answers in your own words.

1. Compare and Contrast Dynamic vs Static memory and where in RAM memory each type of structure is placed. Describe Virtual Memory.

2. Compare and contract Linked List data structure to Array data structure.

3. Why is it difficult to perform a binary search on a linked list?

4. Memory Allocation Analysis: Describe your process for calculating memory required for the following examples. Give an estimate in MB/GB of the amount of memory required.

(a) Array of Doubles that contains 100,000 elements.

(b) Linked List of chars contains 1,000,000 nodes.

Explanation / Answer

Question 1:

The size is fixed.

This type of memory blocks consecutive memory locations.

Virtual Memory: In some cases, the size of the program is larger than the size of the RAM or the available memory in RAM. At that time, a part of the secondary storage is blocked or reserved, to use as swap space. The program is divided into manageable pages or segments and then the part which is needed to run on a particular time gets loaded into RAM. This swap space in the secondary storage is known as Virtual Memory.

Question 2:

Question 3:

It is difficult to perform binary search on linked list because the size of the list is not known and the elements are not identified by index values unlike arrays instead, we have to traverse the list every time we want to access a particular element. Whereas in array, we can simply point to an element we want using the array index.

Question 4:

a) Size of double in c++ is 8 bytes.

Therefore, 100000 double elements reserves 100000 * 8 bytes = 800000 B = 781.25 KB = 0.78 MB

b) Suppose, we're calculating for a 64 bit machine where an address will be of 64 bits i.e., 8 bytes. If we have used 32 bits machine, then the address would be of size 4 bytes.

In a 64 bit machine, the size of a pointer therefore is, 8 bytes. Now, in a linked list of characters of length 1000000, each node will be of 9 bytes (1 byte for char, and 8 bytes for the pointer to the next node).

Therefore, total size = 1000000 * 9 bytes = 9000000 bytes = 8789.06 KB = 8.58 MB

Dynamic Memory Static Memory Here, the memory locations are determined at run time. Here, the memory locations are defined during compilation time. In this case, the memory locations are not found sequentially. The memory locations are placed sequentially. The size of this type of memory varies.

The size is fixed.

The memory locations spreads throughout the RAM.

This type of memory blocks consecutive memory locations.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote