DSA notes python
DSA notes python
Q2. What are the different operation possible with stack data structures?
Ans:
The following are some common operations implemented on the stack:
A. Push: When we insert an element in a stack then the operation is known as a push. If the stack is full then
the overflow condition occurs.
2.If we try to insert the element in a stack, and the stack is full, then the overflow condition occurs.
3.When we initialize a stack, we set the value of top as -1 to check that the stack is empty.
4.When the new element is pushed in a stack, first, the value of the top gets incremented, i.e., top=top+
1, and the element will be placed at the new position of the top.
5.The elements will be inserted until we reach the max size of the stack.
B. Pop: When we delete an element from the stack, the operation is known as a pop. If the stack is empty
means that no element exists in the stack, this state is known as an underflow state.
POP operation
The steps involved in the POP operation is given below:
• Before deleting the element from the stack, we check whether the stack is empty.
• If we try to delete the element from the empty stack, then the underflow condition occurs.
• If the stack is not empty, we first access the element which is pointed by the top
• Once the pop operation is performed, the top is decremented by 1, i.e., top=top-1
• Recursion: The recursion means that the function is calling itself again. To maintain the previous states, the
compiler creates a system stack in which all the previous records of the function are maintained.
• Expression conversion: Stack can also be used for expression conversion. This is one of the most important
applications of stack. The list of the expression conversion is given below:
Infix to prefix
Infix to postfix
Prefix to infix
Prefix to postfix
Postfix to infix
Memory management: The stack manages the memory. The memory is assigned in the contiguous memory blocks.
The memory is known as stack memory as all the variables are assigned in a function call stack memory.
The insertion into a singly linked list can be performed at different positions. Based on the position of the new node
being inserted, the insertion is categorized into the following categories.
Q7.What are the different operation possible with Arrays data structures?
Ans:
• Insertion - It is used to add an element at a particular index.
Insertion operation
This operation is performed to insert one or more elements into the array. As per the requirements, an element can be
added at the beginning, end, or at any index of the array. Now, let's see the implementation of inserting an element into the
array.
• Dequeue: It performs the deletion from the front-end of the queue. It also returns the element which has been
removed from the front-end. It returns an integer value.
2. Queues are used in asynchronous transfer of data (where data is not being transferred at the same rate
between two processes) for eg. pipes, file IO, sockets.
3. Queues are used as buffers in most of the applications like MP3 media player, CD player, etc.
Q12. draw the graphical representation of Big-OH ,Big Omega and Theta notation.
Ans:
1. Big O notation (O):
It is defined as upper bound and upper bound on an algorithm is the most amount of time required ( the worst case performance).
Big O notation is used to describe the asymptotic upper bound.
Mathematically, if f(n) describes the running time of an algorithm; f(n) is O(g(n)) if there exist positive constant C and n0 such that
Mathematically, if f(n) describes the running time of an algorithm; f(n) is O(g(n)) if there exist positive constant C and n0 such that,
0 <= f(n) <= Cg(n) for all n >= n0