Module 14: Dynamic Memory Continued Flashcards

1
Q

hash tables

A

data structure that employs an array (which may be on the stack or the heap and a hashing function. it may also include linked lists to allow for collisions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

multi-file development

A

refers to spreading your code across multiple files; the intent is to centralize common code that other developers could use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

key

A

portion of your data used to map to bucket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

value

A

bucket number in hash table array (aka index number)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

hash function

A

maps key to value (common variations follow)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

associative array

A

what a hash table actually is i.e., an array whose index is associated with your custom data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

collision

A

when more than 1 key maps to the same value, the result is a bucket that contains more than one data item. we use linked lists to allow collisions a “perfect” hash table has no collisions (but then it becomes more of a lookup table)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

load factor

A

number of entries in table or the number of buckets. represents a metric that allows you to determine the tradeoff between time to search and space costs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

function pointers

A

pointers that point to functions. the pointer stores the address in program memory of the first instruction in the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

arrays

A
  • need to allocate a fixed size, cannot grow if you need to add more entries
  • adding things to the end of an array is easy, if there is space
  • inserting or deleting from the middle of an array is painful, since you need to shift things in an array
  • finding things in an array is easy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

linked lists

A
  • easy to add new elements to the front or back as needed
  • inserting or deleting in the middle of the list is not a problem (but is tricky)
  • finding things in the list involves “traversing” the list until we find what we need
  • this is not hard but it is more time-consuming than addressing the exact element you desire
  • once the linked list gets long, finding things inside them becomes very time consuming
  • so, search is an issue with linked lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

review of our implementation of a hash table

A

combination of an array, linked lists, and a hashing function

  • gives us the “fast” addressability of an array with the efficiency of a dynamically allocated linked list
  • note: an array of linked lists is not a hash table (it lacks the hashing function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

to insert a node into a hash table:

A
  1. apply hashing function to the incoming data to determine the bucket it belongs to
  2. address the bucket
  3. insert the node into the linked list addressed by the bucket
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

to find a node in a hash table

A
  1. apply the hash function to the data we wish to find to reveal which bucket it’s in
  2. address the bucket
  3. search for the node in the linked list addressed by the bucket #
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

uses of function pointers

A

can “call” a function inside a function that has been passed as an argument

  • also referred to as a “callback” function
  • often used in asynchronous programming, event loops, and GUI programming
  • -if an “event” occurs (e.g. a certain button is clicked), caller’s function is executed to “handle” the event

offers tremendous flexibility in writing libraries used by other programmers

  • programmer uses a library and gives its flexibility by calling user code at runtime
  • -library runs another person’s code
  • -double-edged sword: lots of power, lots of problems!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly