1.4.2 Data Structures Flashcards

(58 cards)

1
Q

Array features

A

Ordered, mutable, static, one data type

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

Tuple features

A

Preferred, immutable, static, different data types

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

Record features

A

Fixed number of fields of different data types, implemented with each row as a tuple

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

Static vs dynamic

A

Dynamic data structures can change static data structures cannot change size

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

Examples of abstract data types

A

List, stack, queue, graph, tree, hash table, linked list

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

Examples of compound data types

A

Strings, arrays

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

Examples of primitive data types

A

Integer, boolean, real

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

Four operations in queues

A

Add item to rear of queue
Remove item from front of queue
Check if queue is empty
Check if queue is full

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

Adding to circular queue

A

next index = (current +1) MOD len

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

Implementation of a dynamic list

A

New location taken from the heap of memory locations for dynamic allocation
When item is deleted, memory location is returned to heap, pointers keep list in user-specified order

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

List operations

A

isEmpty()
append(item)
remove(item)
count(item)
len(list)
index(item)
insert(pos,item)
pop(pos) - default -1

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

Linked list features

A

Composed of nodes with two parts: the data and the pointer
Start pointer identifies first node
Nextfree pointer shows index of next free space in array
(ALPHABETICAL/ASCENDING ORDER)

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

Linked list operations

A

.data()
.pointer()

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

Stack operations

A

push(item)
pop()
isFull()
isEmpty()
peek()
size()

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

Stack overflow error

A

Attempting to push onto a full stack

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

Stack underflow error

A

Trying to pop from a stack that is empty

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

Call stack

A

System level data structure that provides mechanism for passing parameters and return addressees to subroutines

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

Stack function in subroutine calls

A

The parameters are saved onto the stack
The address where execution will return to is saved
Execution is transferred to the subroutine code

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

Stack function in subroutine execution

A

Stack space is allocated for local variables (recursive routines use much more space and more often cause overflow errors)
Subroutine code executes
Return address received
Parameters popped
Execution transferred back to return address

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

Stack uses

A

Undo/redo in word processors
Holding website addresses just visited
Interrupts

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

Hashing definition

A

Address of data to be stored is calculated from the data itself using a hashing algorithm (often involves MOD)

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

Collision

A

When the hashing algorithm generated the same address for different primary keys (IMPOSSIBLE TO AVOID)

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

Dealing with collisions

A

Put in next free spot, or next third free spot (must ensure every cell in table is covered)

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

Searching for items in a hash table

A

Perform hashing algorithm on item
If not in that cell check next
Keep checking until item or empty cell is found
Empty cell means item is not in table

25
Deleting items from a hash table
Replace with dummy item/marker
26
Examples of hashing algorithms
Mid-square Folding
27
How to hash alphanumeric data
Find ASCII value then hash that
28
Mid-square method
Square the item Extract middle portion of digits MOD the d
29
Folding method
Divide into equal sized pieces Add pieces together MOD
30
Dictionaries
ADT made of associated pairs (key and value)
31
Hashing and dictionaries
Dictionaries are unordered and address of key:value is calculated using a hashing algorithm (much quicker access times than array/list)
32
Dictionary operations
Add new k:v pair Delete k:v pair Amend v in k:v pair Return v if given k Key in dict? Return length of dict
33
Graph
Set of nodes connected by edges, edges can be weighted (cost of traversal)
34
Undirected graph
All edges are bidirectional (same cost both ways)
35
Directed graph
Edges have weights in a specific direction
36
Two ways to represent graphs
Adjacency matrix Adjacency list
37
Adjacency matrix
Each row and column represents a node, item at [row,column] indicates weight of path row -> column
38
Advantages of adjacency matrix
Convenient to work with More visually understandable Adding edges is simple
39
Disadvantages of adjacency matrix
A sparse graph will leave most of the cells empty ^ Wastes lots of memory space
40
Adjacency list
Dictionary of dictionaries - key in the dictionary is a node. Value of that key is a dictionary with k:v pairs of nodes connected to:weights of edges
41
Adjacency list advantages
Only uses storage for the connections that exist - saves space Good for representing large, sparse graphs
42
Applications of graphs
Computer networks Web pages and links Maps Project management
43
Features of trees
Root, branches, leaves
44
Tree definition
A connected, undirected graph with no cycles
45
Rooted tree definition
One node is the root, each node except the root has one unique parent
46
Binary tree definition
A rooted tree where each node has a maximum of two children
47
Parts of a node
Data, left pointer, right pointer
48
Binary tree traversals
Pre-order, in-order, post-order, breadth-first
49
Pre-order traversal
NLR - used to produce pre-fix or Polish notation
50
In-order traversal
LNR - Traverses nodes in sequential order
51
Post-order traversal
LRN - used to produce post-fix or reverse polish notation
52
Breadth-first traversal
Reads each level (top to bottom) from left to right
53
Balanced binary tree
Nodes are distributed to height is kept to a minimum so it is more efficient for searching
54
Three cases of deleting nodes
Is a leaf Has one child Has two children
55
Deleting a leaf
Just delete
56
Deleting a node with one child
Move up subtree with the child replacing the deleted node
57
Deleting a node with two children
Replace node with the next highest node in the whole subtree. Then repeat deleting process with that node - sometimes entire subtree will need to be rebuilt
58
Uses for a tree
NOT FOR EDITING/DELETING Designed to be made, then traversed - very quick to traverse/search