data structures 2 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q
  • How do you test for an empty circular queue?
  • How do you test for a full circular queue
A
  • Check if the front and rear pointers are equal (front == rear)
  • Check if the tail pointer is 1 less than the front pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you add an item to a priority queue?

A
  • Ensure the queue is not full.
  • Place the item according to its priority. Higher priority items are placed before lower priority items.
  • Shift existing elements to accommodate the new item while maintaining the order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you remove an item from a priority queue?

A
  • Ensure the queue is not empty.
  • Take the item with the highest priority (usually the first item).
  • Shift remaining elements to fill the gap left by the removed item.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you test for an empty priority queue?

A

Check if the size of the queue is 0 or if the front pointer is equal to the rear pointer.

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

How do you test for a full priority queue?

A

Check if the rear pointer is at the last index of the array (size - 1)

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

uses of graphs

A
  • navigation systems
  • data transmissions
  • web page links
  • social media trends
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

differences between tree and graph

A
  • graphs have cycles, trees dont
  • theres one path between each node in a tree, there are multiple with a graph
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what are edges/arcs

A

the paths that link nodes together

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

a graph with more edges than vertices is called

a graph with less edges than vertices is called

A

a dense graph

a sparse graph

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

directed vs undirected graphs

A

where the edges go in one direction

undirected - all the edges are biderectional (arrowheads on both heads)

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

how to represent:
- vertices
- edges
- edges with weights

A

vertices - inside curly brackets, eg {A,B,C,D,E,F}
edges - {(A,B),(A,C), (B,E), (C,A)}
edges with weights -
{ (A,B,8), (A,C,2), (B,E,4) }

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

adjacency matrix

A
  • A square 2D matrix used to represent a graph
  • Each row and column represent a node (or vertex).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

adjacency list

A
  • A list of dictionary where each node (or vertex) has a list of its adjacent nodes (or neighbors).
  • implemented as a list of dictionaries
  • key in each dictionary being the node and edge weight
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

advantages and disadvantages of adjacency matrixes

A
  • easy and quick to work with
  • adding new edges/ checking for the presence of edges is quicker using this structure

however:
- if theres many nodes and few edges, it may result in empty space (wasted memory) and problem gets worse as size of the graph increases
- if matrix is implemented as a static 2D array, it can be hard to add or delete nodes

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

advantages of adjacency lists

A
  • more space efficient
  • use less memory to store a sparse graph
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is a tree

A

a connected, undirected graph with no cycles

17
Q

what is a root node

A

the node at the top of the tree

18
Q

what are the children of a tree

A

the node next down the structure

19
Q

what are branches

A

the lines that join nodes together

20
Q

what are leaf nodes

A

nodes without any sub nodes/children

21
Q

describe the operations of a binary tree

A
  • Create a root node
  • The root node has a right and left pointer
  • If the value is smaller than the current node, insert it to the left.
  • If the value is greater, insert it to the right.
  • Repeat Recursively: For each node, follow the same rule until all values are inserted.
  • Nodes with no children have both left and right pointers set to null.
22
Q

explain the circumstances in which it is more appropriate to represent a graph using an adjacency list instead of an adjacency matrix

A
  • when there are few edges between vertices
  • when graph is sparse
  • when edges rarely change
  • when presence of specific edges does not need to be tested frequently
23
Q

what is a weighted graph

A

a graph where each edge has a value associated with it