Algorithms for the Main Data Structures Flashcards

(42 cards)

1
Q

Examples of data structures.

A

-Stacks -Queues
-Linked Lists -Trees

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

What are the traversal types of trees?

A

Depth First (post-order)
Breadth first

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

What data structure is a stack an example of?

A

First in, Last out (FILO)

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

What is the single pointer that keeps track of the top of the stack called?

A

Top pointer

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

What are top pointers initialized at?

A

-1

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

What is the 1st position in the stack

A

0

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

PsuedoCode to check size of stack

A

size()

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

PsuedoCode to check if the stack is empty?

A

isEmpty()

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

PsuedoCode to return the top element in the stack (but not remove it)

A

peek()

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

PsuedoCode to add to stack

A

push(element)

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

PsuedoCode to remove the top element from the stack and return the removed element

A

pop()

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

Example of PsuedoCode size() in a stack

A

size()
return top +1

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

Example of PsuedoCode isEmpty() in a stack

A

isEmpty()
If top < 0:
return True
else:
return False
endif

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

Example of PsuedoCode peek() in a stack

A

peek()
if isEmpty():
return error
else:
return A[top]
endif

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

Example of PsuedoCode push(element) in a stack

A

push(element)
top += 1
A[top] = element

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

Example of PsuedoCode pop() in a stack

A

pop()
if isEmpty():
return error
else:
toRemove = A[top]
A[top] = “”
top -= 1
return toReturn
endif

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

What type of data structure are queues

A

First in, First out (FIFO)

18
Q

What are stacks and queues represented as?

19
Q

What are the pointers called in a queue?

A

Front and back pointer

20
Q

What does the front pointer hold?

A

The position of the first element

21
Q

What does the back pointer store?

A

The next available space

22
Q

PsuedoCode to check size of a queue

23
Q

PsuedoCode to check if a queue is empty

24
Q

PsuedoCode to check the front element of a queue (but not remove)

25
PsuedoCode to add to the queue
enqueue(element)
26
PsuedoCode to remove front element from the queue and return removed elements
dequeue()
27
Example of PsuedoCode size() in a queue
size() return back - front
28
Example of PsuedoCode isEmpty() in a queue
isEmpty() if front == back : return True else : return False endif
29
Example of PsuedoCode peek() in a queue
peek() return A[front]
30
Example of PsuedoCode enqueue(element) in a queue
enqueue(element) A[back] = element back += 1
31
Example of PsuedoCode dequeue() in a queue
dequeue() if isEmpty() : return error else : toDequeue = A[Front] A[front] = "" front += 1 return toDequeue
32
What are linked lists composed of?
Nodes
33
What does each node have in a linked list?
A pointer node to the next item in the list
34
What is the first and last item in a linked list referred to as?
Head and tail
35
Searching a linked list is performed with what type of search?
Linear
36
How does a linear search, search
It checks each item in a lost one by one from the start until the target value is found or the end of the list is found
37
What are trees formed from
Nodes and edges
38
State 2 facts about trees
- Trees do not have cycles - Trees are not directed
39
Why are trees a useful data structure?
Because they can be traversed
40
What are the 2 traversal types in a tree?
- Depth First (post order) - Breadth first
41
Explain depth first, and what abstract data structure is used to store the data in order.
Search goes as far down into the tree as possible, before backtracking. A stack.
42
Explain breadth first, and what abstract data structure is used to store the data in order.
Starting from the left and visiting everything on the same row then back to the right and down