C Data Structures and Pointers
- 66Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What does declaring int *x establish, before any memory is allocated for an integer?
What does declaring int *x establish, before any memory is allocated for an integer?
66 questions
- 1
What does declaring
int *xestablish, before any memory is allocated for an integer?- A
A pointer variable capable of storing an integer's address
- B
A pointer that automatically refers to the value zero
- C
A new integer stored at a guaranteed valid address
- D
A complete integer array with one initialized element
Correct answer
AA pointer variable capable of storing an integer's address
Explanation
The declaration creates a pointer variable, but does not allocate a pointee or initialize the pointer to a valid address.
- A
- 2
After
x = malloc(sizeof(int))succeeds, what doesxcontain?- A
The integer value stored in the newly allocated memory
- B
A copy of the integer type's definition
- C
The address of a memory chunk large enough for an integer
- D
The number of bytes that remain available in memory
Correct answer
CThe address of a memory chunk large enough for an integer
Explanation
mallocallocates a chunk of memory and returns its address, which can be stored in a pointer such asx. - A
- 3
What does
*x = 42do whenxpoints to valid allocated memory?- A
Copies the pointer
xinto a new variable named 42 - B
Changes the address stored in
xto the number 42 - C
Stores the value 42 in the memory location pointed to by
x - D
Allocates a second integer and stores its address in
x
Correct answer
CStores the value 42 in the memory location pointed to by
xExplanation
The asterisk dereferences
x: it accesses the memory at the address stored inx, where the assignment stores 42. - A
- 4
Why is dereferencing an uninitialized pointer such as
yunsafe?- A
It can access only memory belonging to an array
- B
It may attempt to access an unknown or invalid memory address
- C
It always changes the pointer into a null pointer
- D
It automatically allocates memory of the correct size
Correct answer
BIt may attempt to access an unknown or invalid memory address
Explanation
An uninitialized pointer may contain a garbage address. Dereferencing it can access memory that does not exist or is not valid for the program, potentially causing a segmentation fault.
- A
- 5
If
y = x, where both variables are pointers, what happens when the program executes*y = 13?- A
The shared pointee becomes 13, so reading it through
xalso gives 13 - B
Only the address stored in
ychanges, while the pointee stays unchanged - C
A separate integer is allocated for
yand set to 13 - D
The pointee becomes 13 only when accessed through
y
Correct answer
AThe shared pointee becomes 13, so reading it through
xalso gives 13Explanation
Assigning
y = xmakes both pointers hold the same address. Dereferencing either one accesses the same memory, so the value written throughyis visible throughxtoo. - A
- 6
What should a program generally do after calling
malloc?- A
Check whether the returned pointer is
NULLbefore using it - B
Assume allocation succeeded whenever the requested size is positive
- C
Free the returned pointer immediately before accessing the memory
- D
Convert the returned pointer into an integer before checking it
Correct answer
ACheck whether the returned pointer is
NULLbefore using itExplanation
malloccan fail, for example when memory is unavailable, and then returnsNULL. Checking the result before using the allocated memory is good practice. - A
- 7
What is the purpose of calling
freeon a pointer to a dynamically allocated chunk?- A
To preserve the chunk while removing its stored values
- B
To copy the chunk into a larger allocation
- C
To set every pointer to the chunk automatically to
NULL - D
To return that allocated memory so it can be used again
Correct answer
DTo return that allocated memory so it can be used again
Explanation
freereleases dynamically allocated memory. It does not automatically update every pointer that may refer to that memory. - A
- 8
In C, how do
�andNULLdiffer in the context described?- A
�is a character value, whileNULLis used as a null pointer value - B
Both are names for the integer zero and have identical pointer types
- C
�marks the end of an array, whileNULLallocates its first element - D
�is a pointer value, whileNULLis an ordinary character
Correct answer
A�is a character value, whileNULLis used as a null pointer valueExplanation
The content distinguishes
\0, a character, fromNULL, a pointer value representing no address. Though both are associated with zero underneath, they are used for different purposes. - A
- 9
What does the
sizeofoperator contribute when requesting memory for several integers?- A
It supplies the size of one integer so the request can scale to the needed number of bytes
- B
It converts an integer pointer into an array pointer
- C
It reports how many integer values are currently stored in the allocation
- D
It guarantees that the allocated integers will have their values initialized
Correct answer
AIt supplies the size of one integer so the request can scale to the needed number of bytes
Explanation
A request such as
3 * sizeof(int)asks for enough bytes for three integers without hard-coding the size of an integer. - A
- 10
Why can a pointer returned by
mallocbe used with square-bracket notation to access multiple elements?- A
Every pointer in C is automatically initialized as a fixed-size array
- B
Square brackets convert separate memory chunks into adjacent elements
- C
The pointer automatically contains the length of an array and checks every index
- D
The allocation is contiguous, and indexing advances by the size of the pointed-to type
Correct answer
DThe allocation is contiguous, and indexing advances by the size of the pointed-to type
Explanation
mallocreturns a contiguous chunk of memory. C's indexing and pointer arithmetic advance by the size of the pointed-to type, solist[i]accesses the appropriate element within the chunk. - A
- 11
Why can assigning a newly allocated address directly to the only pointer to an old allocation cause a memory leak?
- A
The new address is interpreted as an integer and overwrites the old data
- B
The old allocation is immediately freed whenever a pointer is reassigned
- C
The old allocation becomes unreachable if no pointer still stores its address
- D
The new allocation is automatically merged with the old allocation
Correct answer
CThe old allocation becomes unreachable if no pointer still stores its address
Explanation
If the only pointer to the old allocation is overwritten, the program loses the address needed to access or free that memory. The allocation is then orphaned.
- A
- 12
Why is a fixed-size array inconvenient when a program later needs to store more elements than anticipated?
- A
It stores each element at an unrelated address, preventing traversal
- B
Its size is established in advance, so accommodating more elements may require a new allocation and copying
- C
Its memory is automatically freed as soon as another element is requested
- D
Its elements cannot be accessed by index once the array contains data
Correct answer
BIts size is established in advance, so accommodating more elements may require a new allocation and copying
Explanation
An array has a fixed size. Growing it may require allocating a larger chunk and copying the existing values into it before adding new elements.
- A
- 13
When growing an array of n elements requires copying all existing elements, what is the copying work's asymptotic running time?
- A
O(n), because each of the n existing elements may need to be copied once
- B
O(1), because only the new element determines the amount of work
- C
O(logn), because copying repeatedly halves the array
- D
O(n2), because each element must be compared with every other element
Correct answer
AO(n), because each of the n existing elements may need to be copied once
Explanation
Resizing by copying requires work proportional to the number of existing elements. Copying n elements therefore takes linear time, O(n).
- A
- 14
What is the key advantage of storing sorted values contiguously in an array when searching?
- A
A sorted array guarantees that every search takes constant time
- B
The array automatically relocates each value to the location being searched
- C
The array stores a pointer to every possible search result
- D
Random access allows binary search to examine middle positions efficiently
Correct answer
DRandom access allows binary search to examine middle positions efficiently
Explanation
Arrays allow direct indexing, or random access. That makes it possible to inspect middle elements and repeatedly halve the search range with binary search.
- A
- 15
What does
reallocprovide when a program wants to change the size of an existing allocation?- A
A replacement for checking whether memory allocation succeeded
- B
A way to append an element without changing the allocation's size
- C
A guarantee that the original allocation will remain at the same address
- D
A request to resize an existing chunk, with the function handling any needed data copying
Correct answer
DA request to resize an existing chunk, with the function handling any needed data copying
Explanation
reallocresizes an existing allocation, growing or shrinking it, and handles copying the old data if necessary. The program should still check for failure and use the returned pointer appropriately. - A
- 16
Why is a temporary pointer commonly used to store the result of
realloc?- A
It causes the resized allocation to contain twice as many elements
- B
It prevents
reallocfrom copying existing data - C
It preserves the original pointer if the resizing request fails
- D
It automatically frees the resized allocation at the end of the statement
Correct answer
CIt preserves the original pointer if the resizing request fails
Explanation
If the result is assigned directly to the only pointer to the old allocation and resizing fails, the old address may be lost. Storing the result temporarily allows the program to check for
NULLbefore updating the original pointer. - A
- 17
What does
list[i]mean whenlistpoints to a dynamically allocated chunk containing integers?- A
The number of bytes remaining after element
i - B
The address of a separate allocation created for element
i - C
The
ith byte after the start, regardless of the size of an integer - D
The integer at index
iin that chunk, reached using pointer arithmetic
Correct answer
DThe integer at index
iin that chunk, reached using pointer arithmeticExplanation
Square-bracket notation works with a pointer to a contiguous chunk. The index advances by the size of the pointed-to type, so
list[i]accesses the integer at indexi. - A
- 18
Which header file is associated with the functions
malloc,free, andreallocin the content?- A
stdio.h, which declares these memory-management functions - B
ctype.h, which declares these memory-management functions - C
string.h, which declares these memory-management functions - D
stdlib.h, which declares these memory-management functions
Correct answer
Dstdlib.h, which declares these memory-management functionsExplanation
The content identifies
stdlib.has the header that declaresmalloc,free, andrealloc. - A
- 19
After successfully resizing an allocation and finishing with the old storage, what should the program ensure?
- A
The final allocation is eventually freed when it is no longer needed
- B
The final allocation is copied back into the original storage before use
- C
Every element is freed individually with a separate call to
free - D
The final pointer is set to the address of the old allocation
Correct answer
AThe final allocation is eventually freed when it is no longer needed
Explanation
Dynamically allocated memory should be released when it is no longer needed. After a successful resize, the program must also remember to free the allocation it ultimately uses.
- A
- 20
What is meant by saying that a conventional array has constant-time random access?
- A
The program can jump directly to an indexed element without traversing earlier elements
- B
The program can insert a new element anywhere without moving other elements
- C
The program can resize the array without allocating additional memory
- D
The program can search any unsorted array in a fixed number of comparisons
Correct answer
AThe program can jump directly to an indexed element without traversing earlier elements
Explanation
Random access means that an array element can be reached directly by its index, rather than following a sequence of links from the beginning.
- A
- 21
What is a node in the linked-list design described?
- A
A function that copies one list element to another
- B
A single pointer that stores every value in the entire list
- C
A structure containing a value and a pointer to another node
- D
A fixed-size array that must contain all list elements contiguously
Correct answer
CA structure containing a value and a pointer to another node
Explanation
Each node stores a value, such as an integer, and a pointer—often called
next—to another node in the list. - A
- 22
How does a program represent an initially empty linked list in the design described?
- A
By making the pointer to the first node equal to
NULL - B
By allocating one node whose
nextpointer points to itself - C
By making the first node's integer value equal to zero
- D
By leaving the list pointer uninitialized until a value is inserted
Correct answer
ABy making the pointer to the first node equal to
NULLExplanation
A list with no nodes can be represented by a pointer to its first node that is set to
NULL. - A
- 23
Why does inserting an integer into a linked list require allocating more than just the integer's storage?
- A
The list stores two copies of each integer for reliability
- B
The pointer field records the integer's decimal representation
- C
The node must also hold a pointer that links it to another node
- D
Every integer must be accompanied by a complete copy of the list
Correct answer
CThe node must also hold a pointer that links it to another node
Explanation
A linked-list node contains both the integer and a pointer field used to connect the node to the next node.
- A
- 24
Why can a node structure refer to another node through
struct node *next?- A
A pointer to a structure can be declared even though the structure's full size is not yet available at that point
- B
The declaration makes all nodes occupy one shared memory address
- C
The
nextfield contains a complete copy of the next structure - D
The
structkeyword automatically allocates the next node
Correct answer
AA pointer to a structure can be declared even though the structure's full size is not yet available at that point
Explanation
A node can contain a pointer to another node of its own structure type. The pointer stores an address; it does not embed a complete node within the node.
- A
- 25
What is the relationship between
n->numberand(*n).numberwhennpoints to a node?- A
They are equivalent ways to access the node's
numberfield - B
They access different nodes whenever the list has more than one element
- C
The first accesses a pointer field, while the second allocates an integer
- D
The first changes
n's address, while the second changes its type
Correct answer
AThey are equivalent ways to access the node's
numberfieldExplanation
The arrow operator is shorthand for dereferencing a pointer and then using the dot operator:
n->numberis equivalent to(*n).number. - A
- 26
When adding a node at the beginning of a linked list, which pointer update order preserves access to the existing list?
- A
Make the list point to the new node, then search for the old first node
- B
Set the old first node's
nextpointer toNULL, then discard the list pointer - C
Make the new node point to the old first node, then make the list point to the new node
- D
Free the old first node, then make the new node point to its address
Correct answer
CMake the new node point to the old first node, then make the list point to the new node
Explanation
First linking the new node to the old first node preserves the existing chain. The list pointer can then be updated to point to the new node.
- A
- 27
Why can replacing the list's first pointer with a new node's address before linking the new node cause a problem?
- A
It can orphan the old first node and the nodes reachable from it
- B
It forces the new node to contain a duplicate of every old value
- C
It makes every old node point backward to the new node
- D
It automatically sorts the list in descending order
Correct answer
AIt can orphan the old first node and the nodes reachable from it
Explanation
If the list's only pointer to the old chain is overwritten before the new node points to it, the old nodes become unreachable and their memory is leaked.
- A
- 28
How can a program find the end of a singly linked list?
- A
Compare every node's value with the value stored in the first node
- B
Start at the first node and follow
nextpointers until one isNULL - C
Jump directly to the final node using its array index
- D
Follow each node's pointer backward until reaching the first node
Correct answer
BStart at the first node and follow
nextpointers until one isNULLExplanation
In a singly linked list, traversal follows each node's
nextpointer. The end is reached when the current node'snextfield isNULL. - A
- 29
If a program inserts values into a linked list while keeping them sorted, what is the essential task for inserting a value in the middle?
- A
Find the appropriate neighboring nodes and update their links without losing the rest of the chain
- B
Replace the list with a fixed-size array containing the new value
- C
Change only the head pointer, leaving all other links unchanged
- D
Move every later node to a new contiguous memory location
Correct answer
AFind the appropriate neighboring nodes and update their links without losing the rest of the chain
Explanation
A middle insertion requires finding the correct position and changing links so the new node fits between its neighbors while the rest of the list remains reachable.
- A
- 30
Why can linked lists grow without relocating all their existing nodes?
- A
A new node can be allocated separately and connected with pointer updates
- B
All nodes are stored in a contiguous block that automatically expands
- C
The list reserves an infinite number of unused array positions
- D
Existing nodes are copied into the new node whenever the list grows
Correct answer
AA new node can be allocated separately and connected with pointer updates
Explanation
Nodes can be allocated individually wherever memory is available. Inserting a node changes links rather than requiring all existing values to be moved into a larger contiguous block.
- A
- 31
What capability is lost when data is changed from an array to a linked list?
- A
The ability to allocate additional storage dynamically
- B
Direct indexed access to an arbitrary element
- C
The ability to store values in a chosen order
- D
The ability to connect one element to another
Correct answer
BDirect indexed access to an arbitrary element
Explanation
A linked list must be traversed by following pointers from its beginning, so it does not provide an array's direct random access by index.
- A
- 32
Why is binary search not generally efficient on a linked list?
- A
Binary search requires every element to be stored at a different address
- B
Linked lists do not allow their values to be kept in sorted order
- C
It cannot jump directly to the middle element and must follow links to reach nodes
- D
A linked-list node can store only a character, not a number
Correct answer
CIt cannot jump directly to the middle element and must follow links to reach nodes
Explanation
Binary search relies on efficiently accessing middle positions. A linked list provides no direct indexing, so reaching a middle node requires traversing the links.
- A
- 33
In the worst case, how long can searching a linked list take?
- A
O(logn), because each pointer eliminates half the remaining nodes
- B
O(n2), because every pair of nodes must be compared
- C
O(1), because the first pointer contains every list value
- D
O(n), because the search may need to traverse all n nodes
Correct answer
DO(n), because the search may need to traverse all n nodes
Explanation
A search may have to follow the list through every node before finding a value or determining that it is absent, giving worst-case linear time.
- A
- 34
When inserting into a sorted linked list, why can finding the insertion position take linear time?
- A
Every pointer update requires comparing all pairs of values
- B
A sorted list requires binary search to visit every node
- C
The program may have to traverse many nodes to locate the correct position
- D
The program must copy all nodes into a larger contiguous allocation
Correct answer
CThe program may have to traverse many nodes to locate the correct position
Explanation
To preserve sorted order, a program may need to walk through the list until it finds the correct position. In the worst case, that traversal takes O(n) time.
- A
- 35
How does a binary search tree restore an efficient search strategy while still linking nodes dynamically?
- A
Each node points only to the immediately following value
- B
Each node can have left and right children arranged by value
- C
The tree keeps all values in one contiguous memory block
- D
Each node stores every other value in a sorted array
Correct answer
BEach node can have left and right children arranged by value
Explanation
A binary search tree uses nodes with left and right pointers. Its value ordering lets a search choose a subtree instead of scanning every node.
- A
- 36
What makes a tree a binary tree in the sense described?
- A
Each node has at most two children
- B
Each node has exactly two children
- C
The tree contains exactly two values
- D
Each node stores a value using two bytes
Correct answer
AEach node has at most two children
Explanation
The 'binary' property means each node has no more than two children; a node may have zero, one, or two.
- A
- 37
Which ordering rule defines the binary search tree described?
- A
Every left child is smaller, but values farther down are unrestricted
- B
Values in a node's left subtree are larger, and those in its right subtree are smaller
- C
Values in a node's left subtree are smaller, and those in its right subtree are larger
- D
Values alternate between smaller and larger at each tree level
Correct answer
CValues in a node's left subtree are smaller, and those in its right subtree are larger
Explanation
For each node, the values to its left are smaller and the values to its right are larger. The rule applies recursively throughout the subtrees.
- A
- 38
When searching a binary search tree for a value smaller than the current node's value, which subtree should be searched?
- A
Both subtrees, because their values are unordered
- B
The left subtree, because its values are smaller
- C
The right subtree, because its values are smaller
- D
Neither subtree, because the current node must match
Correct answer
BThe left subtree, because its values are smaller
Explanation
The tree's ordering rule places smaller values in the left subtree, so a search for a smaller value proceeds left.
- A
- 39
In a recursive tree-search algorithm, what should happen when the subtree pointer is
NULL?- A
Return false because there is no node in that subtree to match
- B
Return true because
NULLmarks the successful end of every search - C
Restart the search from the root without checking any nodes
- D
Allocate a new node containing the value being searched for
Correct answer
AReturn false because there is no node in that subtree to match
Explanation
An empty subtree cannot contain the sought value. Returning false for a
NULLsubtree is the recursive search's base case. - A
- 40
If the target value is neither smaller nor greater than the current node's value, what conclusion can a binary search tree search make?
- A
The current node contains the target value
- B
The tree must be empty
- C
The target must be in the right subtree
- D
The target must be in the left subtree
Correct answer
AThe current node contains the target value
Explanation
If the current node exists and the target is neither less than nor greater than its value, the values are equal, so the search succeeds.
- A
- 41
For a balanced binary search tree with n elements, what search time is described?
- A
O(n), because every node must be visited in order
- B
O(logn), because each decision can discard a substantial subtree
- C
O(1), because the root stores the address of every value
- D
O(n2), because each node must be compared with every other node
Correct answer
BO(logn), because each decision can discard a substantial subtree
Explanation
In a balanced tree, each left-or-right decision reduces the remaining search region substantially, giving logarithmic search time.
- A
- 42
Why can repeatedly inserting values into a binary search tree make its search performance worse?
- A
A tall tree cannot contain pointers to dynamically allocated nodes
- B
The tree automatically loses its ordering rule after each insertion
- C
The left and right pointers become contiguous array indices
- D
The tree can become unbalanced and tall, requiring more steps to reach a value
Correct answer
DThe tree can become unbalanced and tall, requiring more steps to reach a value
Explanation
An unbalanced tree can become very tall, so searches may follow many links rather than benefiting from the logarithmic height of a balanced tree.
- A
- 43
How can a tree remain balanced as values are inserted, according to the content?
- A
Algorithms can rearrange pointer relationships without moving the nodes themselves
- B
The program can discard values that would make one side taller
- C
The program can convert every node into an array element after each insertion
- D
The program can make every node have exactly two children
Correct answer
AAlgorithms can rearrange pointer relationships without moving the nodes themselves
Explanation
Balancing algorithms can update pointers to rearrange the tree's structure. The nodes need not be physically moved in memory.
- A
- 44
What combination of structures makes up the hash table described?
- A
A binary search tree whose leaves are fixed-size queues
- B
An array of buckets, with linked lists available to handle collisions
- C
A trie with one pointer leading to every possible word
- D
A single linked list whose nodes contain sorted arrays
Correct answer
BAn array of buckets, with linked lists available to handle collisions
Explanation
The hash table described combines an array with linked lists in its buckets, allowing multiple values to be stored when they map to the same bucket.
- A
- 45
What does a hash function do in a hash table?
- A
It maps an input to an output used to choose an array bucket
- B
It sorts all stored inputs before searching them
- C
It copies an input into every bucket in the array
- D
It guarantees that each input has a unique output
Correct answer
AIt maps an input to an output used to choose an array bucket
Explanation
A hash function takes an input, such as a name, and produces an output used to select a bucket in the array.
- A
- 46
If a hash function uses the first letter of a name, what does the output typically represent?
- A
The array position corresponding to that first letter
- B
The location of the name's final letter in memory
- C
The name's position in alphabetical order among all stored names
- D
The number of letters in the full name
Correct answer
AThe array position corresponding to that first letter
Explanation
A first-letter hash can map a name to the bucket associated with its initial letter, such as the bucket for H.
- A
- 47
What is a collision in a hash table?
- A
A value is stored outside the array's allocated memory
- B
Two inputs map to the same bucket
- C
A hash function returns a null pointer
- D
A linked list contains nodes in sorted order
Correct answer
BTwo inputs map to the same bucket
Explanation
A collision occurs when an input maps to a bucket that already contains another input mapped there.
- A
- 48
How does the described hash table handle a collision when a bucket already contains a name?
- A
It moves every other entry to a different array
- B
It changes the stored names into tree roots
- C
It overwrites the existing name and discards the new one
- D
It links the colliding entry into that bucket's linked list
Correct answer
DIt links the colliding entry into that bucket's linked list
Explanation
The design uses a linked list in a bucket so that multiple entries that map to the same array position can be stored there.
- A
- 49
Why can hashing only the first letter lead to slow searches in the worst case?
- A
A first-letter hash forces every input into a separate linked list
- B
The array cannot be indexed when its buckets are labeled with letters
- C
Many inputs could share that letter and build a long linked list in one bucket
- D
The first letter is unavailable until every name has been searched
Correct answer
CMany inputs could share that letter and build a long linked list in one bucket
Explanation
If many names begin with the same letter, they all map to one bucket. Searching that bucket can then require traversing many entries.
- A
- 50
What is the trade-off involved in using more characters of each name to choose a hash-table bucket?
- A
More characters make the hash function independent of its input
- B
Fewer buckets reduce collisions but increase direct indexing
- C
More buckets guarantee no collisions while using less space
- D
More buckets may reduce collisions, but require more space
Correct answer
DMore buckets may reduce collisions, but require more space
Explanation
Using more characters can distribute entries across more buckets and reduce collisions, but the larger bucket array consumes additional memory.
- A
- 51
Why does using the first two letters instead of the first letter not guarantee that collisions disappear?
- A
Linked lists cannot store names longer than two letters
- B
Different names can still share the same first two letters
- C
The array cannot represent combinations of letters
- D
A two-letter hash always maps every input to the same bucket
Correct answer
BDifferent names can still share the same first two letters
Explanation
Even when the hash uses two characters, names with the same two-character prefix still map to the same bucket.
- A
- 52
What is the theoretical worst-case search time for a hash table if many inputs collide into one bucket?
- A
O(logn), because a collision list is always balanced
- B
O(n2), because each collision creates a separate array
- C
O(n), because searching the bucket may require examining all n inputs
- D
O(1), because every bucket is directly indexed
Correct answer
CO(n), because searching the bucket may require examining all n inputs
Explanation
If all inputs end up in one bucket, its linked list can contain all n entries, making a search through it linear.
- A
- 53
Why can a hash table still be practically fast even though its theoretical worst case is linear?
- A
A hash table automatically converts every bucket into a binary search tree
- B
Theoretical worst-case analysis excludes inputs with repeated initial letters
- C
A good distribution usually keeps bucket lists much smaller than the entire collection
- D
A direct array lookup guarantees that collisions never occur
Correct answer
CA good distribution usually keeps bucket lists much smaller than the entire collection
Explanation
With a reasonably effective hash function and a suitable distribution, most buckets contain relatively few entries, so practical searches are often much faster than the worst case.
- A
- 54
What is a trie, as described in the content?
- A
A hash table in which every bucket is guaranteed to be empty
- B
A tree in which each node is essentially an array of possible next characters
- C
A linked list in which each node stores an entire dictionary
- D
An array that contains one complete copy of every stored word
Correct answer
BA tree in which each node is essentially an array of possible next characters
Explanation
A trie is a tree whose nodes are arrays used to branch according to characters in a word or name.
- A
- 55
How is a word such as
Harryrepresented in the described trie?- A
By storing its letters in a linked list without a word-ending marker
- B
By following character branches for H, a, r, r, and y, marking where the word ends
- C
By placing the complete word in every array node along one branch
- D
By storing only its first letter in the root array
Correct answer
BBy following character branches for H, a, r, r, and y, marking where the word ends
Explanation
The trie follows a branch for each successive character in the word. A marker at the final character indicates that a complete word ends there.
- A
- 56
Why can two words with a shared prefix reuse part of a trie?
- A
Every word is assigned the same root array regardless of its spelling
- B
A shared prefix is stored by combining both words into one value
- C
They follow the same character branches until their letters diverge
- D
The trie stores only the last letter of each word
Correct answer
CThey follow the same character branches until their letters diverge
Explanation
Words with the same initial characters follow the same branches in the trie until they reach a character where their paths differ.
- A
- 57
Why is trie lookup described as constant time with respect to the number of stored words?
- A
The number of branches is always equal to the number of stored words
- B
Every trie stores all words in a single constant-size array
- C
The trie compares the query with every stored word simultaneously
- D
The lookup follows only the characters of the queried word, not all other stored words
Correct answer
DThe lookup follows only the characters of the queried word, not all other stored words
Explanation
The search follows the input's character path. Its steps depend on the word's length rather than on how many other words are stored.
- A
- 58
What resource cost is associated with a trie compared with its fast lookup?
- A
It cannot store words that share prefixes
- B
It can use substantial memory for its many character-indexed arrays
- C
It requires moving every stored word whenever a branch is added
- D
It requires sorting every branch after each character is read
Correct answer
BIt can use substantial memory for its many character-indexed arrays
Explanation
Tries can consume a great deal of memory because nodes contain arrays of possible character branches. Their fast lookup therefore comes with a space cost.
- A
- 59
What does FIFO mean for a queue?
- A
The first element added is the first one removed
- B
Elements are removed in alphabetical order
- C
The last element added is the first one removed
- D
The first element added is the last one removed
Correct answer
AThe first element added is the first one removed
Explanation
FIFO means 'first in, first out': elements leave a queue in the order in which they were added.
- A
- 60
Which pair names the basic operations associated with a queue?
- A
hashadds an element, andsortremoves an element - B
enqueueadds an element, anddequeueremoves an element - C
pushadds an element, andpopremoves an element - D
leftadds an element, andrightremoves an element
Correct answer
Benqueueadds an element, anddequeueremoves an elementExplanation
The queue operations are called enqueue, meaning to join the queue, and dequeue, meaning to leave it.
- A
- 61
Which situation best illustrates a queue's FIFO behavior?
- A
A tray stack gives out the most recently placed tray first
- B
A tree search visits the smaller child before the larger child
- C
A printer completes jobs in the order they were submitted
- D
An inbox displays the newest message before older messages
Correct answer
CA printer completes jobs in the order they were submitted
Explanation
A printer queue can process jobs in their arrival order: the first job submitted is the first one printed.
- A
- 62
What does LIFO mean for a stack?
- A
The last element added is the last one removed
- B
The last element added is the first one removed
- C
Elements are removed in numerical order
- D
The first element added is the first one removed
Correct answer
BThe last element added is the first one removed
Explanation
LIFO means 'last in, first out': the most recently added element is removed first.
- A
- 63
Which pair names the basic operations associated with a stack?
- A
enqueueadds an element, anddequeueremoves the first element - B
insertadds an element, andsearchremoves the matching element - C
pushadds an element, andpopremoves the top element - D
leftadds an element, andrightremoves the bottom element
Correct answer
Cpushadds an element, andpopremoves the top elementExplanation
Stack operations are conventionally called push and pop. Pushing adds an element, and popping removes the top element.
- A
- 64
Why does an email inbox that puts the newest messages at the top behave like a stack?
- A
Messages are always displayed in the order they arrived
- B
Older messages are automatically deleted when new ones arrive
- C
Messages are grouped by the first letter of the sender's name
- D
The most recently added messages are presented first
Correct answer
DThe most recently added messages are presented first
Explanation
If the newest messages appear first, the most recently added items are at the top, matching the stack's last-in, first-out behavior.
- A
- 65
What is a dictionary as an abstract data structure?
- A
A structure that maps keys to values
- B
A structure that contains only alphabetically sorted arrays
- C
A structure that stores only values in arrival order
- D
A structure that guarantees every search takes linear time
Correct answer
AA structure that maps keys to values
Explanation
A dictionary is an abstraction for mapping keys to values, such as words to associated information or a word's presence in a vocabulary.
- A
- 66
How can a hash table serve as a building block for a dictionary?
- A
It can organize keys so the program can retrieve or test their associated values
- B
It replaces keys with pointers that cannot be searched
- C
It stores values only if they are inserted in alphabetical order
- D
It turns each key into a queue of unrelated values
Correct answer
AIt can organize keys so the program can retrieve or test their associated values
Explanation
A hash table can implement the dictionary abstraction by organizing keys into buckets, allowing the program to look up entries such as words in a vocabulary.
- A

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