Data Structures Flashcards

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

What is a data structure?

A

A group/collection of related data elements

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

What is an array?

A
  • Data structure where there is a predetermined number of elements of the same type.
  • Elements are accessed via indexes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a record?

A

Set of data items which are all related to a single entity and can contain data of different types

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

What is a stack?

A

‘First In, Last out’ data structure where data elements can only be added and removed at the top

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

What examples can stacks be used for?

A
  • Store subprogram addresses
  • Store recursion values
  • Store short-term arithmetical results
  • Undo Function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does a ‘Push’ and a ‘Pop’ include in a stack data structure?

A
  • Push adds items to the top of a stack and pop removes the item from the top.
  • Underflow may occur if you attempt to pop an empty stack and overflow occurs if you attempt to push to a full stack.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why are stacks and queues commonly used for most situations?

A

The natural processing order is first in last out or first in first out depending on the situation.

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

How would a stack be implemented?

A

Would be stored in an array and a pointer would keep track of the top of the stack.

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

Pseudocode for pushing onto a stack:

A

If stackPointer < stackMaximum then:
stackPointer = stackPointer + 1
stackArray(stackPointer) = dataItem
Else:
Output “Stack is full - your data has not been saved”

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

Pseudocode for popping from a stack:

A

If stackPointer > 0 then:
dateItem = stackArray(stackpointer)
stackPointer = stackPointer - 1
Else:
Output “Stack is empty - no data can be retrieved”

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

What is a Queue?

A

‘First In, First Out’ data structure which could be used for printer queues and keyboard buffers

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

How would you implement a queue?

A

Data would be stored in an array and two pointers would keep track of the front and the back of the queue.

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

What is a linked list?

A

A set of data elements where each element contains the data itself and a pointer to the next element.

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

What are the benefits of using a linked list?

A

Items can be added without rearranging the entire order and can use memory more efficiently if programmed dynamically.

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

What are the drawbacks of using linked lists?

A

More difficult to program and manipulate than an array, extra programming is needed to send the data in the opposite direction and it can only be accessed in a linear manner.

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

What is a binary tree?

A

Data structure made up of nodes and branches, root node at the top of the tree and the data is added in the order it occurs in.

17
Q

Name an advantage and disadvantage of using a binary tree rather than an array.

A

It is faster to search and add a value however it is more complex to program and process.

18
Q

What happens if a binary tree is not well balanced?

A

searching and processing times will be significantly increased

19
Q

What are the three methods of traversing a binary tree?

A

Preorder (root, left, right)
Inorder (left, root, right)
Postorder (left, right root)

20
Q

What is a hash table?

A

Two components including a table where the actual data is stored and a mapping function (hash function)

21
Q

What is the point of a hash function?

A

Uses the data that will be entered in the table to generate a location as to where it should be stored.

22
Q

What is separate chaining?

A

The original table stores a link to a dynamic structure like a linked list which will add a new node in case of duplicate data locations.

23
Q

What is an advantage and disadvantage of separate chaining?

A

It avoids data collisions however it will slow down trying to find the data again as the linked list would have to be searched after the hashing algorithm is complete

24
Q

What other solution can be used instead of separate chaining?

A

Flagging the original block and moving the data into an overflow area for subsequent linear search