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
Q

How do you traverse a linked list?

A

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

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

How do you add a node to a linked list?

A

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

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

What is a stack?

A

A last in first out data structure and is often implemented using an array so maximum size is known in advance

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

What does an isEmpty() stack operation do?

A

Checks if stack is empty by checking the value of the top pointer

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

What does a push(value) stack operation do?

A

Adds a new value to the end of the list
Need to check stack is not full before pushing

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

What does a peek() stack operation do?

A

Returns the top value of the stack
First checks stack is not empty by looking at value of the top pointer

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

What does an pop() stack operation do?

A

Removes and returns the top value of the stack
First checks stack is not empty by looking at value of top pointer

32
Q

What does a size() stack operation do?

A

Returns size of the stack

33
Q

What does an isFull() stack operation do?

A

Checks if the stack is full and returns the boolean value, this compares stack size to the top pointer

34
Q

What does a stack pointer do?

A

Points the the top of the stack, where next data will be pushed or popped

35
Q

What happens when data is pushed onto a stack?

A

Data is pushed to position of the pointer
Once pushed the pointer will increment by 1 to signify top of the stack

36
Q

What is stack overflow?

A

Since a stack is a static data structure an attempt to push item onto a full stack is stack overflow
Size cant change

37
Q

What happens when data is popped from a stack?

A

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
Q

What is stack underflow?

A

Since a stack is a static data structure an attempt to pop item onto an empty stack is stack underflow
Size cant change

39
Q

What is the pseudocode to check if a stack is empty?

A

function isEmpty
if top == -1 then
return True
else
return false
endif
endfunction

40
Q

What is the pseudocode to check if a stack is full?

A

function isFull
if top ==maxSize then
return True
else
return false
endif
endfunction

41
Q

What is the pseudocode to push an item onto a stack?

A

procedure push(item)
if isFull() then
print(“Stack is full”)
else
top = top+1
stack(top)=item
endif
endprocedure

42
Q

What is the pseudocode to pop an item out of a stack?

A

procedure push(item)
if isEmpty() then
print(“Stack is empty”)
else
top = top-1
return item
endif
endprocedure

43
Q

Whats the pseudo code to insert item into a linked list?
LONNNGG WRITE IT

A

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
Q

Whats the pseudo code to delete item in a linked list?
LONNNGG WRITE IT

A

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
Q

What is a queue?

A

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
Q

What are the queue operations to remove and add to a queue?

A

To add an element to back of queue its - enQueue(item)
To remove an element from front of queue its - deQueue

47
Q

What is a linear queue?

A

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
Q

What is a circular queue?

A

A static array that has a fixed capacity so you will eventually reach end of queue

49
Q

What happens when items are deQueued in a circular queue?

A

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
Q

What is the pseudocode for initialising a queue?

A

procedure initialise
front=0
rear=-1
size=0
maxSize=(size of array)
end procedure

51
Q

What is the pseudocode for checking if queue is empty?

A

function isEmpty()
if size==0 then
return true
else
return false
endif
endfunction

52
Q

What is the pseudocode for checking if queue is full?

A

function isFull
if size==maxSize then
return true
else
return false
endif
endfunction

53
Q

What is the pseudocode for adding an element to a queue?

A

procedure enqueue(newitem)
if isFull then
print(“Queue Full”)
else
rear=(rear+1) MOD (maxSize)
queue(rear) = newitem
size=size+1
endif
endprocedure

54
Q

What is the pseudocode for removing an element to a queue?

A

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
Q

What is a graph?

A

Set of nodes that are connected by pointers

56
Q

What are the different types of graphs?

A

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
Q

What is the data like in an adjacency matrix?

A

Its symmetric

58
Q

How does an adjacency matric work to determine presence or absence of an edge

A

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
Q

How does an adjacency matric store data for undirected un weighted graphs?

A

1 for a pointer between two nodes
0 for no pointer between to nodes

60
Q

What is a problem with adjacency matrixes?

A

The larger the graph the more memory that will be wasted
Using static 2D array its harder to delete or add nodes

61
Q

What is breadth first search?

A

Graphical traversal algorithm which visits all neighbors of a node before moving onto its neighbors

62
Q

What is depth first search?

A

Graph traversal algorithm that uses a pointer based system

63
Q

What is a tree and its structure?

A

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
Q

What are trees used for?

A

Managing folders
Storing routing tables
Speed up searching
Represent algebraic and Boolean expressions

65
Q

What is depth first traversal of a binary tree?

A

Goes left then right nodes

66
Q

What is breadth first traversal of a binary tree

A

Begin with root node and move to left node under root and go left to right down the tree

67
Q

What is the pseudo code for in order traversal

A

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
Q

What is the pseudo code for post order traversal?

A

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
Q

What is the pseudo code for pre order traversal?

A

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
Q

What is a hash table?

A

An associated array coupled with a hash function that takes in data and releases an output

71
Q

What is a hash function used for?

A

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
Q

What is a collision in a hash table?

A

When two inputs have the same hash value

73
Q

How is a collision in a hash table resolved?

A

Item is placed in the next available location this is called collision resolution

74
Q

Why are hash tables used?

A

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
Q

How do you work out hash value?

A

Convert characters to ASCII value
Add them up
Mod the total by how much the table can store