Docsity

Data Structures and Algorithms: Queues, Stacks, and Hash Tables, Study notes of Computer science

Toggle sidebar
bg1
TOPIC-1
Data Types:
Elementary: Integer, real, Boolean
Composite: string, array
Abstract: List, stack and queue.
Abstraction:
An abstract data type is a logical description of how we view the data and
possible operations.
We are creating an encapsulation around the data.
Encapsulation is a type of information hiding
Modelling a queue
Add item to the rear of the queue
Remove item from the front of the queue
Check if the queue is empty or full
Front points t the next item that is to be removed, rear points to the last item
that was added.
Empty and full queue:
We can’t add to a full queue or remove an item from an empty queue.
Therefore, when the queue is initialised, we need to specify the maximum
number that it can hold. Ex- maxSize.
We may also need a variable size to hold the number of items currently in the
queue.
Queus functions-
enQueue(item) – adds an item to the rear
deQueue – remove and return an item from the front
isEmpty – indicated if the queue is empty
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Data Structures and Algorithms: Queues, Stacks, and Hash Tables and more Study notes Computer science in PDF only on Docsity!

TOPIC-

Data Types:  Elementary: Integer, real, Boolean  Composite: string, array  Abstract: List, stack and queue. Abstraction:  An abstract data type is a logical description of how we view the data and possible operations.  We are creating an encapsulation around the data.  Encapsulation is a type of information hiding Modelling a queue  Add item to the rear of the queue  Remove item from the front of the queue  Check if the queue is empty or full  Front points t the next item that is to be removed, rear points to the last item that was added. Empty and full queue:  We can’t add to a full queue or remove an item from an empty queue.  Therefore, when the queue is initialised, we need to specify the maximum number that it can hold. Ex- maxSize.  We may also need a variable size to hold the number of items currently in the queue. Queus functions-  enQueue(item) – adds an item to the rear  deQueue – remove and return an item from the front  isEmpty – indicated if the queue is empty

 isFull -indicated if the queue is full Problems arise with the implementation of a queue as a fixed-size array. Circular queue – This queue overcomes the problem of reusing the spaces that have been freed by dequeuing from the front of the array. Priority Queue- some items are allowed to ‘jump’ the queue. This type of queue is used when the items arriving have some type of priority associated with them. Static Data Structure  Cannot grow, shrink or be freed during execution.  An array is a static data structure. Dynamic data structure  Allocated and deallocated memory from the head (an area of memory especially used for this purpose)  Excessive allocation if memory, without deallocation may cause overflow (exceeding maximum memory limit)  Python – list, Java – ArrayList TOPIC – 2 The idea behind the creation of abstract data types is creating complex data types that will help solve problems efficiently. A queue is an Abstract Data Type (ADT)  The data used in implementing a queue are hidden from the user. A list is an Abstract Data Type (ADT)  An ADT allows us to view the data and perform operations that are allowed without regard to how they will be implemented.

TOPIC -

STACKS- Last in First out. Modelling a stack  Add an item to the top  Remove an item from the top  Check is the stack is full  Check if the stack is empty PROGRAMMING OPERATIONS  Push(item) – adds item to the top of the stack  Pop() – removed and return the item on the top of the stack  isFull() – checks if the stack is full  isEmpty() – Checks if the stack is empty.  Peek() – return the top item without removing it  Size() – return the number of item in the stack.

Overflow – attempting to push onto a stack that is full Underflow – attempting to pop from a stack that is empty. THE CALL STACK  Call stack is a system of level data structure  It provides the mechanism for passing parameters and return addresses to subroutines.  In a high-level programming language, the use of a call stack is hidden from the programmer. Subroutine call-  The parameters are saved onto the stack  Local variables are saved into the stack  The address to which execution returns after the end of the subroutine is reached is saved onto the stack  Execution is transferred to the subroutine code Subroutine execution-  Stack space is allocated for local variables  The subroutine code executes  The return address is retrieved  The parameters are popped

 ASCII for a= Dealing with deletions  Items to be deleted maybe replaced with a dummy item or marker  When searching for an item which hashes to that spot, if it is not found, the search will continue until it is found, or a free space located.  If a new item is to be added, it will replace the deleted item. Dictionary  A dictionary is an abstract data type made up of associated pairs.  Each pair has a key and a value.  The value is accessed via the key  

TOPIC – 5

Adjacency matrix  Each row and column represent a node.  The item at (row, column) indicated a connection.  It only uses storage for the connections that exis so it is more efficient. 