Section 7: Data structures Flashcards

1
Q

When searching for a value in a 2-D array table, would you start with columns or rows?

A

In a 2-D array table you start your search along the rows.

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

How does a tuple differ from an array?

A

Unlike an array, a tuple can have different data types. However, a tuple is immutable i.e. its elements can’t be changed.

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

What is a record?

A

A record is a way of storing data from a program permanently. It stores values in columns as a table.

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

What is an abstract data type?

A

An abstract data type is a data type that is created by the programmer rather than embedded in the language itself.

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

What are some examples of abstract data types?

A

Examples include queues, stacks, trees and graphs.

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

What is the basic dynamic of a queue?

A

The basic dynamic of a queue is First in First out.

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

Where can queues be used?

A

Examples of uses for queues:

  • Keyboard
  • Simulation e.g. simulating customers at a checkout
  • Outputs waiting to be printed (stored as a queue on the disk)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a dynamic data structure?

A

A dynamic data structure refers to a collection of data in the memory that has the ability to shrink or grow in size.

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

What is heap?

A

Heap is a portion of memory from which space is allocated or de-allocated.

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

What is a static data structure?

A

A static data structure refers to a data structure that is fixed in size, meaning it cannot increase or decrease its memory allocation while the program is running.

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

What is a linked list?

A

A linked list is a dynamic data structure used to hold ordered data that may not be held in contiguous memory locations.

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

What is a stack?

A

A stack is a Last in First out data structure.

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

What are the main areas that a stack will be used?

A

A major use of stacks is to store information about the active subroutines while a program is running. This includes holding return addresses, parameters and local variables.

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

Is a stack a dynamic or static data structure?

A

A stack can be implemented as EITHER a dynamic data structure or a static data structure, depending on the preference of the programmer and the context in which it is being implemented.

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

What does the “peek()” operation do when applied to a stack?

A

The “peek()” operation returns the item at the top of the stack, but does not remove it from the stack.

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

How does a hash table work?

A

In a hash table, a hashing algorithm is applied to the value that requires storage, which transforms the value into an address in which the value itself will be held.

17
Q

How is an item searched for in a hash table?

A

Hash table search:

  • Hashing algorithm is applied to the inputted value
  • Examines the resulting memory address
  • If the item is there, return the item. If the address is empty, the item is not there. If there is another value there, check the neighboring addresses.
18
Q

What is the “folding method” hashing algorithm?

A

The folding method divides the item into equal parts, and adds the parts to give the hash value. E.g. the phone number 01543677896 can be written as 01, 54, 36, 77, 89, 6 which add together to make 263.

19
Q

How can a string be hashed?

A

A string can be hashed by converting it to its ASCII value and then taking the modulus depending on how many spaces you have in your hash table.

20
Q

How can you minimise collisions in a hash table?

A

Firstly, you can take collision resolution into account when designing the hash table in a way in which only 70% of the table’s cells would be occupied when the table is full. You could also tailor the rehashing algorithm towards the particular data set that you’re using in order to make the best use of the space that you have in your hash table.

21
Q

Where might a hash table be used?

A

Uses for a hash table:

  • Storing phone numbers
  • Storing customer ID codes
  • Storing encrypted passwords
22
Q

What is a node in a tree?

A

A node is a part of the tree that contains data.

23
Q

What is a branch/edge in a tree?

A

A branch/edge in a tree is the part of the tree that connects two nodes.

24
Q

What is the root of a tree?

A

The root of a tree is the only node that has no incoming edges.

25
Q

What is a child in a tree?

A

A child in a tree is technically any node with an incoming edge, but is only referred to as a child in relation to its parent.

26
Q

What is a parent in a tree?

A

A parent in a tree is a node that has outgoing nodes.

27
Q

What is a subtree?

A

A substree is the set of nodes and edges comprised of a parent and all descendants of the parent (it may also be a leaf)

28
Q

What is a leaf node in a tree?

A

A leaf node is a node that has no children.

29
Q

What is a binary tree?

A

A binary tree is a rooted tree in which each node has a maximum of two children.

30
Q

How do you draw a pre-order traversal?

A

A pre-order traversal is drawn by drawing an outline of the tree, starting to the left of the root node. Each time you pass the left of a node, the data in that node would be outputted.

31
Q

How do you draw an in-order traversal?

A

An in-order traversal is drawn by drawing an outline of the tree, starting to the left of the root node. Each time you pass the bottom of a node, the data in that node would be outputted.

32
Q

How do you draw a post-order traversal?

A

A post-order traversal is drawn by drawing an outline of the tree, starting to the left of the root node. Each time you pass the right of a node, the data in that node would be outputted.

33
Q

In words, how is a post-order traversal implemented as an algorithm?

A

Post-order traversal algorithm:

  • Traverse the left subtree
  • Traverse the right subtree
  • Visit the root node
34
Q

In words, how is a pre-order traversal implemented as an algorithm?

A

Pre-order traversal algorithm:

  • Visit the root node
  • Traverse the left subtree
  • Traverse the right subtree