Data types and structures Flashcards
Select the most appropriate data types and structures for the following data:
a) 222
b) 2.95
c) True
d) Panda
e) 019234
f) Customer: {Phoebe, Corp, 08/08/2018, 123 Fourth Street, Fifthsville, VIC, 3888}
g) Players: {Wanda, Greg, Tuan, Rishad, Dillon, Nicole, Shveta, Ramesh}
h) Stock: {“potatoes”: 300kg, “cauliflower”: 344kg, “peas”: 120kg, “carrots”: 403kg}
i) -
j) 0
a) Integer, as it is a whole number.
b) Floating point, as it has decimal places.
c) Boolean
d) String
e) string, as it has a leading 0.
f) Record, as it is a collection of related data with differing data types.
g) Array, as it is a collection of related data of the same data type (string).
h) Dictionary, as it is a series of (key, value) pairs.
i) Character, as it is a single punctuation unit.
j) Integer or Boolean. It is a whole number, but it is also the integer representation of “False”.
A computer program runs an algorithm on very large numbers and displays an incorrect output number: 2,147,483,647. Explain what has most likely occurred.
The issue likely results from an integer overflow on a 32-bit system, where the number surpasses the maximum allowed value, causing the error and displaying the maximum number allowed.
What is the difference between a hash table and a dictionary?
A hash table computes the key index using a hash function to store elements (1, New York).
Dictionaries use unprocessed (key, value) pairs (Concrete jungle, New York).
When would you use a record over an array to store a collection of related values?
A record could be used over an array when storing a collection of related values that have different data types.
Arrays generally only support single data type collections.
Which data structure is best for a café’s ordering system to ensure kitchen orders are cooked in the order they’re received?
The suitable data structure is a queue, where orders are processed in the order they arrive, following a “first in, first out” principle.
Which data structure is best for a playlist application where newly added songs play next, ahead of existing ones?
The suitable data structure is a stack, where the playlist adds new songs at the front, pushing existing songs back. This follows a “last in, first out” approach, characteristic of a stack.