# 5 A list can be implemented as anIntListthat uses a linked sequence

Content type
User Generated
Rating
Showing Page:
1/3
5. A list can be implemented as anIntListthat uses a linked
sequence ofIntNodes or using an array of typeint. Assume
that aninttakes up 4 bytes in memory, a reference takes up
4 bytes in memory, and an array A is defined to hold up to
200ints.
(a)If a list has 180 integers in it, which method (array or
linked list) is more efficient in terms of memory usage?
(b)If a list has 20 integers in it, which method (array or
linked list) is more efficient in terms of memory usage?
(c)The array and linked list implementations require the
same amount of memory if the list has how many
elements? (Do not includeheadin this calculation.)
Solution
A list can be implemented as an IntList that uses a linked
sequence of IntNodes or using an array of type int.
Assuming that an int takes up 4 bytes in memory, a
reference takes up 4 bytes in memory, and an array A is
defined to hold up to 200 ints.
from above statements, we refer that
struct intList
{

Showing Page:
2/3
int value; // inttakes up 4 bytes in memory
intList *node; //a reference takes up 4 bytes in memory
};
so to store values in intList, 8 Byte Node will be used for
each value stored in it.
(a)If a list has 180 integers in it, ARRAY is more efficient
in terms of memory usage beacuse
array with Maximum size will be 800 Bytes is more efficient
to store 180 values
then useing intList where
180 Nodes * 8 Bytes = 1440 Bytes will be used from
memory.
(b)If a list has 20 integers in it, LINKED LIST is more
efficient in terms of memory usage beacuse
If we use intList then
20 Nodes * 8 Bytes = 160 Bytes will be used from memory.
But array will use 800 Bytes as predefined size.
c)The array and linked list implementations require the
same amount of memory if the list has 100 elements
beacuse
array will use 800 Bytes as predefined size and is efficient
to store 100 values
intList will use 100 Nodes * 8 Bytes = 800 Bytes to store
values.

Showing Page:
3/3

Unformatted Attachment Preview
5. A list can be implemented as anIntListthat uses a linked sequence ofIntNodes or using an array of typeint. Assume that aninttakes up 4 bytes in memory, a reference takes up 4 bytes in memory, and an array A is defined to hold up to 200ints. (a)If a list has 180 integers in it, which method (array or linked list) is more efficient in terms of memory usage? (b)If a list has 20 integers in it, which method (array or linked list) is more efficient in terms of memory usage? (c)The array and linked list implementations require the same amount of memory if the list has how many elements? (Do not includeheadin this calculation.) I want answers with explanations Solution Answer : A list can be implemented as an IntList that uses a linked sequence of IntNodes or using an array of type int. Assuming that an int takes up 4 bytes in memory, a reference takes up 4 bytes in memory, and an array A ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

### Review

Anonymous
Really helped me to better understand my coursework. Super recommended.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4