1.4.2 - data structures Flashcards

7 (36 cards)

1
Q

one dimensional array

A

A finite, ordered set of elements of the same type stored in contiguous memory.

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

Does row or column come first in 2D array?

A

row

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

tuple

A

An immutable, ordered set of values of any data type.

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

immutable

A

Its elements cannot be changed and you cannot dynamically add or delete elements from a tuple.

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

record

A

Contains a number of fields, each holding one item of data.

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

list

A

A contiguously stored data structure consisting of a number of ​ordered ​items where the items can occur more than once​.

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

list.isEmpty()

A

Test for an empty list.

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

list.append(item)

A

Adds item to the end of a list.

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

remove(item)

A

Removes the first occurrence of an item from a list.

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

search(item)

A

Return whether an item exits in a list or not.

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

list.length()

A

Returns number of items in a list.

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

list.index(item)

A

Returns the position of item.

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

list.insert(position, item)

A

Insert a new item at position.

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

list.pop()

A

Remove and return the last item in the list.

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

list.pop(position)

A

Remove and return the item at position.

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

linked list

A

A dynamic data structure used to hold an ordered sequence not necessarily in contiguous data locations.

17
Q

What is each item in a linked list called?

18
Q

2 parts of a node and their explanation

A
  • data field: actual item
  • pointer field: contains address of next item in sequence.
19
Q

null pointer in a linked list

A

Used to identify the last item of data.

20
Q

List 4 operations that can be carried out on queues.

A

1- enQueue()
2- deQueue()
3- isEmpty()
4- isFull()

21
Q

3 uses of queues

A
  • storing print jobs until the printer is ready to print
  • CPU scheduling
  • breadth first traversal of a graph
22
Q

linear queues

A

When an item of data is removed from the front, all the other items move up one place. This is only suitable in a small queue, otherwise data processing time can be excessive.

23
Q

circular queues

A

When an item of data is removed from the front, the two pointers have to be updated to identify the new front and rear of the queue.

24
Q

2 uses of graphs

A
  • locations on a map
  • products on an e-commerce website
25
2 uses of hash tables
- customer records - password verification
26
hash table
A data structure that is used for very large collections of data or where quick access to data is required.
27
2 approaches to dealing with collisions in a hash table
1- A rehashing algorithm is used to determine the next empty slot in which to store the data. 2- We can create a separate data structure such as a linked list from each storage location and store the collisions there.
28
2 uses of stacks
1- To reverse the order of a set of data. 2- Used by processors to handle interrupts.
29
Why is a hash table better suited to storing records than a linked list?
- A hash table enables direct access to the location of the record. - A hash table will take the same time to search through regardless of the number of records.
30
describe a depth first traversal
- goes to left child if possible - else goes to right child - if no child, node is marked as visited and backtracks to parent node - uses a stack
31
describe a breadth-first traversal
- Visits all nodes connected directly to the start node. - The visits all the nodes directly connected to each of those and so on. - Uses a queue.
32
Explain backtracking in depth-first traversals.
- when a node has no children - the algorithm goes back to the previous visited node - to check if that has further children nodes to visit
33
Describe the purpose of a free list pointer. (2)
* Points to where the next/first free node is * To add data into the linked listed.
34
4 ways that a graph is different from a tree
* Trees have one root node // graphs do not have a root node (1) * Trees do not allow cycles/loops // graphs do allow cycles / loops (1) * Trees store hierarchy // graphs have no hierarchy (1) * Trees are always undirected // graphs can be directed (1) * Trees are always connected // graphs can be connected or disconnected (1)
35
explain why a record data structure is suitable
* Can store multiple items of data under one identifier // so all the data about a task can be accessed using the same identifier * Can store data of different data types and this task has string, real and integers
36
advantages of storing in a binary tree instead of a 1-dimensional array
* Searching is faster ( O(log n) ) * Inserting new tasks is faster * Do not need to sort the structure (each time a new task is inserted)