Data Structure Flashcards

4.2

1
Q

What is an array?

A

An ordered, static set of elements
Can only store 1 data type
1D array is a linear array

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

How do we create a 1D array?

A

array[number]= {“values”}

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

How do we create a 2D array?

A

array_2d=new array[rows][columns]

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

How do we create a 3D array?

A

array_3d=new array[rows][columns][depth]

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

What is a record?

A

A row in a file and is made up of fields

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

How do we create a record in pseudocode?

A

(record name)=record
(data type)(field name)

end record
e.g(string firstname)

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

What is a list?

A

A data structure that consists of a number of items where the items can occur more than once

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

What are features of a list?

A

List values are stored non contiguously
Can contain elements of more than one data type

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

How do you create a list in psuedocode?

A

list (listname)=[“data”…]

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

What list operation checks if its empty?

A

(listname).isEmpty()

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

What list operation adds a new value to the end of the list?

A

(listname).append(data)

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

What list operation returns the length of the list

A

(listname).length()

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

What list operation returns the position of an item

A

(listname).index(data)

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

What list operation inserts a value at a given position

A

(listname).insert(position,data)

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

What list operation returns and removes the last value

A

(listname).pop()

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

What is a tuple?

A

An ordered set of values of any type that cant be changed

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

How do you create a tuple in pseudocode?

A

tuple1=(data,data…)

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

When should an array be used?

A

For a fixed size collection of elements and need random access to elements inside by index
(e.g list of student grades)

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

When should a record be used?

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

When should a list be used?

A

For a dynamic collection of elements that may change in size. They provide flexibility for adding,removing or modifying elements.
(e.g student record in school system)

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

What is a linked list?

A

A dynamic data structure that is used to hold an ordered sequence

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

What are the features of a linked list?

A

Data doesn’t have to be held in contiguous data locations
Each item is called a node and contains a data field called a pointer

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

What does the data field contain?

A

Value of the actual data apart of the list

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

What does the pointer contain?

A

Contains address of the next item in the list
List also stores a pointer identifying the next available space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you traverse a linked list?
**Check** if linked list is **empty** **Start** at the **node** the **pointer** is **pointing to** **Output item at current node** **Follow pointer** to the **next node** **repeating** through each node **until the end** of the linked list When **pointer is null** it **signals end** of linked list has been reached
26
How do you add a node to a linked list?
Check if there is free memory to insert data into the node Add new value to the end of the linked list and update 'nextfree' pointer All other pointers are updated
27
What is a stack?
A last in first out data structure and is often implemented using an array so maximum size is known in advance
28
What does an isEmpty() stack operation do?
Checks if stack is empty by checking the value of the top pointer
29
What does a push(value) stack operation do?
Adds a new value to the end of the list Need to check stack is not full before pushing
30
What does a peek() stack operation do?
Returns the top value of the stack First checks stack is not empty by looking at value of the top pointer
31
What does an pop() stack operation do?
Removes and returns the top value of the stack First checks stack is not empty by looking at value of top pointer
32
What does a size() stack operation do?
Returns size of the stack
33
What does an isFull() stack operation do?
Checks if the stack is full and returns the boolean value, this compares stack size to the top pointer
34
What does a stack pointer do?
Points the the top of the stack, where next data will be pushed or popped
35
What happens when data is pushed onto a stack?
Data is pushed to position of the pointer Once pushed the pointer will increment by 1 to signify top of the stack
36
What is stack overflow?
Since a stack is a static data structure an attempt to push item onto a full stack is stack overflow Size cant change
37
What happens when data is popped from a stack?
Data is popped from the position of the pointer Once popped the pointer will decrement by 1 to point at the new top of the stack
38
What is stack underflow?
Since a stack is a static data structure an attempt to pop item onto an empty stack is stack underflow Size cant change
39
What is the pseudocode to check if a stack is empty?
function isEmpty if top == -1 then return True else return false endif endfunction
40
What is the pseudocode to check if a stack is full?
function isFull if top ==maxSize then return True else return false endif endfunction
41
What is the pseudocode to push an item onto a stack?
procedure push(item) if isFull() then print("Stack is full") else top = top+1 stack(top)=item endif endprocedure
42
What is the pseudocode to pop an item out of a stack?
procedure push(item) if isEmpty() then print("Stack is empty") else top = top-1 return item endif endprocedure
43
Whats the pseudo code to insert item into a linked list? LONNNGG WRITE IT
procedure insertItem(newItem) if nextFree == null then print("List is full") return endif temp = nextFree nextFree = items[nextFree].pointer items[temp].item = newItem if start == null or newItem < items[start].item then items[temp].pointer = start start = temp else p = start while items[p].pointer ≠ null and newItem ≥ items[items[p].pointer].item p = items[p].pointer endwhile items[temp].pointer = items[p].pointer items[p].pointer = temp endif endprocedure
44
Whats the pseudo code to delete item in a linked list? LONNNGG WRITE IT
procedure deleteItem(target) if start == null then print("List is empty") return endif if items[start].item == target then temp = start start = items[start].pointer else p = start while items[p].pointer ≠ null and items[items[p].pointer].item ≠ target p = items[p].pointer endwhile if items[p].pointer == null then print("Item not found") return endif temp = items[p].pointer items[p].pointer = items[temp].pointer endif # Free up space items[temp].pointer = nextFree nextFree = temp endprocedure
45
What is a queue?
A first in first out data structure Items are added to end of queue and removed from the front Can be static or dynamic
46
What are the queue operations to remove and add to a queue?
To add an element to back of queue its - enQueue(item) To remove an element from front of queue its - deQueue
47
What is a linear queue?
Data structure that consists of an array Items are added to next available space in queue starting from front Items are then removed from front of queue
48
What is a circular queue?
A static array that has a fixed capacity so you will eventually reach end of queue
49
What happens when items are deQueued in a circular queue?
Space is freed up at the start of the array it would take time to move items up to the start of the array to free up space at the end so a circular queue is implamented it reuses empty slots at the front of the array Rear pointer wraps around to point to start of array
50
What is the pseudocode for initialising a queue?
procedure initialise front=0 rear=-1 size=0 maxSize=(size of array) end procedure
51
What is the pseudocode for checking if queue is empty?
function isEmpty() if size==0 then return true else return false endif endfunction
52
What is the pseudocode for checking if queue is full?
function isFull if size==maxSize then return true else return false endif endfunction
53
What is the pseudocode for adding an element to a queue?
procedure enqueue(newitem) if isFull then print("Queue Full") else rear=(rear+1) MOD (maxSize) queue(rear) = newitem size=size+1 endif endprocedure
54
What is the pseudocode for removing an element to a queue?
function dequeue if isEmpty then print("Queue empty") else item=queue(front) front=(front+1) MOD (maxSize) size=size-1 endif return item end function
55
What is a graph?
Set of nodes that are connected by pointers
56
What are the different types of graphs?
Directed-Pointers can only be traversed in one direction Undirected-Pointers can be traversed in both directions Weighted-A value is attached to each pointer
57
What is the data like in an adjacency matrix?
Its symmetric
58
How does an adjacency matric work to determine presence or absence of an edge
By inspecting the row that represents a node You need a method to record which row is used for a specific nodes edge data The data values of the nodes are not stored in the matrix
59
How does an adjacency matric store data for undirected un weighted graphs?
1 for a pointer between two nodes 0 for no pointer between two nodes
60
What is a problem with adjacency matrixes?
The larger the graph the more memory that will be wasted Using static 2D array its harder to delete or add nodes
61
What is breadth first search?
Graphical traversal algorithm which visits all neighbors of a node before moving onto its neighbors
62
What is depth first search?
Graph traversal algorithm that uses a pointer based system
63
What is a tree and its structure?
A connected undirected form of graph with nodes and pointers A root node at the top with nodes connecting to it called children nodes Leaf node at the bottom with no children
64
What are trees used for?
Managing folders Storing routing tables Speed up searching Represent algebraic and Boolean expressions
65
What is depth first traversal of a binary tree?
Goes left then right nodes
66
What is breadth first traversal of a binary tree
Begin with root node and move to left node under root and go left to right down the tree
67
What is the pseudo code for in order traversal
procedure inorderTraverse (P) if tree[p].left !=-1 then inorderTraverse (treelp].left) endif print (tree(p) .data) if tree(p). right != -1 then inorderTraverse (tree(p] .right) endif endprocedure
68
What is the pseudo code for post order traversal?
procedure postorderTraverse (p) if treel[p].left 1=-1 then postorderTraverse (tree(p). left) endif if tree[p]. right!= -1 then postorderTraverse (tree(p]. right) endif print (tree [p) .data) endprocedure
69
What is the pseudo code for pre order traversal?
P r o c e d u r e p r e o r d e r T r a v e r s e (p) p r i n t ( t r e e [ p ] . d a t a ) i f t r e e l p l . l e f t ! = - 1 then p r e o r d e r T r a v e r s e ( t r e e [ p ] . l e f t ) e n d i f i f t r e e l p l . r i g h t ! = - 1 t h e n p r e o r d e r Tr a v e r s e ( t r e e [ p ] . r i g h t ) e n d i f e n d p r o c e d u r e
70
What is a hash table?
An associated array coupled with a hash function that takes in data and releases an output
71
What is a hash function used for?
To map the key to an index in the hash table Each piece of data is mapped to a unique value using the hash function
72
What is a collision in a hash table?
When two inputs have the same hash value
73
How is a collision in a hash table resolved?
Item is placed in the next available location this is called collision resolution
74
Why are hash tables used?
They provide fast access to data due to having a unique 1-1 relationship with the address at which they are stored Very fast efficient data searching
75
How do you work out hash value?
Convert characters to ASCII value Add them up Mod the total by how much the table can store