ADT Flashcards

Abstract data types: Based on Google Classroom PowerPoints and Joshua's Past Papers

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

what is an ADT?

A

An abstract data type is a logical description of how data
is viewed and the operations that can be performed on it,
but how this is done is not necessarily known to the user.

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

Describe the stack data structure

A

A stack is a Last In, First Out (LIFO) data structure. This
means that with a stack the last item in is the first item to
leave the stack.

Stack data structure is used in calculations and to hold
return addresses. Using the BACK and UNDO buttons
on web browser or word processing package are actions
done using stacks ADT.

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

List and describe some operations done on a stack

A

push(item) – adds a new item to the top of the stack

pop() – removes and returns the top item from the stack

peek() – returns the top item from the stack but does not
remove it

isEmpty() – tests to see whether the stack is empty, and
returns a Boolean value

isFull() – tests to see whether the stack is full, and returns
a Boolean value

size() - Return the number of elements in the stack

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

Detail the steps to remove a node from a singly liked list

A
  1. Identify the Node to Remove.

The first step is to locate the specific node you want to remove from the linked list. This typically involves
traversing the list using a temporary pointer. You should have some criteria for identifying the node to be
removed, such as a matching value.

  1. Update the Previous Node’s “next” Pointer.

Once the node to be removed is found, you need to update the “next” pointer of the previous node (the node
before the one you’re removing). This step is critical because it effectively bypasses the node you’re removing.

  1. Free the Node to Remove
    Now that you’ve updated the “next” pointer of the previous node, the node to be removed is effectively
    disconnected from the list. At this point, it’s safe to free the memory allocated for this node to avoid memory
    leaks.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Detail the steps to add a node in singly linked list

A

To add a new node at the front of the singly linked list, follow these steps:
 Create a new node with the desired data.
 Make the new node point to the current head of the list.
 Update the head to point to the new node.

To add a new node to the end of the singly linked list, follow these steps:
 Create a new node with the desired data.
 Traverse the list to find the last node (the one with a NULL next pointer).
 Update the next pointer of the last node to point to the new node.

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

How to add a new node after another node

A

To add a new node after a specific node in the singly linked list, follow these steps:
 Create a new node with the desired data.

 Traverse the list to find the node after which you want to insert.
 Update the next pointer of the new node to point to the node after which you want to insert.
 Update the next pointer of the previous node to point to the new node.

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

Provide a detailed description of a linked list

A

A linked list is a linear data structure that stores data in various memory locations known as nodes. A linked list contains a head pointer that points to the first node of the linked list. Each node contains data and a pointer to the next node and the last node in the sequence points to null

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

State the Two conditions that must exist for the successful execution of the INSERT and DELETE operations as they relate to stacks and queues

A
  1. The stack or queue cant be empty if you want to remove data
  2. The stack or queue cant be full if you want to add data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly