Posts

Showing posts from December, 2022

Difference between Array and Linked list

Image
  Difference between Array and Linked List ================================================================================= Array : Arrays store elements in contiguous memory locations, resulting in easily calculable addresses for the elements stored and this allows faster access to an element at a specific index. Linked List : Linked lists are less rigid in their storage structure and elements are usually not stored in contiguous locations, hence they need to be stored with additional tags giving a reference to the next element.  This difference in the data storage scheme decides which data structure would be more suitable for a given situation. ARRAY LINKED LIST Array cannot grow or shrink dynamically. (realloc() is not efficient) Linked List can grow or shrink dynamically. Array has contiguous memory. Hence random access is possible. Notes are not in contiguous memory. Hence only sequential access is allowed.

QUEUE

Image
QUEUE ================================================================================ A  Queue  is defined as a linear data structure that is open at both ends.   The operations are performed in First In First Out (FIFO) order. A Queue is like a line waiting to purchase tickets, where the first person in line is the first person served. (i.e. First come first serve). Position of the entry in a queue ready to be served, that is, the first entry that will be removed from the queue, is called the  front  of the queue(sometimes,  head  of the queue) Similarly, the position of the last entry in the queue, that is, the one most recently added, is called the  rear  (or the  tail ) of the queue Queue Operations: enqueue: Add a new element to the rear of queue. It requires element to be added and returns nothing. dequeue :   Removes the elements from the front of queue. It does not require any parameters and returns the deleted item. isEmpty:  Check the whether the queue is empty or not. It do

Difference between Stack and Queue

Image
  Difference between Stack and Queue ================================================================================= Stack : A stack is a direct information structure in which components can be embedded and erased exclusively from one side of the rundown, called the top. A stack follows the LIFO (Rearward In First Out) rule, i.e., the component embedded at the latter is the main component to emerge. The inclusion of a component into the stack is called push activity, and the erasure of a component from the stack is called pop activity. In stack, we generally monitor the last component present in the rundown with a pointer called top. Queue : is a linear data structure in which elements can be inserted only from one side of the list called rear, and the elements can be deleted only from the other side called the front. The queue data structure follows the FIFO (First In First Out) principle, i.e. the element inserted at first in the list, is the first element to be removed from the l

STACK

Image
STACK ================================================================================ Stack is a linear data structure that follows a particular order in which the operations are performed.  The order may be LIFO(Last In First Out) or FILO(First In Last Out). Basic Operation on Stack: push() :  To insert an element into the stack pop() :  To remove an element from the stack top() :  Returns the top element of the stack. isEmpty() :  Returns true if stack is empty else false. isFull() :  Returns true if stack is full else false. push(): Adds an item to the stack. If stack is full, then it said to be an "Overflow Condition". Time Complexity: 0(1) Only a new node is created and the pointer of the last node is updated. This includes only memory allocation operations. Hence it can be said that insertion is done in constant time. Algorithm: begin if stack is full return endif else increment top stack[top] = assign value end else end Flow Chart: %3CmxGraphModel%3E%3Croot%3E%3CmxCel