Computer Memory and Arrays
- 60Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Conceptually, what is computer memory most like?
Conceptually, what is computer memory most like?
60 questions
- 1
Conceptually, what is computer memory most like?
- A
A network of objects that cannot be accessed directly
- B
A processor register that stores one value at a time
- C
A linear array of individually addressable storage locations
- D
A hierarchy of files organized only by their names
Correct answer
CA linear array of individually addressable storage locations
Explanation
Computer memory can be modeled as a large array of small storage locations, each identified by an address.
- A
- 2
What are the two fundamental operations supported by the memory interface?
- A
Sorting data by address and deleting unused addresses
- B
Writing data to an address and reading data from an address
- C
Moving data automatically and repairing damaged values
- D
Compressing data and encrypting its contents
Correct answer
BWriting data to an address and reading data from an address
Explanation
At the fundamental level, memory allows programs to write data to a particular address and read data from a particular address.
- A
- 3
In the array model of memory, what does a memory address represent?
- A
An index into the array representing memory
- B
The value currently stored in the entire array
- C
The number of bytes allocated to a program
- D
A description of the data type stored at the address
Correct answer
AAn index into the array representing memory
Explanation
A memory address is another way of describing an index into the array that represents memory.
- A
- 4
Why can every program ultimately be viewed as using array operations?
- A
Arrays automatically determine the best organization for every data set
- B
All program data is built on memory, which supports indexed reads and writes
- C
Programs are unable to store data outside the processor
- D
Every programming language exposes only arrays to its users
Correct answer
BAll program data is built on memory, which supports indexed reads and writes
Explanation
Because memory is modeled as an array and provides indexed reads and writes, higher-level data access strategies are built on those operations.
- A
- 5
How many possible orders are there for three distinct elements?
- A
Six possible orders
- B
One possible order
- C
Nine possible orders
- D
Three possible orders
Correct answer
ASix possible orders
Explanation
The number of arrangements of three distinct elements is 3!=6.
- A
- 6
What mathematical concept describes the number of possible arrangements of elements in an array?
- A
A remainder of the number of elements
- B
A logarithm of the number of elements
- C
A factorial of the number of elements
- D
A square of the number of elements
Correct answer
CA factorial of the number of elements
Explanation
The number of possible arrangements of n distinct elements is described by the factorial n!.
- A
- 7
Why does checking an unsorted million-character array for a particular character require potentially examining every element?
- A
The character can occur only at the final index
- B
The array cannot be read at arbitrary indexes
- C
No ordering information allows the search to eliminate unexamined elements
- D
The array must be copied before any search can begin
Correct answer
CNo ordering information allows the search to eliminate unexamined elements
Explanation
With no useful ordering, the search may need to inspect every character before finding the target or determining that it is absent.
- A
- 8
If characters are sorted in ascending alphabetical order, how can the presence of Z be checked most directly?
- A
Inspect the first element of the array
- B
Randomly inspect indexes until Z appears
- C
Count every character before comparing them
- D
Inspect the final element of the array
Correct answer
DInspect the final element of the array
Explanation
In ascending alphabetical order, Z is the greatest possible character, so it can occur only at the end. The final element therefore determines whether Z is present.
- A
- 9
Why does sorting characters by frequency help find the most frequent character?
- A
Sorting causes every character to occupy the same number of positions
- B
The most frequent character is placed at a known position, such as the beginning
- C
The most frequent character is always alphabetically last
- D
Sorting removes all repeated characters from the array
Correct answer
BThe most frequent character is placed at a known position, such as the beginning
Explanation
If elements are ordered by frequency, the most frequent character is placed at the beginning, making it immediately accessible.
- A
- 10
What is the central task underlying data access strategies in programming?
- A
Converting every object into a character
- B
Ensuring that all data is stored in alphabetical order
- C
Determining the array index where the desired data can be found
- D
Increasing the physical size of memory before each access
Correct answer
CDetermining the array index where the desired data can be found
Explanation
Since array-based memory provides indexed access, data structures ultimately need a strategy for determining an appropriate array index.
- A
- 11
What two components define a data structure?
- A
The data type and the amount of available memory
- B
The ordering of elements and the logic for operating on them
- C
The programming language and the processor architecture
- D
The user interface and the input device
Correct answer
BThe ordering of elements and the logic for operating on them
Explanation
A data structure consists of an arrangement or ordering of elements and logic for operations such as finding, inserting, and removing elements.
- A
- 12
What is a sorted array an example of?
- A
A data structure organized to support access through sorted order
- B
A memory system that cannot perform indexed reads
- C
A linked structure in which every item has multiple parents
- D
A queue that removes items from both ends simultaneously
Correct answer
AA data structure organized to support access through sorted order
Explanation
A sorted array is a data structure whose elements are arranged according to their values or a selected ordering criterion.
- A
- 13
How might an array of user objects be sorted for efficient lookup?
- A
By a selected field such as the user's ID
- B
By assigning every user the same array index
- C
By deleting all fields except the user's name
- D
Only by the physical address of the computer
Correct answer
ABy a selected field such as the user's ID
Explanation
Composite objects can be sorted using a subfield, such as a user's ID, rather than the entire object as a single value.
- A
- 14
Why might a system maintain separate arrays of indexes for users?
- A
To prevent users from being stored in the main array
- B
To duplicate every user object in several physical locations
- C
To make all lookups independent of the user's data
- D
To support different orderings, such as lookup by name and by ID
Correct answer
DTo support different orderings, such as lookup by name and by ID
Explanation
Separate index arrays can be sorted by different fields while pointing to the same underlying user objects.
- A
- 15
In the library analogy, what does a pointer most closely represent?
- A
Directions to the stable location of the actual data
- B
A complete duplicate of the physical book
- C
A record that stores only the book's genre
- D
A new building containing books in another order
Correct answer
ADirections to the stable location of the actual data
Explanation
A pointer identifies where the actual data is located, much like a library system returns directions to a book on a shelf.
- A
- 16
What distinguishes an array list from a basic fixed-length array?
- A
An array list cannot read or write arbitrary indexes
- B
An array list always removes elements without shifting any data
- C
An array list can add elements and track a changing logical length
- D
An array list stores elements without using memory addresses
Correct answer
CAn array list can add elements and track a changing logical length
Explanation
An array list supports indexed access like an array but also provides operations such as adding and removing elements while maintaining a logical size.
- A
- 17
What is the capacity of an array list?
- A
The number of elements removed since creation
- B
The index of the first element in the list
- C
The length of its underlying backing array
- D
The number of elements currently stored in the list
Correct answer
CThe length of its underlying backing array
Explanation
Capacity refers to the length of the backing array, which can be larger than the list's current number of elements.
- A
- 18
What does the size or count of an array list represent?
- A
The highest possible index in all computer memory
- B
The number of unused memory addresses in the system
- C
The number of logical items currently in the list
- D
The total number of locations in the backing array
Correct answer
CThe number of logical items currently in the list
Explanation
The list's size or count is separate from capacity and records how many items are currently part of the logical list.
- A
- 19
How does an array list typically add an element to its end?
- A
It changes the physical size of memory at the target index
- B
It writes at the current count index and then increases the count
- C
It deletes the final element and replaces it with the new value
- D
It shifts every element toward the beginning before writing
Correct answer
BIt writes at the current count index and then increases the count
Explanation
The current count serves as the next available logical index; the list writes there and increments the count.
- A
- 20
What happens when an element is removed from the middle of an array list?
- A
Subsequent elements are shifted backward to fill the gap
- B
The backing array automatically removes a physical memory cell
- C
All earlier elements are shifted forward to the end
- D
The list leaves the gap permanently and changes no indexes
Correct answer
ASubsequent elements are shifted backward to fill the gap
Explanation
To preserve contiguous ordering, every later element must be copied backward by one position.
- A
- 21
Why can a normal fixed-length array not directly remove one element?
- A
Arrays can only contain elements in alphabetical order
- B
Removing an element automatically changes every memory address
- C
Removing it would require removing the corresponding physical memory location
- D
Arrays cannot store zero or empty values
Correct answer
CRemoving it would require removing the corresponding physical memory location
Explanation
An array's locations are fixed. A normal array can overwrite a value, but it cannot individually remove the physical location represented by an index.
- A
- 22
Why can removing an element from the middle of a large array list be slow?
- A
Many subsequent elements must be read and rewritten
- B
The operation requires searching all of computer memory
- C
The list must recompute every possible element arrangement
- D
The list must sort all elements alphabetically
Correct answer
AMany subsequent elements must be read and rewritten
Explanation
Removal from the middle requires copying each subsequent element backward, which becomes expensive for large lists.
- A
- 23
How does insertion into the middle of an array list preserve ordering?
- A
It overwrites the target and discards all later elements
- B
It shifts subsequent elements forward before writing the new element
- C
It changes the meaning of every existing index
- D
It places the new element at the end without changing other elements
Correct answer
BIt shifts subsequent elements forward before writing the new element
Explanation
Insertion creates space by copying subsequent elements forward, then writes the new element into the target position.
- A
- 24
What determines whether an array-based data structure performs well?
- A
Whether every operation uses the same array index
- B
Whether the programming language hides its implementation
- C
Whether the data's access pattern matches the structure's strengths
- D
Whether the structure has the largest possible capacity
Correct answer
CWhether the data's access pattern matches the structure's strengths
Explanation
Each ordering and representation has strengths and weaknesses, so performance depends on how the program actually accesses the data.
- A
- 25
What is the defining access restriction of a stack?
- A
Elements can be added or removed only at the beginning
- B
Elements can be removed only from arbitrary middle positions
- C
Elements can be added or removed only at the end called the top
- D
Elements must always be accessed in sorted order
Correct answer
CElements can be added or removed only at the end called the top
Explanation
A stack restricts modifications to its last element, called the top.
- A
- 26
Why is a stack described as last-in, first-out?
- A
Elements are removed in alphabetical order of their values
- B
The most recently added element is the first one available for removal
- C
The oldest element is always removed before newer elements
- D
Every element is removed immediately after insertion
Correct answer
BThe most recently added element is the first one available for removal
Explanation
Like blocks in a vertical stack, the newest top element must be removed before earlier elements beneath it can be reached.
- A
- 27
How is adding an element to a stack implemented over an array?
- A
Replace the top element without changing the count
- B
Shift every element forward and write at the middle
- C
Write after the current last element and increase the count
- D
Write before the current first element and decrease the count
Correct answer
CWrite after the current last element and increase the count
Explanation
Stack insertion is equivalent to adding at the end of an array list: write at the next position and increment the count.
- A
- 28
Why is popping from a stack especially efficient?
- A
Popping reallocates the backing array after every operation
- B
Removing the final element requires only decreasing the count
- C
Popping shifts all earlier elements toward the end
- D
Popping searches for the element throughout the backing array
Correct answer
BRemoving the final element requires only decreasing the count
Explanation
There are no subsequent elements after the top, so no copying is needed; the count can simply be reduced by one.
- A
- 29
Which application naturally benefits from a stack?
- A
Sorting users by two independent fields
- B
Tracking undoable changes in a text editor
- C
Finding a book by several library categories
- D
Processing network requests in arrival order
Correct answer
BTracking undoable changes in a text editor
Explanation
Undo operations usually reverse the most recent change first, matching stack behavior.
- A
- 30
How can redo functionality be implemented alongside an undo stack?
- A
By maintaining a second stack for redoable changes
- B
By duplicating the entire text after every keystroke
- C
By storing every change in a sorted array by character
- D
By removing the oldest change from the undo stack
Correct answer
ABy maintaining a second stack for redoable changes
Explanation
A second stack can hold changes that were undone and may be reapplied. A new change clears that redo stack.
- A
- 31
What additional operation does a queue provide compared with a stack?
- A
Removing an element from the front
- B
Tracking the number of stored elements
- C
Reading an element at an arbitrary index
- D
Adding an element to the back
Correct answer
ARemoving an element from the front
Explanation
Both structures can add at the back, but a queue additionally removes from the front.
- A
- 32
Why is a queue appropriate for processing web requests?
- A
It processes requests in the order they arrive
- B
It sorts requests alphabetically before processing
- C
It permanently discards requests during heavy load
- D
It always processes the newest request first
Correct answer
AIt processes requests in the order they arrive
Explanation
Queues provide first-in, first-out processing, preventing older requests from being continually pushed behind newer ones.
- A
- 33
How does a circular queue prevent wasted space in a fixed-size array?
- A
It reallocates a larger array after each dequeue
- B
It stores every removed element in a second permanent array
- C
It uses modulo arithmetic to wrap indexes back to zero
- D
It shifts every remaining element toward the front after removal
Correct answer
CIt uses modulo arithmetic to wrap indexes back to zero
Explanation
Taking each index modulo the array capacity causes indexes that pass the end to wrap around to the beginning.
- A
- 34
What does the start index represent in a circular queue?
- A
The array position immediately after the last item
- B
The total capacity of the backing array
- C
The number of items that have ever been dequeued
- D
The array position of the queue's first logical item
Correct answer
DThe array position of the queue's first logical item
Explanation
The start index tracks where the first current queue element is located in the backing array.
- A
- 35
What is the main organizational idea of a linked list?
- A
Elements must occupy consecutive array positions
- B
Elements are kept in order by links to other elements
- C
Elements are ordered only by their numerical values
- D
Elements are always stored in separate physical arrays
Correct answer
BElements are kept in order by links to other elements
Explanation
A linked list maintains logical order through links, rather than relying on the physical order of the underlying array.
- A
- 36
What information does a linked-list node typically store in addition to its data?
- A
The index of every node in the entire list
- B
The array index of the next node
- C
The total capacity of computer memory
- D
The sorted position of every possible future node
Correct answer
BThe array index of the next node
Explanation
A simple array-based linked-list node stores its data and the index of the following node.
- A
- 37
Why can linked lists insert an element without shifting later elements?
- A
They reserve a physical memory cell inside the existing node
- B
They add the element elsewhere and update the relevant links
- C
They automatically sort the entire array after insertion
- D
They overwrite the target element and discard its successor
Correct answer
BThey add the element elsewhere and update the relevant links
Explanation
The new node can be placed in another array location, while links are updated to place it logically between existing nodes.
- A
- 38
How can a linked-list element be removed efficiently when its predecessor is known?
- A
Update the predecessor's next index to skip the removed element
- B
Sort the remaining nodes before reconnecting them
- C
Delete the physical array location and renumber all indexes
- D
Shift every later node one position toward the beginning
Correct answer
AUpdate the predecessor's next index to skip the removed element
Explanation
Removing a node only requires changing the preceding node's link to point to the removed node's successor.
- A
- 39
What is the major cost of accessing the element at position n in a basic linked list?
- A
The list must copy the entire backing array into a new array
- B
The list must hash every element before reaching position n
- C
The list may require following links from the first element n times
- D
The list must shift all elements after position n
Correct answer
CThe list may require following links from the first element n times
Explanation
Because physical array indexes do not necessarily match logical positions, a naive linked list must traverse links from the beginning.
- A
- 40
What performance trade-off does a linked list make compared with an array list?
- A
It improves indexed access but requires more copying for every insertion
- B
It improves insertion and removal with known neighbors but worsens indexed access
- C
It improves memory locality but requires a fixed logical ordering
- D
It improves sorting but prevents elements from being removed
Correct answer
BIt improves insertion and removal with known neighbors but worsens indexed access
Explanation
Linked lists avoid shifting during insertion and removal when a nearby reference is known, but they cannot efficiently access the nth position.
- A
- 41
Why is iterating through a linked list often slower than iterating through an array?
- A
Linked lists cannot store more than one element in memory
- B
Arrays perform mathematical operations automatically during iteration
- C
Linked lists require sorting before every sequential traversal
- D
Linked-list nodes may be accessed in a scattered pattern with poor cache performance
Correct answer
DLinked-list nodes may be accessed in a scattered pattern with poor cache performance
Explanation
Linked-list nodes may be distributed across memory, producing less cache-friendly access than the contiguous pattern of an array.
- A
- 42
At the lowest software level, what is a pointer most closely equivalent to?
- A
A sorting rule for an array
- B
An index into memory
- C
A copy of the referenced object
- D
A count of unused memory locations
Correct answer
BAn index into memory
Explanation
Because memory is modeled as an array, a pointer can be understood as an index identifying where data is located.
- A
- 43
What is the purpose of a hash function in a hashmap?
- A
It removes duplicate values from the hashmap
- B
It transforms a key into a number that can be mapped to an array index
- C
It guarantees that every distinct key has a unique array index
- D
It sorts all keys alphabetically before they are stored
Correct answer
BIt transforms a key into a number that can be mapped to an array index
Explanation
A hash function converts arbitrary key data, such as a string, into a numeric value that can be reduced to a valid array index.
- A
- 44
Why is the hash value typically reduced modulo the backing-array length?
- A
To convert the key back into its original string
- B
To ensure that every array position remains empty
- C
To map it into the valid index range from zero through the array length minus one
- D
To guarantee that no two keys will ever collide
Correct answer
CTo map it into the valid index range from zero through the array length minus one
Explanation
Taking the hash value modulo the array length produces an index within the valid range of the backing array.
- A
- 45
What is a collision in a hashmap?
- A
Two different keys produce the same array index
- B
The backing array reaches its maximum physical address
- C
Two values have the same data but different keys
- D
A key is removed before its value is read
Correct answer
ATwo different keys produce the same array index
Explanation
A collision occurs when distinct keys map to the same calculated array index.
- A
- 46
How does an open-addressing hashmap commonly resolve a collision?
- A
It deletes the item already occupying the index
- B
It creates a separate building of duplicate data
- C
It searches forward for an empty slot
- D
It changes the key until the hash value becomes unique
Correct answer
CIt searches forward for an empty slot
Explanation
One-array collision handling searches forward through the array until it finds an empty location.
- A
- 47
Why must an open-addressing hashmap store identifying information with each item?
- A
The hashmap cannot store values without storing their data types
- B
The calculated index may contain another key's item after a collision
- C
The identifying information determines the array's physical capacity
- D
The key is needed only to sort all values alphabetically
Correct answer
BThe calculated index may contain another key's item after a collision
Explanation
After collisions, the initial hash index may not contain the desired item, so the stored key must be compared during probing.
- A
- 48
What are clusters in an open-addressing hashmap?
- A
Separate arrays allocated for every individual key
- B
Groups of keys that have identical values but different indexes
- C
Long consecutive runs of occupied array positions
- D
Empty regions created whenever an item is removed
Correct answer
CLong consecutive runs of occupied array positions
Explanation
Forward probing tends to create consecutive runs of stored items, known as clusters.
- A
- 49
How does a two-array hashmap handle collisions?
- A
It copies every colliding item into every available array
- B
It places all collisions at the final index of the first array
- C
It links colliding items into a list stored in a second array
- D
It discards keys that map to an occupied position
Correct answer
CIt links colliding items into a list stored in a second array
Explanation
The first array identifies the initial item for a hash, while colliding items are stored in a second array and connected by links.
- A
- 50
What useful property of linked lists benefits the two-array hashmap design?
- A
Multiple separate linked lists can be interleaved in one array
- B
Every linked list must occupy one consecutive region of memory
- C
Linked lists automatically resize every collision bucket equally
- D
Linked lists guarantee that hash collisions cannot occur
Correct answer
AMultiple separate linked lists can be interleaved in one array
Explanation
Because linked lists follow explicit links rather than physical adjacency, many independent lists can share one underlying array.
- A
- 51
What relationship distinguishes a tree from a general graph?
- A
Trees cannot contain links between nodes
- B
Graphs allow only one outgoing link per node
- C
Each child in a tree has only one parent
- D
Each node in a tree must have multiple parents
Correct answer
CEach child in a tree has only one parent
Explanation
A tree allows a parent to have multiple children, but each child has only one parent.
- A
- 52
What are the elements of a tree called?
- A
Buckets
- B
Registers
- C
Nodes
- D
Clusters
Correct answer
CNodes
Explanation
The elements in a tree are called nodes, and their relationships are parent-child relationships.
- A
- 53
In a tree, what is the node at the top of a relationship called?
- A
The child
- B
The terminal bucket
- C
The vertex index
- D
The parent
Correct answer
DThe parent
Explanation
The node above another node in a tree relationship is the parent; the lower node is the child.
- A
- 54
How can a tree be implemented using two arrays?
- A
Store nodes in one array and child relationships in a second linked-list array
- B
Store only the root in one array and all values in the second
- C
Store parents in one array and duplicate every child in another
- D
Store every complete path in one array and delete the second array
Correct answer
AStore nodes in one array and child relationships in a second linked-list array
Explanation
One array holds the nodes, while another holds linked relationship records containing child-node indexes and links to additional children.
- A
- 55
When traversing a tree's children, what does a relationship record typically contain?
- A
The parent's value and the total number of tree levels
- B
The hash of the child and the capacity of the node array
- C
The child node's index and the index of the next child relationship
- D
The physical address of every descendant in the tree
Correct answer
CThe child node's index and the index of the next child relationship
Explanation
A relationship record identifies a child in the node array and links to the next child relationship in the second array.
- A
- 56
How is a graph more general than a tree?
- A
A graph permits links only from the root toward leaves
- B
A graph requires every node to have exactly one parent
- C
A graph removes all relationships between elements
- D
A graph allows a node to have multiple parent connections
Correct answer
DA graph allows a node to have multiple parent connections
Explanation
A graph relaxes the tree constraint that each child has one parent, allowing multiple incoming relationships.
- A
- 57
What are the links between nodes in a graph called?
- A
Capacities
- B
Indexes
- C
Edges
- D
Buckets
Correct answer
CEdges
Explanation
Graph terminology calls the relationships between nodes edges; the nodes may also be called vertices.
- A
- 58
What is A* commonly used for?
- A
Tracking the most recent edits in a text editor
- B
Resizing an array without copying its elements
- C
Finding a shortest or best path between two points
- D
Sorting hashmap keys by their string length
Correct answer
CFinding a shortest or best path between two points
Explanation
A* is a pathfinding algorithm widely used to calculate routes between locations, including routes for characters in video games.
- A
- 59
How is a graph commonly represented using arrays?
- A
Nodes are stored in one array and edges in a second linked-list array
- B
Only the root node is stored, while edges are inferred from values
- C
Every possible path is stored as a separate complete array
- D
Edges are stored without any reference to their connected nodes
Correct answer
ANodes are stored in one array and edges in a second linked-list array
Explanation
A common representation stores nodes in one array and edge records in another, with each node pointing to its first edge.
- A
- 60
What additional representation may be needed to traverse a graph in both directions?
- A
A second root that replaces all existing parent relationships
- B
A sorted copy of every node without any edge information
- C
A duplicate vertex reference accessible from both connected nodes
- D
A separate stack that stores every possible array index
Correct answer
CA duplicate vertex reference accessible from both connected nodes
Explanation
To traverse an edge in either direction, the connected vertex may need to be represented as accessible from both endpoints.
- A

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