10.4 DataTypes&Structures.abstract_data_types Flashcards

1
Q

How is a stack implemented?

A

A stack can be implemented using an array and a set of pointers. The stack has a finite size, and conditions for full and empty states must be handled.

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

What remains constant during stack operations (push and pop)?

A

The value of the basePointer remains constant during stack operations.

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

What are the declarations to set up a stack in pseudocode?

A
DECLARE stack ARRAY[1:10] OF INTEGER  
DECLARE topPointer : INTEGER  
DECLARE basePointer : INTEGER  
DECLARE stackful : INTEGER  
basePointer ← 1  
topPointer ← 0  
stackful ← 10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the pseudocode to push an item onto a stack?

A
IF topPointer < stackful  
    THEN  
        topPointer ← topPointer + 1  
        stack[topPointer] ← item  
    ELSE  
        OUTPUT "Stack is full, cannot push"  
ENDIF  
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the pseudocode to pop an item from a stack?

A
IF topPointer = basePointer - 1  
    THEN  
        OUTPUT "Stack is empty, cannot pop"  
    ELSE  
        item ← stack[topPointer]  
        topPointer ← topPointer - 1  
ENDIF 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What changes after enqueue and dequeue in a queue?

A
  • rearPointer changes after enqueue.
  • frontPointer changes after dequeue.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is a queue implemented and managed?

A

A queue can be implemented using an array with pointers for front and rear. It is managed as a circular queue to prevent repositioning items when the queue reaches the array’s bounds.

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

What are the declarations to set up a queue in pseudocode?

A
DECLARE queue ARRAY[1:10] OF INTEGER  
DECLARE rearPointer : INTEGER  
DECLARE frontPointer : INTEGER  
DECLARE queueful : INTEGER  
DECLARE queueLength : INTEGER  
frontPointer ← 1  
rearPointer ← 0  
upperBound ← 10  
queueful ← 10  
queueLength ← 0  
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the pseudocode to enqueue an item into a queue?

A
IF queueLength < queueful  
    THEN  
        IF rearPointer < upperBound  
            THEN  
                rearPointer ← rearPointer + 1  
            ELSE  
                rearPointer ← 1  
        ENDIF  
        queueLength ← queueLength + 1  
        queue[rearPointer] ← item  
    ELSE  
        OUTPUT "Queue is full, cannot enqueue"  
ENDIF 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the pseudocode to dequeue an item from a queue?

A
IF queueLength = 0  
    THEN  
        OUTPUT "Queue is empty, cannot dequeue"  
    ELSE  
        item ← queue[frontPointer]  
        IF frontPointer = upperBound  
            THEN  
                frontPointer ← 1  
            ELSE  
                frontPointer ← frontPointer + 1  
        ENDIF  
        queueLength ← queueLength - 1  
ENDIF
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can a linked list be implemented in programming?

A

A linked list can be implemented using two 1D arrays:

  1. One for storing items in the linked list.
  2. One for storing pointers to the next item in the list.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What must be managed when implementing a linked list in arrays?

A
  • The possibility of the linked list becoming full.
  • Empty positions in the array, represented as an empty linked list (the heap).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of the heap in a linked list?

A

The heap is a linked list of all available spaces in the array, used to manage empty positions after items are removed.

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

What is the pseudocode to declare and initialise a linked list?

A
DECLARE myLinkedList ARRAY[0:11] OF INTEGER  
DECLARE myLinkedListPointers ARRAY[0:11] OF INTEGER  
DECLARE startPointer : INTEGER  
DECLARE heapStartPointer : INTEGER  
DECLARE index : INTEGER  

heapStartPointer ← 0  
startPointer ← –1 // List is empty  

FOR index ← 0 TO 11  
    myLinkedListPointers[index] ← index + 1  
NEXT index  

myLinkedListPointers[11] ← –1 // Final heap pointer set to –1  

Identifier table:
myLinkedList: Linked list to be searched.
myLinkedListPointers: Pointers for the linked list.
startPointer: Start of the linked list.
heapStartPointer: Start of the heap.
index: Pointer to the current element in the linked list.

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

What does the final pointer in the heap signify when initialising a linked list?

A

It is set to –1 to indicate there are no further links in the heap.

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