1.4.2 DATA STRUCTURES

33 flashcardsby Sabs2023
Study these flashcardsFree · spaced repetition · iPhone, Android, Mac & web

All cards

1
what is immutable
data can not be changed
2
what is mutable
data can be changed
3
What is list
An ordered data structure in which values have an index and is non-contiguous; mutable and can store various data types
4
What is an array
Like a list(mutable) but its contiguous, ,static and only store one data type
5
What is tuple
Lists that are immutable, static but store various data types
6
static meaning
its size cannot be changed afterwards
7
dynamic meaning
its size can be changed afterwards
8
what stack
A LIFO structure which has a stack pointer pointing at top node
Items can only be added / removed from the top
9
what queue
A FIFO structure in which has two pointers FRONT and REAR that track the items. Items are added at the rear and removed from the front
10
Circular queue
a type of queue in which front and rear pointers can wrap around to reuse spaces
11
Priority queue
Items are given priority and those with the highest go to the front
12
what is linked list
Dynamic data structure in which each item is called a node, and contains an index, data and pointers which give location of next node
13
what tree
A data structure which consists of nodes and pointers.
14
What do trees have
root node , leaf nodes , edges/pointers and child nodes
15
whats a sub tree
A set of nodes and pointers from any single node down to its leaf nodes
16
Whats a binary tree
Type of tree which nodes can have up to two child nodes
17
How to delete nodes
1) If node is a leaf node - Just delete it
2) If node has one child node- Set previous pointer to child
3)If node has two child nodes. Set previous pointer to child which is next in a inorder traversal.
18
How to add to a linked list(if node is supposed to be in between)
1)Check if free space
2)Create the node and insert data in it
3)Have previous node point to it
4)Set new nodes pointer to point next node
5)Update free pointer
19
How to remove from linked list:(lets say ben)
1)Check if empty
2)Find Ben
3)Remove bens pointer
4)Update previous pointer to point to next node
5)Update free pointer
20
What graph
Data structure made of nodes and pointers.
Each node can have > 2 pointers and point to ANY nodes
21
What other special stuff with em?
Can point in two/one directions or not specify
Can be weighted
22
Uses of graphs
Mapping road networks for navigation
Social media network
Representing molecular structures
23
How to do breadth first search (A- B -E-G.
A-C
A-D -F
current node = CN
Result = R
Q= queue
1)Visit first node A. Place in CN and R
2)Visits all its 1st connections. B C D. Place them in Q and R
3)Find next CN which is B remove it from Q
4)Visits its 1st connections
- repeat until all found

A B C D E F G
24
How to do DEPTH first search (A- B -E-G)
A-C
A-D -F
1)Visit first node A. Place in S and R
2) Visit alphabetical next so B and visit the whole path. Putting them in S and R
3)When path end or same node pop stack until new connection
Repeat until all found
A B E G C D F
25
How to add in stack/queue
1)Check for overflow
2)Increment stack/ back pointer
3)Insert data
26
How to remove in stack/queue
1)Check for underflow
Stack:
2)Remove last item
3)Decrement pointer
Queue is opposite
27
Traversals?
Pre order- Root L R
Inorder - L Root R
Postorder - L R Root
28
whats the goal of a hash table?
Immediately find an item in un/sorted list without comparing items
29
How it works? key = initial data
1)Initial data passed into hash function
2)It converts it into hash address
3)Hash address tells where to store
30
Whats a collision
Two keys trying to take same address
31
How to counter collisions?
Open addressing - check next available spaces and store it there
Chaining - 2D array to store it. Overflow Linked list can be used
32
How is data in open addressing found?
Linear probing - function sends start position of where linear search can be done until its found
33
A good hash function should:
Be calculated quickly
Result in as few collisions as possible
Use as little memory as possible
Study all 33 cards for free