1.4.2 Data Structures Flashcards

1
Q

What are the main differences between arrays and
lists?

A
  • Lists can store data non-contiguously whereas arrays store data in order.
  • Lists can store data of more than one data type.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a linked list?

A

A dynamic data structure that is used to hold an ordered set of items that are not stored in contiguous locations.

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

What is a pre-order traversal?

A

Traversal algorithm in which you traverse the root node, followed by the left subtree then the right subtree.

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

What is in-order traversal?

A

Traversal algorithm in which you traverse the left subtree, the root node, then the right subtree.

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

What is post-order traversal?

A

Traversal algorithm in which you traverse the left subtree, the right subtree followed by the root node.

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

How to add data to a linked list?

A
  1. Check if the linked list is full
  2. Create a node and insert data into it
  3. Find between what 2 nodes the data should be inserted
  4. Make the previous node point to the current node
  5. Make the current node point to the next node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to delete data from a linked list?

A
  1. Check if the linked list is empty
  2. Find the node to delete
  3. Set the pointer of the previous node to point to the next node (node ahead of the node to be deleted)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to traverse a linked list?

A
  1. Check if the linked list is empty
  2. Start at the node the start pointer is pointing to
  3. Output the item
  4. Follow the pointer to the next item
  5. Repeat from 3 till end of list is reached
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to add data to a queue?

A
  1. Check if the queue is full
  2. Create a new node
  3. Insert it into the tail pointer position
  4. Increment the tail pointer`
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to remove data from a queue?

A
  1. Check if the queue is empty
  2. Output node pointed by the head pointer
  3. Increment the head pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to add data to a stack?

A
  1. Check if the stack is full
  2. Create a new node
  3. Insert it into the pointer position
  4. Increment the pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to remove data from a stack?

A
  1. Check if the stack is empty
  2. Output node in pointer position
  3. Decrement pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to add data to a binary tree?

A
  1. Check if there’s free memory for a new node
  2. Create a new node and insert data into it
  3. If tree is empty
    a. New node becomes the first item
  4. If tree is not empty
    a. Start at root node
    b. If the new node is before current node, follow left pointer
    c. If the new node is after current node, follow right pointer
    d. Repeat from step 4b until leaf node is reached
    e. If new node is placed before current node, set left pointer to be the new node
    f. If new node is placed before current node, set right pointer to be the new node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly