Data Structure Flashcards
4.2
What is an array?
An ordered, static set of elements
Can only store 1 data type
1D array is a linear array
How do we create a 1D array?
array[number]= {“values”}
How do we create a 2D array?
array_2d=new array[rows][columns]
How do we create a 3D array?
array_3d=new array[rows][columns][depth]
What is a record?
A row in a file and is made up of fields
How do we create a record in pseudocode?
(record name)=record
(data type)(field name)
…
end record
e.g(string firstname)
What is a list?
A data structure that consists of a number of items where the items can occur more than once
What are features of a list?
List values are stored non contiguously
Can contain elements of more than one data type
How do you create a list in psuedocode?
list (listname)=[“data”…]
What list operation checks if its empty?
(listname).isEmpty()
What list operation adds a new value to the end of the list?
(listname).append(data)
What list operation returns the length of the list
(listname).length()
What list operation returns the position of an item
(listname).index(data)
What list operation inserts a value at a given position
(listname).insert(position,data)
What list operation returns and removes the last value
(listname).pop()
What is a tuple?
An ordered set of values of any type that cant be changed
How do you create a tuple in pseudocode?
tuple1=(data,data…)
When should an array be used?
For a fixed size collection of elements and need random access to elements inside by index
(e.g list of student grades)
When should a record be used?
When should a list be used?
For a dynamic collection of elements that may change in size. They provide flexibility for adding,removing or modifying elements.
(e.g student record in school system)
What is a linked list?
A dynamic data structure that is used to hold an ordered sequence
What are the features of a linked list?
Data doesn’t have to be held in contiguous data locations
Each item is called a node and contains a data field called a pointer
What does the data field contain?
Value of the actual data apart of the list
What does the pointer contain?
Contains address of the next item in the list
List also stores a pointer identifying the next available space