Data Structures Flashcards
What data type is an integer and why?
Primitive - as it can only contain 1 value
What are some examples of primitive data types?
Integers
What is a compound/composite data type? What is an example?
More than 1 primitive data types combined together for example, a record or a class
Define data structure
Collection of data that is organised to allow efficient processing
Define abstract data type
A conceptual model that describes how data is organised and which operations can be carried out on the data (i.e. delete, insert) from the perspective of an end user who does not know how it is implemented
What do static data structures do with memory? Who controls this?
Reserves memory for a set amount of data - the programmer establishes this in advance
How is an array usually implemented?
As a static data structure that is fixed in size and can only contain elements of the same data type
What can and cannot be changed in a static data structure? What would you need to do if you wanted to change something that cannot be changed?
The contents can be changed however the size of it cannot be changed - if you needed an array of a different size, you would need to create a whole new array and then copy the contents from the original array to the new structure
How are static data structures efficient?
Can access elements directly (by index)
How are static data structures inefficient?
In terms of memory use - for example, if you allocate a space worth 100 elements but when running it only uses 10 - waste of memory. On the other hand, if too less memory is allocate, the program can crash when run due to insufficient memory
Why are dynamic data structures better than static data structures?
They are memory efficient and the number of data items that it can hold is limited only by the overall memory location to the program
What is an example of the dynamic data structure, a linked list, and state it’s advantages and disadvantages
Linked list:
+: size is not predetermined
-: elements cannot be readily accessed directly as they are accessed by memory location rather than index
Where is memory for dynamic data structures taken from? What does this do?
The memory heap - allocated memory for a program at runtime
Define array
Data structure that holds a number of data items/elements of the same type
What index do most languages use when identifying a position in an array?
0
What type of data structure is an array?
A static data structure
What do you need to ensure you refer to when retrieving a particular value from an array?
The correct index
How can you envisage a two dimensional array?
A table with rows and columns
What is another word for a two dimensional array?
Matrix
Which indexes do you need when implementing a two dimensional array
Column index and row index
What order do the indexes for a two dimensional array go in?
Column and then row
How are items positioned in a 3 dimensional array?
Using 3 indexes
What is a field?
A fixed number of variables
What is a record?
A data structure that consists of a fixed number of variables (fields)
Do fields in a record need to have the same data type?
No
How would you create a record for player data? And then retrieve information from this record?
- Create a class that contains fields that state what attributes for each piece of information will be stored about the player
- Create a player record by using the PayerRecord() subroutine
- Store the details of the player: I.e.:
player1.playernumber= 1;
player1.DateOfbirth= new DateTime(1994,7, 3) - You need to specify the name of the record and the field that you need to retrieve information from the record ie.
console.WriteLine($”Name: {player1.playernumber}{player1.dateOfbirth}”);
Where is memory for a dynamic data structure taken from?
The memory heap
What is the heap?
Amount of memory allocated to a program at runtime
What is the default coding for text files? What is its main property?
UFT-8 = backward compatibility with ASCIIN which means it can take a text file that is encoded as ASCII and convert it to a human readable text without any compatibility issues.
What is the difference between a private and protected attribute?
A private attribute can be accessed (within its class) by derived subclasses however a public attribute can only be accessed within its class
Why are some attributes private whilst other methods are public?
Attributes are private so they cannot be altered throughout the program/outside the class however methods are public so certain fields can have a change in value without affecting the entire class.
What type of data structure is a stack? Why?
Dynamic - it uses unused memory
What concept is a stack an example of and why?
abstraction - conceptual model that describes how data is organised from the perspective of an end user that does not know how it is implemented
Where does a stack use memory from?
The heap
How can you delete items in a stack (impact on pointer too) and what does this do to the memory?
You can delete items by simply removing them and then moving the pointer to the next data item - when items are deleted, the memory location is freed up and returned to the heap
What are lists examples of?
Abstract data types
What happens if you PUSH an element in a stack?
The item goes to the very top of the list and the top pointer is moved to that element
What happens if you POP an element in a stack?
When you pop an element, it can mean you have either replaced, deleted or overwritten the top element - the element does not actually disappear but instead the top pointer moved to the next element in the list (the element you popped waits to be overwritten)