data structures Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

stack

A

data can be added or removed from one location - the TOP of the stack

LIFO (last in first out) structure

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

stack operations

A

push() - add an item to the top of the stack
pop() - take an item from the top\

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

limitations on stack operations

A

cant push if stack full
cant pop if stack empty

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

how push() stack operation is carried out

A

push - add an item at the top pointer and then move the top pointer up by one

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

how pop() stack operation is carried out

A

pop - return the value at the top pointer then move the top pointer down by one

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

evaluate the stack

A

traverse or insert is not possible

big-O value of all stack operations is one

no wasted space

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

when stack is used

A
  • undo button
  • recursive function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

queue

A

data can be added at the end/ tail of the queue

can be removed at the front/ head of the queue

FIFO ( first in first out) structure

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

queue operations

A

Enqueue - add item to end of queue
Dequeue - take an item from front of queue

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

how enqueue() queue operation is carried out

A

add an item at the end marker
move it forward by one

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

how dequeue() queue operation is carried out

A

return value at front marker and move it forward by one

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

limitations of queue operations

A
  • queue moves along in available space as changes are made
  • to avoid running out of space it can be made circular. if the end of the queue catches up w the front, no more items can be added
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

evaluate queue

A

traverse insert not possible

big- O value of all queue operations is 1

no wasted space

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

when queue is used

A

print queue

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

linked list

A

made of nodes
each node contains an item of data and a pointer to the next node

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

how to traverse a linked list

A

start at header
follow pointers until reach node with no pointers

17
Q

how to insert items to a linked list

A

add the item in an empty space
change pointers to include item in the list

18
Q

how to delete items from a linked list

A

change pointers so that the list skips over the deleted item

19
Q

What does the free space pointer do

A

computer remembers the location of an empty storage space
this is where new nodes can be added

after adding a new node the free space pointer is updated

20
Q

evaluate linked list

A
  • wide range of operations possible. traverse, search , insert, sort, delete etc.
  • most operations have O(n) - linear complexity, making the linked list slower than a stack or queue
21
Q

when to use a linked list

A

list data type in python

22
Q

tree data structure

A

made of nodes
each node holds one data value and more than one pointer

23
Q

parts of a tree data structure

A

root - start value
branches - nodes to left and right of root
leaf node- a node with no branches

24
Q

binary tree

A

made of nodes with two pointers

25
Q

binary search tree

A

a type of binary tree where data is added in a predictable way so it can be found easily

26
Q

How is data added to a binary search tree

A

Compare the value to the root value

If it is less go to the left branch

If it is larger go to the right branch

Continue to travel left or right until you find an empty location to add the value

27
Q

How can you find data in a binary search tree

A

Compare the value you are looking for to the root value

If it is less go to the left branch

If it is larger go to the right branch

Continue to travel left or right until you find the value.

If you find an empty location the value is not in the tree.

28
Q

What are the two ways of traversing a tree

A

Breadth-first traversal

Depth-first traversal

29
Q

Breadth-first traversal of a tree

A

Start at the root, output the value

Visit the branches, left then right, output each value in turn

Visit each level in turn, going from left to right across the tree

30
Q

Depth-first traversal of a tree

A

Start at the root but do not output any value until you have output the left and right nodes in that order

That means you will start at the bottom left of the tree

Visit each branch in order left then right then root

Work upwards until you return to the root node, which is the final value

31
Q

Describe the map data structure

A

A map is made of nodes with data and a variable number of pointers

The nodes are connected, but they do not make a regular pattern. There is no root node.

32
Q

Parts of a map

A

Each node may be called a vertex (plural vertices)

The connections may be called edges

33
Q

weighted map

A

a map with weight values added to the edges – these weights represent the distance (or effort or cost of moving) between nodes

34
Q

directed vs undirected graph

A

A directed graph has one-way connections, an undirected graph has two-way connections

35
Q

What is the purpose of Dijkstra’s algorithm

A

Dijkstra’s algorithm will find the shortest route between two nodes in a map – that is the route with the smallest total weight or distance

36
Q

What are the steps of Dijkstra’s algorithm

A

-start node is active node
i-dentify every node you can get to from active node
-enter the route and total distance into the table. If there’s a shorter route there do not replace it
- find the node which is the shortest distance from the start- becomes the active node
- repeat until route to end node is found

37
Q

How is A star different from Dijkstra

A

The A* algorithm is the same as Dijkstra but it uses a heuristic value

The heuristic value represents the distance from each node to the end point

38
Q

Evaluate the benefits and limitations of the A star algorithm

A

A* is an improvement on Dijkstra because it finds the same route as Dijkstra but with less working out

39
Q

How does the A* algorithm find the route

A

All the steps are the same as Dijkstra, except when the time comes to choose the next active node

Find the total value for each node by adding the route from the start node and the heuristic value

Choose the node with the lowest total value as the next active node