fundamentals of data structures Flashcards
data structure
the arrangment of data
one dimensional array
stores data in one direction
useful way of representing a vector
two dimensional array
stores data horizontally and vertically
useful way of representing a matrix
example:
triplets = [[a,b,c], [d,e,f], [g,h,i]]
triples[2,1] = h
binary files
formatted so only one a program can read them
text files
contain characters structured as lines of text
why files must be closed
closing free up resources, preventing corruption and ‘flushes’ the buffer
record
usually for a single entity
heterogenous
subprogram
an ‘out of line’ block that performs a specific task
(can be ither user written or pre existing)
how can subprogram be used
by calling their name in a statement causing them to be executed
how can data be passed in to a sub routine
through parameters (variables used for the input to the subroutine)
two types of subprograms
procedure (doesn’t return a value)
functions (returns a value
structured programming
improves the quality and clarity of code
pros for structured programming
code is more readable and easier to understand
easier to test
modules can be reused
steps in adding a record to a hash table
- apply hash function to calculate the hash value for the key .
- use the hash value to find the index in the hash table so that the new record could be stored.
- check if there is a record at the index. if yes, use a collision resolution technique.
- insert the new record at the index in the hash table and update the number of records in the hash table.
two components of a stack frame
local variables and parameters