Posts

DS & A (DATA STRUCUTRES)

Image
| Data Structures - CHAPTER 1 |What is Data Structures?
Data Structures are any data representations and it's associated operations. It is also defined as the implementation of ADT(Abstract Data Type, We will learn about Abstract Data Type later).
E.g. Integer: Summation        String: Replace
Note: There are different types of data Structures and no particular data structure is better than the other in all cases, it all comes down to a number of factors depending on which a certain type of Data Structure is suitable for a certain problem. Resource Constraints such as Time consumption and space(memory) availability are the two major factors that determine the efficiency of a certain data structure. Selecting Efficient Data Structure for a problem Carefully analyze the problem and figure out the resource constraints. Determine the basic operations and quantify the resource constraints for each operation. Select the data structure that best meets the requirements.  Note: In the second p…
ScaleFree

DS & A(Queue)

Image
In this chapter, our topic of discussion will be the "Queue" Data Structure. But, before we get started, I would recommend you to read the previous chapters on Data Structures & Algorithms (especially the chapters on Array List, Linked List, Array Stack, and Linked Stack), that is in case it's your first time visiting my blog. Queue: Just like Stacks, Queues also are a restricted version of List but with a few minor differences compared to Stack. The following are some of the notable characteristics of a Queue:Data can only be inserted from the rear/back. Data insertion is referred to as ENQUEUE.Data can only be deleted from the front. Data deletion is referred to as DEQUEUE.Alternatively, ENQUEUE and DEQUEUE should always be executed on the opposite ends of the Queue.A Queue follows the FIFO(First In First Out)principle.The first and the last elements are referred to as FRONT and REAR respectively.

Visual Representation: Array-Based Queue: Pointer-Based(Linked) Queue: So…

DS & A(Stacks - Pointer Based)

Image
In the previous chapter, we talked about Array Based Stacks so continuing our discussion on Stacks, In this chapter, we will see how to implement pointer-based Stacks also known as Linked Stacks.

Visual Representation:


Properties of Linked Stack:

Follows LIFO principle and all the other general properties of a stack.Unlike Array-based stack it's size is not fixed. Its size grows with the addition of new elements.A Linked Stack can have head and tail pointers but it is not mandatory. Stack ADT:

template<typename e> class Stack{public:    //Function to insert a value at the pop of the Stack    virtual bool push(const e& item) = 0;
    //Function to remove top-most Stack value    virtual bool pop(e& item) = 0;
    //Function to Display the stack    virtual void print() const= 0;};
Stack Implementation: Creating the Node: public:template<typename e>class Node{public:    e element;    Link<e>* next;
    Link(e elemValue = 0, Link<e>* nextValue = nullptr)    {      …

Share on Social Media