Computer Memory and Arrays
- 87Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
How can computer memory be conceptualized at a basic level?
87 questions
- 1
How can computer memory be conceptualized at a basic level?
Model answer
Computer memory can be viewed as a linear array of small boxes, each holding a fundamental unit of data.
Explanation
Each memory location acts like one element in a large sequential array.
- 2
What is a memory address?
Model answer
A memory address is a sequential number that labels a particular location in memory.
Explanation
Although addresses are often displayed in hexadecimal, they function like indexes into an array.
- 3
What two basic operations does the memory interface provide?
Model answer
The two basic operations are writing data to an address and reading data from an address.
Explanation
All higher-level data access ultimately relies on reading from or writing to a particular memory location.
- 4
Why can a memory address be compared to an array index?
Model answer
Both identify a specific position in a sequence where data can be read or written.
Explanation
A memory address is essentially an index into the array that represents memory.
- 5
Why is every program ultimately built on array-like operations?
Model answer
All program data is stored in memory, and memory provides only the ability to read from or write to particular indexed locations.
Explanation
More complex programming abstractions are implemented on top of these fundamental operations.
- 6
What happens when a single-byte memory array is used to store one character?
Model answer
The character must be stored in the only available location, at index zero.
Explanation
With only one element, there is no alternative position or ordering.
- 7
How many possible orders are there for two distinct elements in an array?
Model answer
There are two possible orders.
Explanation
Either element can appear first, so the number of arrangements is the factorial of two.
- 8
How many possible orders are there for three distinct elements?
Model answer
There are six possible orders.
Explanation
The number of arrangements is the factorial of three.
- 9
What happens to the number of possible element orderings as an array grows?
Model answer
The number of possible orderings increases extremely rapidly, according to the factorial of the number of elements.
Explanation
Even a moderate increase in array length creates astronomically more possible arrangements.
- 10
Why would finding a character in an unsorted array require checking many elements?
Model answer
Because the desired character could be at any index, the search may need to inspect every element until the character is found or the array ends.
Explanation
An unsorted arrangement provides no information that allows elements to be skipped.
- 11
How could you determine whether the letter Z appears in an array sorted in ascending alphabetical order?
Model answer
Inspect the final element; the array contains Z if and only if that final element is Z.
Explanation
If Z is present in ascending order, it must be the greatest and therefore last character.
- 12
Why is finding the most frequent character generally harder than checking for Z in an alphabetically sorted array?
Model answer
Determining frequency usually requires examining the entire array, whereas checking for Z can be answered by inspecting one known position.
Explanation
Alphabetical ordering helps locate a specific maximum character but does not directly reveal which character occurs most often.
- 13
What arrangement would make finding the most frequent character especially fast?
Model answer
Arrange the characters by frequency, with the most frequent character at the beginning.
Explanation
The desired answer can then be obtained by reading the first element.
- 14
What is the first foundational idea about data access in computer science?
Model answer
Because memory is an array and its basic operations use indexes, every data-access strategy ultimately involves finding an array index.
Explanation
Different data structures mainly provide different methods for determining that index.
- 15
What is the second foundational idea about data structures?
Model answer
Different orderings of elements have different strengths and weaknesses that can be exploited by access algorithms.
Explanation
An arrangement that is efficient for one operation may be inefficient for another.
- 16
What is a data structure?
Model answer
A data structure is a strategy for finding, inserting, or removing data in an underlying array.
Explanation
It combines an arrangement of elements with logic for performing operations on them.
- 17
What are the two main components of a data structure?
Model answer
The first is the ordering of elements in the underlying array, and the second is the logic used to access, insert, or remove elements.
Explanation
Both physical arrangement and operational logic determine performance.
- 18
What is a sorted array?
Model answer
A sorted array is an array whose elements are arranged according to an ordering, such as alphabetical or numerical order.
Explanation
Sorting can make certain searches very efficient by placing relevant values at predictable positions.
- 19
How can composite objects be sorted in an array?
Model answer
Composite objects can be sorted according to one of their fields, such as sorting user objects by user ID.
Explanation
The ordering need not be based on the entire object; a selected subfield can determine it.
- 20
Why might a program use multiple sorted index arrays for one collection of objects?
Model answer
It can provide efficient lookup by different fields, such as one index sorted by user name and another sorted by user ID.
Explanation
The actual objects can remain in one array while separate arrays provide different search orderings.
- 21
What is the role of an index array in a data structure?
Model answer
An index array stores references or indexes that identify where the actual objects are located.
Explanation
It avoids duplicating the objects while supporting alternative orderings.
- 22
How does the library analogy illustrate pointers?
Model answer
The physical book remains in one stable shelf location, while a search system returns directions to that location.
Explanation
A pointer similarly identifies where the actual data can be found rather than duplicating the data.
- 23
What is an array list?
Model answer
An array list is an ordered collection that supports indexed reading and writing while also allowing elements to be added or removed.
Explanation
It provides list-like behavior using an array internally.
- 24
How can an array list grow if its underlying array has fixed length?
Model answer
The backing array is allocated with unused capacity larger than the list's current number of elements.
Explanation
The list can use available positions until the backing array needs to be resized.
- 25
What is the difference between an array list's capacity and size?
Model answer
Capacity is the length of the backing array, while size or count is the number of elements currently in the list.
Explanation
The capacity can exceed the size so that new elements can be added.
- 26
How does an array list add an element to its end?
Model answer
It writes the new element at the position given by the current count and then increases the count by one.
Explanation
Appending uses the next unused position in the backing array.
- 27
What happens internally when an array list removes an element from the middle?
Model answer
Every subsequent element is copied backward by one position to fill the resulting gap.
Explanation
The copying preserves the list's order despite the fixed layout of the underlying array.
- 28
Why can removing an element from a normal array not truly shorten the array?
Model answer
An array has fixed-length memory locations, so an individual physical location cannot be removed; its data can only be replaced or marked as empty.
Explanation
A simple substitute is to set the location's data to zero or another empty value.
- 29
What happens when an array list inserts an element into the middle?
Model answer
The new element is created at the target position, and all subsequent elements are shifted forward by one.
Explanation
Insertion requires copying existing elements to make room.
- 30
Why can insertion and removal be slow in an array list?
Model answer
They may require copying many subsequent elements, which becomes expensive for large lists.
Explanation
The array's physical ordering creates a cost whenever a gap must be filled or space must be created.
- 31
What determines whether an array list is an appropriate data structure?
Model answer
The best choice depends on the data and the expected pattern of access, insertion, and deletion.
Explanation
No data structure is efficient for every possible workload.
- 32
What restriction gives stacks and queues efficient insertion and deletion?
Model answer
They restrict insertion and deletion to the beginning or end rather than allowing changes at arbitrary positions.
Explanation
Limiting operations avoids much of the copying required by general array lists.
- 33
How is a stack different from a general array list?
Model answer
A stack allows changes only at its last element, called the top.
Explanation
The restriction models a vertical stack in which only the top object is directly accessible.
- 34
Why is a stack called a stack?
Model answer
It behaves like a vertical stack of objects: an object in the middle cannot be accessed until the objects above it are removed.
Explanation
The top element is the only directly accessible element.
- 35
How is a stack implemented over an array?
Model answer
It uses a backing array with fixed capacity and a count that records how many elements are currently present.
Explanation
The count identifies the position at which a new top element can be stored.
- 36
How does a stack push an element?
Model answer
It writes the element immediately after the current last element and increases the count by one.
Explanation
Pushing is equivalent to adding an element at the end of an array list.
- 37
How does a stack pop an element?
Model answer
It removes the last element by decreasing the count by one.
Explanation
No elements need to be copied because there are no elements after the last one.
- 38
Why are stack push and pop operations efficient?
Model answer
Both operate at the end of the array, so they do not require shifting or copying other elements.
Explanation
Adding at the end is a special case of insertion, and removing at the end is a special case of deletion.
- 39
How can a text editor use a stack to implement undo?
Model answer
It can push each change onto a stack and pop the most recent change when the user selects undo.
Explanation
The last change entered is the first one removed, matching last-in, first-out behavior.
- 40
How can redo be implemented using stacks?
Model answer
A second stack stores redoable changes; entering a new change empties the redo stack.
Explanation
The second stack tracks changes that have been undone and may be reapplied.
- 41
How does a queue extend the functionality of a stack?
Model answer
A queue permits removal from the front as well as insertion and removal at the back.
Explanation
This additional front-removal operation supports first-in, first-out processing.
- 42
What processing order does a queue provide?
Model answer
A queue processes elements in the order in which they were added.
Explanation
The earliest request or item is removed first.
- 43
Why is a queue preferable to a stack for processing web requests?
Model answer
A queue processes requests in arrival order, preventing older requests from being delayed indefinitely behind newer ones.
Explanation
A stack could repeatedly push new requests above older ones, potentially starving requests at the bottom.
- 44
How can a queue remove its front element without shifting all remaining elements?
Model answer
It increments a start index and treats the array as though the removed location no longer belongs to the queue.
Explanation
The start index identifies the current front without physically moving the remaining data.
- 45
What problem occurs if a queue only advances its start index?
Model answer
Unused or dead space accumulates at the beginning, and the end index may eventually exceed the backing array's capacity.
Explanation
Repeated removals and insertions would eventually overflow the fixed array.
- 46
How does the modulo operator solve the queue's space problem?
Model answer
Each array access uses the index modulo the array capacity, causing indexes that pass the end to wrap back to zero.
Explanation
This reuses freed positions at the beginning of the array.
- 47
What is a circular queue?
Model answer
A circular queue is a queue whose logical sequence wraps around the end of a fixed-size backing array.
Explanation
Modulo-based indexing allows insertion and removal without reallocating, resizing, or copying the entire queue.
- 48
What is the defining organizational principle of a linked list?
Model answer
A linked list keeps elements in order by storing a link from each element to the next element rather than relying on adjacent array positions.
Explanation
The linked order can differ from the physical order in the underlying array.
- 49
How can a linked list be implemented using an array?
Model answer
Each array entry stores an element and the array index of the next element in the linked list.
Explanation
The next-index field creates logical links between physically stored records.
- 50
How would a linked list insert an element between two existing elements?
Model answer
It stores the new element in an available array position and updates the next-index fields so the links point from the first element to the new element and then to the original successor.
Explanation
The physical position of the new element does not need to be adjacent to either neighbor.
- 51
How would a linked list remove an element from the middle?
Model answer
It changes the previous element's next index to point to the removed element's successor.
Explanation
The removed element is bypassed without shifting other array entries.
- 52
What is the main performance advantage of linked-list insertion and deletion?
Model answer
They avoid copying subsequent elements when the location of the target and its neighboring element is already known.
Explanation
Only the relevant links need to be updated.
- 53
What is the main performance disadvantage of accessing a position in a linked list?
Model answer
The list may need to be traversed from the beginning, following links one at a time until the desired position is reached.
Explanation
The array index does not necessarily match the element's logical position in the list.
- 54
Why might removing the element at position 300,000 be slow in a linked list?
Model answer
A naive implementation may have to follow 300,000 links from the first element before reaching the target.
Explanation
Linked lists do not provide efficient arbitrary index access.
- 55
Why can iterating through a linked list be slower than iterating through an array?
Model answer
Linked-list elements may be scattered in memory, producing a less predictable access pattern and poorer cache performance.
Explanation
Arrays generally store consecutive elements, which are more cache-friendly.
- 56
When does a linked list provide its best insertion and deletion performance?
Model answer
It performs best when there is already a direct reference to the element before or after the target.
Explanation
The links can then be updated without first performing a long search.
- 57
Why can linked lists be useful as building blocks even when they are not ideal for ordinary ordered collections?
Model answer
Their flexible linking allows other structures to store multiple independent sequences without requiring contiguous storage.
Explanation
This property is useful in structures such as hashmaps and trees.
- 58
How are pointers related to array indexes at the lowest level?
Model answer
A pointer can be understood as an index or address identifying a location in memory.
Explanation
Memory itself can be modeled as an array, so references to data ultimately identify memory locations.
- 59
What happens when a program allocates a linked-list node using
newormalloc?Model answer
The program requests memory from a heap-management data structure provided by the language or standard library.
Explanation
The heap is itself implemented over the computer's underlying memory array.
- 60
Why might heap-allocated linked-list nodes perform worse than nodes managed in an array?
Model answer
The general-purpose heap must support many workloads, so allocation and memory placement may be less efficient than managing nodes directly in an array.
Explanation
Manual array-based storage can provide more predictable layout and access.
- 61
What is a hashmap?
Model answer
A hashmap, also called a dictionary, stores values that can be looked up using a non-numerical key such as a string.
Explanation
The key is transformed into an array index for storage and retrieval.
- 62
What is the purpose of a hash function?
Model answer
A hash function converts an arbitrary key, such as a string, into a numerical value.
Explanation
The resulting value is used to determine where the key's data should be stored.
- 63
Why is a hash value usually reduced modulo the backing-array length?
Model answer
The hash value may be too large to use directly, so taking it modulo the array length maps it to a valid index from zero through the last array position.
Explanation
Modulo converts a large numerical range into the fixed range supported by the array.
- 64
What is a collision in a hashmap?
Model answer
A collision occurs when two different keys produce the same array index.
Explanation
Because the backing array has limited positions, distinct keys can map to the same location.
- 65
How does linear probing resolve a hashmap collision?
Model answer
It searches forward through the array until it finds an empty slot, storing or locating the item there.
Explanation
Each item must also retain identifying information, such as its key, so searches can determine whether a slot contains the requested item.
- 66
Why must a hashmap compare stored keys during lookup after hashing?
Model answer
The hash index alone does not prove that the stored item has the requested key, especially when collisions occur.
Explanation
The hashmap must compare key information while probing until it finds the target or an empty slot.
- 67
What are clusters in a linearly probed hashmap?
Model answer
Clusters are long consecutive runs of occupied array positions created by collision resolution.
Explanation
They can make later searches slow because a lookup may need to inspect many consecutive slots.
- 68
How does a two-array hashmap handle collisions using linked lists?
Model answer
One array stores the first item for each hash, while a second array stores colliding items linked together by next indexes.
Explanation
Lookup follows the collision chain rather than scanning consecutive positions in the first array.
- 69
Why are linked lists useful for storing hashmap collision chains?
Model answer
Multiple collision chains can share one array even when their elements are interleaved physically.
Explanation
The links determine logical order, so the items do not need to occupy consecutive array positions.
- 70
Why would separate array lists for every hashmap collision bucket be inconvenient?
Model answer
It would require many separate allocations and make capacity planning difficult because the future distribution of collisions is unpredictable.
Explanation
The arrays might also need to be resized independently as collision counts change.
- 71
What is a tree data structure?
Model answer
A tree is a structure of nodes connected by one-directional relationships from parents to children.
Explanation
Trees represent hierarchical relationships such as interface elements and their containers.
- 72
What is a node in a tree?
Model answer
A node is an individual element in the tree.
Explanation
Nodes hold data and may have relationships with other nodes.
- 73
What are the parent and child relationships in a tree?
Model answer
The parent is the node above a relationship, and the child is the node below it.
Explanation
Relationships are directed from the parent toward its children.
- 74
What restriction does a tree place on parent and child relationships?
Model answer
Each child has only one parent, while a parent can have multiple children.
Explanation
This one-parent restriction distinguishes a tree from a more general graph.
- 75
How can a user interface benefit from a tree structure?
Model answer
Elements can be positioned relative to parent or container elements, so moving a parent automatically moves its children.
Explanation
The hierarchy avoids manually updating every nested element when a parent changes.
- 76
How can a tree be implemented using two arrays?
Model answer
One array stores the nodes, and a second array stores linked child relationships containing child-node indexes and next-child indexes.
Explanation
Each node points to the first relationship in its child list.
- 77
What information does a tree relationship entry contain in a two-array implementation?
Model answer
It contains the index of a child node in the node array and the index of the next relationship in the child-linked list.
Explanation
Together, these indexes allow all children of a node to be traversed.
- 78
How would a traversal find a node's second child in a linked-list representation of a tree?
Model answer
It follows the node's first-child index to the first relationship and then follows the next-child index to the second relationship.
Explanation
The second relationship contains the index of the second child in the node array.
- 79
Why can a tree be built using linked-list techniques?
Model answer
A tree node's multiple child links can be represented as a linked list, and linked lists can be implemented with array indexes.
Explanation
The tree extends the idea of linking elements while allowing multiple outgoing links.
- 80
What is a graph in relation to a tree?
Model answer
A graph is a more general structure than a tree because it allows a node to have multiple parents.
Explanation
A tree is a constrained graph with one parent per child.
- 81
How can linked lists, trees, and graphs be viewed as progressively less constrained structures?
Model answer
A linked list permits one previous and one next link, a tree permits multiple next links, and a graph permits multiple links in both directions.
Explanation
Each structure relaxes restrictions on how nodes can be connected.
- 82
What are edges and vertices in graph terminology?
Model answer
Nodes may be called vertices, and the relationships connecting them are called edges.
Explanation
The terms describe the elements and connections of a graph.
- 83
What is A* used for?
Model answer
A* is a pathfinding algorithm that finds a shortest or best path between two points.
Explanation
It is commonly used in video games to route a character from its current location to a target.
- 84
How are graphs commonly implemented using arrays?
Model answer
One array stores the nodes, and a second array stores linked lists of edges; each node stores the index of its first edge.
Explanation
The underlying data arrangement is similar to the two-array tree implementation.
- 85
What is the main implementation difference between a tree and a graph?
Model answer
The data arrangement can be the same, but graph operations allow relationships to be traversed in more directions than tree parent-to-child operations.
Explanation
The distinction is primarily in the allowed relationships and operations rather than the basic arrays.
- 86
What additional storage may be needed to traverse a graph in both directions?
Model answer
A duplicate of an endpoint or vertex may be stored so that the relationship is accessible from both connected nodes.
Explanation
Bidirectional traversal requires each direction to be represented.
- 87
Why might beginning a programming problem with a simple array be useful?
Model answer
An array provides the fundamental operations needed to build many more complex structures and may be sufficient for the problem.
Explanation
Starting simply can reveal an efficient structure tailored to the data and access pattern.

Ask anything
We've read this whole study set, so questions about it get the best answers.