Application of Non
Application of Non
Application of Non
Advantages of Arrays
Below are some advantages of the array:
In an array, accessing an element is very easy by using the index number.
The search process can be applied to an array easily.
2D Array is used to represent matrices.
For any reason a user wishes to store multiple values of similar type then the
Array can be used and utilized efficiently.
Disadvantages of Arrays
Now let’s see some disadvantages of the array and how to overcome it:
Array size is fixed: The array is static, which means its size is always fixed.
The memory which is allocated to it cannot be increased or decreased. Below is
the program for the same:
Advantages of Stack:
Stack helps in managing data that follows the LIFO technique.
Stacks are be used for systematic Memory Management.
It is used in many virtual machines like JVM.
When a function is called, the local variables and other function parameters
are stored in the stack and automatically destroyed once returned from the
function. Hence, efficient function management.
Stacks are more secure and reliable as they do not get corrupted easily.
Stack allows control over memory allocation and deallocation.
Stack cleans up the objects automatically.
Disadvantages of Stack:
Stack memory is of limited size.
The total of size of the stack must be defined before.
If too many objects are created then it can lead to stack overflow.
Random accessing is not possible in stack.
If the stack falls outside the memory it can lead to abnormal termination.
Advantages of Queue:
A large amount of data can be managed efficiently with ease.
Operations such as insertion and deletion can be performed with ease as it
follows the first in first out rule.
Queues are useful when a particular service is used by multiple consumers.
Queues are fast in speed for data inter-process communication.
Queues can be used in the implementation of other data structures.
Disadvantages of Queue:
The operations such as insertion and deletion of elements from the middle
are time consuming.
Limited Space.
In a classical queue, a new element can only be inserted when the existing
elements are deleted from the queue.
Searching an element takes O(N) time.
Maximum size of a queue must be defined prior.
Advantages of Graph:
By using graphs we can easily find the shortest path, neighbors of the
nodes, and many more.
Graphs are used to implement algorithms like DFS and BFS.
It is used to find minimum spanning tree which has many practical
applications.
It helps in organizing data.
Because of its non-linear structure, helps in understanding complex
problems and their visualization.
Disadvantages of Graph:
Graphs use lots of pointers which can be complex to handle.
It can have large memory complexity.
If the graph is represented with an adjacency matrix then it does not allow
parallel edges and multiplication of the graph is also difficult.
Step 5 - If there are no new vertices to visit, go back and pop one
from the stack using backtracking.
DFS:
Time complexity is again O(|V|), you need to traverse all nodes.
Space complexity - depends on the implementation, a recursive
implementation can have a O(h) space complexity [worst case],
where h is the maximal depth of your tree.
Using an iterative solution with a stack is actually the same as BFS,
just using a stack instead of a queue - so you get both O(|V|) time
and space complexity.
Breadth-First Search Algorithm
Step 1: In the graph, every vertex or node is known. First, initialize
a queue.
For Unweighted Graphs, You Must Use the Shortest Path and
Minimum Spacing Tree.
Broadcasting Network
Garbage Collection
Identifying Routes
To see if there is a path between two vertices, you can use either
Breadth-First or Depth First Traversal.
Finding All Nodes Within One Connected Component
To locate all nodes reachable from a particular node, you can use
either Breadth-First or Depth First Traversal.
BFS:
Time complexity is O(|V|), where |V| is the number of nodes. You
need to traverse all nodes.
Space complexity is O(|V|) as well - since at worst case you need
to hold all vertices in the queue.