Data Structures Flashcards

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

What is a data structure?

A

A conceptual way of arranging data

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

What is the difference between a static and dynamic data structure?

A

Static:
- Stored contiguously in memory as a series of sequential memory locations
- Size is fixed in compilation

Dynamic:
- Change in size during run time
- Store pointers as well as data to point between to next memory location
- Data dynamically allocated from the heap

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

What is overflow in static data structures?

A

Attempting to store more data than is available with set memory locations.

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

What data structures are static and which are dynamic?

A

Static:
- Arrays
- Some stacks
- Some queues
- Graphs which use adjacency matrix

Dynamic:
- Some stacks
- Some queues
- Graphs which use an adjacency list
- Lists

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

What is an array?

A

A finite, indexed set of related elements of the same data type.

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

What is a stack?

A

An abstract data structure which operates on a FILO (first-in-last-out) basis

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

What components are there in a stack?

A

Stack array / list - stores the items in the stack
Stack pointer - indicates the top of the stack

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

What are the key operations we can perform on a stack?

A

1) Push (add item to top of stack)
2) Pop (remove item from top of stack)
3) Peek (return the value at the top of the stack)
4) Checking if a stack is empty
5) Checking if a stack is full

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

How can you check if a stack is empty?

A

You can check if the index of the stack pointer is at -1 (initial value).
~~~
private bool IsEmpty() {
return stackPointer == -1;
}
~~~

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

How to check if a stack is full?

A

Check if the index of the stack pointer is at the max size of the stack - 1;
~~~
private bool IsFull() {
return stackPointer == stack.Length - 1;
}
~~~

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

How to push an item onto the stack?

A

1) Check if the array storing the stack is full. If it is, raise an error / exception.
2) If not full, increment the stack pointer by 1.
3) Store the item at the new memory that the stack pointer points to.
~~~
public int[] Push(int x) {
if (!IsFull()) {
stackPointer++;
stack[stackPointer] = x;
return stack;
} else {
System.Console.WriteLine(“The Stack is full.”);
return stack;
}
}
~~~

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

How to pop an item off the stack?

A

1) Check if the array storing stack is empty. If empty, raise an error or throw an exception
2) If not, decrement the stack pointer by 1.
3) Return the value of the item at index stack pointer + 1.
~~~
public void Pop() {
if (!IsEmpty()) {
stackPointer–;
System.Console.WriteLine(stack[stackPointer + 1] + “ has been popped from the stack.”);
} else {
System.Console.WriteLine(“The list is empty! Cannot pop!”);
}
}
~~~

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

How to peek an item in a stack?

A

1) Check if array storing stack is empty. If it is, raise an error
2) Return value of item at index of stack pointer.
~~~
public int? Peek() {
if (!IsEmpty()) {
System.Console.WriteLine(“Your number is “ + stack[stackPointer]);
return stack[stackPointer];
} else {
System.Console.WriteLine(“Stack is empty! Nothing to peek!”);
return null;
}
}
~~~

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

What is a multi-dimensional array?

A

an n-dimensional array is a set of elements of the same data type with each element being of type array with n-1 dimension

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

What is an abstract data stucture?

A

An unimplemented data structure which makes use of other data structures to form a new way of storing data. (e.g. stacks using arrays)

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

Key differences between static and dynamic data structures

A
17
Q

What is a queue?

A

An abstract data structure that operates on a FIFO (first-in-first-out) basis.

18
Q

What are the types of queues?

A

1) Linear Queues
2) Circular Queues
3) Priority Queues

19
Q

What are the elements of a linear queue?

A
  • Array or list for the items
  • Front and rear pointer (for start and end of the queue)
20
Q

What are the key operations of a linear queue?

A

1) Check if the array for the queue is empty
2) Check if the array for the queue is full
3) Enqueue (add) an item to the end of the queue
4) Dequeue (remove) an item from the start of the queue

21
Q

How do you check if a LINEAR queue’s array is empty?

A

Check if the value of rear pointer is less than the value of the front pointer
~~~
public bool IsEmpty() {
if (rearPointer < frontPointer) {
return true;
else {
return false;
}
}
~~~

22
Q

How to check if a queue is full?

A

Check if the index of the rear pointer is at the max size - 1.
~~~
public bool IsFull() {
if (rearPointer == maxSize - 1) {
return true;
else {
return false;
}
}
~~~

23
Q

What are the advantages and disadvantages of linear queues?

A

Advantages:
- Simple to program

Disadvantages:
- Can lead to wasted capacity due as memory is stored statically (static)
- Process of shuffling is inefficient

24
Q

What is a circular queue?

A

A type of queue that allows the front and rear pointer over the ends of the queue. This makes it a more efficient structure.

25
Q

What mathematical operation do we use in implementation of a circular queue for indexing?

A

Modulo function e.g. with enqueue
~~~
public void Enqueue(T toAdd) {
if (!isFull()) {
rearPointer = (rearPointer ++) % maxSize;
items[rearPointer] = toAdd;
queueSize++;
} else {
System.Console.WriteLine(“The queue is full!”);
}
}
~~~

26
Q

What is a priority queue?

A

A queue that has each item assigned with a priority with items with the highest priority being dequeued before low priority happen.

Within a given priority, items are dequeued in a first-in-first-out basis.

27
Q

What are the uses for queues and stacks?

A