Introduction to DSA
Data Structures Overall
In linear data structures, elements are arranged in a sequential manner. Example:
Arrays: Think of an array like a row of lockers. Each locker holds an item and is identified by a unique number.
Linked Lists: Imagine a chain where each link knows about the link following it.
Stacks and Queues: Stacks are like a pile of books, where you can only interact with the top book.
Queues, on the other hand, are like a line at a grocery store - the first one in line gets served first.
Linear Data Structures
Non-Linear Data Structures
Non-linear data structures, as the name implies, do not maintain a particular sequence for the arrangement of elements.
Example:
Trees: Think of a family tree where each person is a node that has connections to their parents and children.
Graphs: These are like social networks, where each person (node) can be connected to multiple other people (nodes).
Big-O Notation
Big-O notation is a way of expressing the time and space complexity of an algorithm.
It provides a rough estimate of how long an algorithm takes to run and how much memory it uses, based on the size of the input.
It’s important to note that Big-O notation only provides an upper bound (max time) on the running time of an algorithm.
These factors depend on hardware on which the code is being run and language's implementation.
Big-O Notation
Time complexity is a measure of how long an algorithm takes to run, based on the size of the input.
Time Complexity
Space Complexity
Time complexity is a measure of how long an algorithm takes to run, based on the size of the input.
Extra or temporary space used by an algorithm, other than given input.
Auxiliary Space Complexity
Big-O Notation
Examples of time complexity expressed using Big-O notation:
O(1): Constant time.
O(n): Linear time.
O(n2) : Quadratic time.
O(logn) : Logarithmic time.
O(2n): Exponential time.
Big-O Notation
Big-O Notation
Operations on Data Structures
- Accessing Elements
- Searching Elements
- Inserting Elements
- Deleting Elements
- Updating Elements
Worst case scenarios
DSA: Big O'Notation
By Yash Priyam
DSA: Big O'Notation
- 139