1.4 Relation between data structures and algorithms Flashcards
What do data structures define?
How data is organized and stored, and the operations performed on the data structure.
What is a common operation for data structures?
Inserting, removing, and searching for data.
True or False: The algorithm to append an item to a linked list is the same as for an array.
False
Fill in the blank: The algorithm to append an item to a linked list points the tail node’s next pointer and the list’s tail pointer to the _______.
new node
What is the first step in the algorithm to append an item to an array?
Determine the current size of the array.
In the ListAppend algorithm, what happens if the list is empty?
list⇢head and list⇢tail are set to newNode.
What does the ArrayAppend algorithm do after increasing the array size?
Assigns the new item as the last array element.
What does the GetCurrentSize function return?
The length subitem of the values.
What is the purpose of the topSales array in the DisplayTopFiveSalespersons algorithm?
To store the top five salespersons sorted by their total sales.
What initial values are assigned to the topSales array elements?
All elements are initialized with a negative sales total.
Which of the following is NOT equal to the number of items in the topSales array?
allSalesperson⇢length
To adapt the algorithm to display the top 10 salespersons, what modifications are required?
Both the array creation and all loops.
True or False: If allSalespersons has length 3, DisplayTopFiveSalespersons() displays five elements.
True
What does the algorithm do when a salesperson’s total sales is greater than the last topSales element?
Assigns the last element in topSales with the current salesperson and sorts topSales.
What is the output of the DisplayTopFiveSalespersons algorithm?
The top five salespersons.
What is the significance of the SortDescending function in the DisplayTopFiveSalespersons algorithm?
It sorts topSales in descending order based on total sales.
What data structure is used in the algorithm that determines a list of the top five salespersons?
An array.
What happens to the topSales array if a new salesperson qualifies?
The last element is updated, and the array is sorted.
Fill in the blank: The algorithm to append an item to an array requires _______ to increase the array size.
increasing the array size by one
What is the first item accessed in an array?
array[0]
What pointer does the tail node in a linked list point to when a new node is appended?
The new node.