Data structures Flashcards

1
Q

def Variable

A

a Variable is a named reference to a memory location that stores data that can change during the runtime of the program

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

why is declaring variable type important

A

So that the computer knows how much memory space it has to allocate for the data

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

def Constant

A

named reference to a memory location where the data inside the constant cannot change during the runtime of the program

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

whats an ADT(abstract data type)

A

ADT is logical description of how we view data and the possible operations
e.g queue of print jobs, stack of books, list of tasks to do

Only concerned w/ what data is representing, not how its constructed

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

2d array: array[x,y]

which is column which is row

A

row = x
column = y

Remember matrices (3x1)

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

What are the pointers used in a queue
and the important variables to use in queue

A

Front
Rear
maxSize
currentSize

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

In memory, after the first elements memory location, where are the other elements stored

A

in the next consecutive memory location

In low level langs, amount of data needed 4 array is reserved, starting from 1st reserved mem location, it checks the next mem location, until end of reserved mem locations 4 array.

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

where do dynamic data structures allocate and deallocate memory from

A

the heap - an area of memory used for ____________________

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

3 types of queues

A

linear
circular
priority

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

in what manner do queues operate?

A

FIFO

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

advantages priority queue

A

gives preference to more important items

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

how do priority queues work

A

Items qiven priority
If item has higher priority than item in front of it, it can jump in front of it
If same or greater, stay put

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

in what manner do stacks operate

A

FILO

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

4 operations of a queue

A

enQueue - add an item to the REAR of the queue
deQueue - remove and return an item from the FRONT of the queue
isFull - check if queue is full
isEmpty - check if queue is empty

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

Circular queues

A

Reuse the empty spaces freed by dequeueing from front of the array

(rear + 1) MOD max

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

excessive amount of allocation without deallocation leads to

A

overflow

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

example dynamic data structre
example static data structure

A

dynamic: list

static: array

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

advantage using queues in a list

A

list is dynamic data structure, will use enough memory for number of elements inside the list

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

disadvantage using queues as a list

A

can keep adding items to the list - eventually all the memory will be exhausted and cant keep adding more

To solve this, make it so list has maxsize
Can change the maxsize when needed if need to add more items

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

advantages of linear queues (created using arrays)

A

simple to program
predictable memory usage

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

what to do w/ pointers when dequeue item

A

move the front pointer (and rear if needed)

You dont actually delete item

When need to add to slot where item is but not in queue, you overwrite it

Saves processing time

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

advantages circular queue

A

can reuse free spaces

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

What is an array

A

An array is a data structure that holds a number of data items or elements of the same data type.

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

disvantages linear queue

A

fixed length
single pass
cant reuse spaces

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

disadvantages circular queue

A

harder to program

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

disadvantages priority queue

A

additional processing required to keep order

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

features of array

A

Indexed - each element has its own index
Mutable - contents of array can change during runtime of program

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

list of list operations

A

isempty()
append(item)
remove(item)
count(item)
len(item)
index(item)
insert(pos,item)
pop()
pop(pos)

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

remove(item) does

A

remves first occurance of item from the list

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

count(item)

A

returns number of occurances of item from list

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

len(item)

A

returns num of items in list

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

insert(pos,item)

A

insert item at position pos

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

Implementing a queue as a list

A

No need for size variable as you have len function
maxSize needed to prevent exhauston of memory
isFull function needed

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

Common operations on lists

A

merging, sorting, searching, comparing lists

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

Linked Lists

A

dynamic ADT which can be implemented as array and pointers
Composed of nodes

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

what are nodes in linked lists composed of

A

the data
pointer of the next node (and of node pointing to it if doubly linked list)

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

Pointers in linked lists

A

Start pointer
Nextfree pointer
Pointer in each node pointing to nxt (or prev) node

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

Adding node to linked list

A

Store data in the node pointed to by the nextfree pointer
Adjust pointer of the previous item to point to the added item
Added item assumes the value of the pointer of the previous item before the item was added

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

deleting node in linked list

A

pointer of node before the deleted item points to node after the deleted item

deleted node points to nextfree index position after itself (might not be same value as nextfree pointer)

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

an application of stacks

A

reversing lists

any other good examples add them here

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

what pointers used in stacks + what variables

A

one pointer - the top of the stack
size, maxSize variables can be used

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

operations on stacks

A

push(item) - add item to top of the stack
pop() - removes and returns the item on the top of the stack
isFull() - check if stack is full
isEmpty() - check if stack is empty
peek() - return top item w/o removing it
size() - return num of items in stack

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

def overflow

A

attemping to push into a full stack

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

def underflow

A

attempting to pop from an empty stack

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

stack overflow def

A

a computer program tries to use more memory space in the call stack than has been allocated to that stack.

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

Call stack

A

system level data structure
provides mechanism for passing parameters + return addresses to subroutines

IN OTHER WORDS:
REMEMBERS THE PARAMETERS PASSED INTO SUBROUTINE + WHAT LINE THE SUBROUTINE WAS CALLED SO PROGRAM CAN REMEMBER WHERE TO GO BACK TO

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

Subroutine calls

A

calls to subroutine executed as follows:

1st step - parameters saved onto the stack
2nd - address to which program returns to after subroutine is executed saved onto the stack
3rd - execution transferred to subroutine code

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

Subroutine execution

A

subroutine executed as follows:

stack space allocated for local variables
subroutine code executes
return address retrieved
parameters popped
execution trasnferred back to return address

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

hashing is

A

Hashing is the practice of transforming a given key or string of characters into another value

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

how is the hashed item found in thedatabase

A

calculated from the data istelf, using hashing algo

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

hashing algo use cases

A

encryption
checking for errors in downloaded code
searching datasets
verifying integrity of data

24
Q

what is used to ensure records are assigned a unique address and how

A

hashing is used

some part of the record eg primary key is hashed to give a unique destination address

24
Q

what is the data structure that stores the results of hashing algorithms

A

hash table

24
Q

primary key def

A

unique identifier of a record

24
Q

whats a collision

A

When hashing algo returns same address for different primary keys

24
Q

Table of items to be inpuuted into hash algo size compared to hash table size

A

Hash table size must be bigger

24
Q

load factor def

A

The number of elements in a hash table divided by the number of slots.

24
Q

simplest method w/ dealing w/ collisions

A

put item in next available slot

24
Q

disvantage of put item in next available slot method hashing

A

leads to clustering of items

25
Q

how to make the method of puting an item in next slot hashing better

A

increment the skip e.g 1st skip is by 1, next is by 3, next is by 5 etc

25
Q

how big should the hash table be

A

prime number size

25
Q

good load factor size

A

0.7 or below

25
Q

Mid square method

A

square the item
take middle digits
perform mod step to get the address

if it has letters or symbols, take denary value of them

25
Q

folding method

A

divide item into equal isze pieces (last piece may be unequal size)
add pieces together (e.g 13+12 = 25)
perform mod step

25
Q

Why do you mod the key by number of slots - hashing

A

So the result can always fit in the table

25
Q

Searching for items in hash table if collision occured

A

From the slot it would have been placed in, check each next slot until the next empty space

25
Q

Dealing w/ deletion in hash table

A

When delete an item, put a dummy value in it e.g ‘Deleted’
That way when searching through, it is not treated as an empty space

25
Q

hashing characters + symbols

A

take their denary values from ascii table

25
Q

what is dictionary

A

ADT made up of key:value pairs
value is accessed via the key

25
Q

can you have dictionary in dictionary

25
Q

uses of dictionaries

A

ascii/unicode table
in translation program - foreign lang dictionary
trees + graphs can be implemented w/ dicts

25
Q

can multiple items have same key dictionary

25
Q

Dictionary operations

A

add new key:value pair to dict
delete a pair from dict
amend value in key:value pair
return value associated w/ a key
return true/false depending on whether key is in dict
return len of dict

25
Q

when hashing: are key:value pairs held in any particular order

25
Q

chaining

A

instead of storing actual data in hash table, you store pointer that point to where that data is stored

25
Q

3 attributes that data in linked list in hash table (chaining) has

A

key value
data
pointer to next node

25
Q

if there are multiple collisions in one slot, how does the chaining work

A

pointer pointing to next collided item (node a) is put in hash table
node a points to next collided item (node b)
node b point to node c etc

26
Q

When could chaining become a problem

A

If there is lots of clustering

will take time going thru linked list , too long of a list

26
Q

what direction undirected graphs

A

bidriectional

26
Q

what do edge weights represent

A

cost of travel

26
Q

graph def

A

set of vertices/nodes connected by edges/arcs

26
Q

directed graph aka

26
Q

2 ways a graph can be represented

A

adjacency list + matrix

26
Q

adjacency matrix

A

each row and column represent a node
item at [row,column] indicate connection

26
Q

in which graph will matrix be syymetric

A

undirected

26
Q

what could entries in adjacency matrix represent

A

edge weights

26
Q

advantages adjacency matrices

A

adding an edge/node is simple

27
Q

disavantage ajaceny matrix

A

sparse graph w/ little connections will leave most cells empty wasting mem space

27
Q

ajaceny list

A

list of nodes created
each node points to list of ajacent nodes

27
Q

representing a wegihted graph

A

can be represented as dict of dicts
each key in dict is the node
the value is a dict of adjacent edges + edge weights

27
Q

avantae ajaceny list

A

only uses storage for existing connections
good way to represent large sparse graph

27
Q

graph applications

A

computer netowrks
states in finite state machine
social networks
web pages + links
chemistry
project management
maps
search engines

27
Q

trees

A

an adt
has a root, branches and leaves

27
Q

can trees be weighted

27
Q

tree def

A

connected undirected graph with no cycles (unique path from each node to any other node)

27
Q

rooted tree

A

one node identified as root
each node except root has 1 unique parent

27
Q

terminology for trees

A

root
node
edge
child
parent
subtree
leaf

27
Q

nodes w/ no children

27
Q

binary tree def

A

a rooted tree with at max 2 children

27
Q

can you represent trees as matrices

28
Q

binary tree node - 3 parts

A

data
left pointer
right pointer

28
Q

binary search tree

A

nodes added in order given, first item as root
if item larger, put to right
if less, put to left

28
Q

2 types of traversal

A

depth first tree traversal (DFT)
breadth first tree traversal

28
Q

3 types of DFT

A

pre order - NLR
in order - LNR
post order - LRN

28
Q

where are subroutines for tree traversals put in when carried out

A

in a stack
in case backtracking needs to occur

28
Q

backtrackin def

A

Going back a step after there are no more options to explore down the route you just went

28
Q

avantage storing data in binary search tree

A

large chunks of data can be eliminated while searching for data

28
Q

balanced binary trees

A

nodes distributed in a way height kept to a minimum
leads to efficient searching

28
Q

deleting leaf node

A

pointer of parent pointing to leaf changes value to -1

28
Q

deleting node w/ one child

A

child takes place of deleted node
parent of deleted node points to child of deleted node

28
Q

deleting node w/ 2 children

A

next largest number replaces the deleted node
parent of deleted node has its pointers changed

28
Q

deleting nodes - why may they be bad

A

whole tree may have to be rebuilt - time consuming
trees used for searching, shouldnt be used as a generalised ADT