All you would like to know about

✪ Array Data Structure
✪ Array Operations
✪ Array Based Problems

* Time and Space Complexities covered

DSA Series: 🧵 👇
We will cover

1️⃣ Introduction
2️⃣ Array Size
3️⃣ Array Index
4️⃣ Array Dimension
5️⃣ Array Operations
6️⃣ Other Array-based Data Structures
7️⃣ Some Array-based Problems
1️⃣ Introduction

An array is a "collection of items" stored at contiguous memory locations.

Syntax: All items are written comma-separated inside square brackets.

Example: [1, 2, 3, 4, 5]

There are total 5 items in the array. 1 is the first item, 2 is the 2nd and 5 is the last.
2️⃣ Array Size

The total number of items contained in an array defines its size.

There are 2 types of Arrays wrt its size. Static Sized and, Dynamic Sized.

++
✪ Static Sized
These arrays are initialised with a size which can never be changed. If array is full, no new item can be inserted until any existing item is removed.

✪ Dynamic Sized
When a dynamic sized array is full, while inserting a new item, size is increased.
3️⃣ Array Index

An item in the array can be accessed "directly" by using an index (an integer).

Each array has a "base index" which is used to access the first item in the array.

++
Index of an item is calculated by adding an "offset" to the base index.

Offset indicates how far an item is from the very first item in the array. 1 item far means offset is 1, 10 items far means offset is 10.
4️⃣ Array Dimension

If items of an array are non-arrays, its dimension is 1.
If items are arrays, its dimension is (child array dimension + 1).

Example: [[1,2,3],[4,5,6]] is a 2-dimensional array.

Items are accessed using 2 indices.

Example: array[1][2]
5️⃣ Array Operations

5️⃣.1️⃣ Get
5️⃣.2️⃣ Insert/Update
5️⃣.3️⃣ Remove
5️⃣.4️⃣ IsEmpty
5️⃣.5️⃣ Search
5️⃣.6️⃣ Sort
5️⃣.1️⃣ Get

Getting an item in an array is straightforward. Index of the item is used to fetch it directly.

Example: array[1] fetches an item at Index "1"

Time Complexity: O(1)
5️⃣.2️⃣ Insert/Update

If no item is already existing at an index, attempting to store an item at that index is known as "Insert". Or else it's an "Update" operation.

Example: array[2] = 5

Here item "5" is inserted/updated at index "2" of array.

Time Complexity: O(1)
5️⃣.3️⃣ Remove

When an item at an index is removed from array, that place becomes empty.

Example: delete array[1]

Time Complexity: O(1)
5️⃣.4️⃣ IsEmpty

It checks if no items are present in the entire array.

To do this, we traverse through entire array starting from the base index and continue till the last index.

If an item is found at any index, this operation returns "false". Else "true"

Time Complexity: O(n)
5️⃣.5️⃣ Search

To search for an item in an array, array has to be traversed. There are 2 popular search techniques. Both of these will be discussed in separated threads.

5️⃣.5️⃣.1️⃣ Linear Search
Time Complexity: O(n)

5️⃣.5️⃣.2️⃣ Binary Search
Time Complexity: O(log n)
5️⃣.6️⃣ Sorting

Sorting (or ordering) is done to keep items of an array is a specific order (increasing, decreasing or, custom defined)

There are many sorting techniques and each will be discussed in upcoming threads. Here, we will highlight their time and space complexities.

++
5️⃣.6️⃣.1️⃣ Bubble Sort
Time: Best O(n), Worst O(n²), Avg O(n²)
Space: O(1)

5️⃣.6️⃣.2️⃣ Selection Sort
Time: Best O(n²), Worst O(n²), Avg O(n²)
Space: O(1)

5️⃣.6️⃣.3️⃣ Insertion Sort
Time: Best O(n), Worst O(n²), Avg O(n²)
Space: O(1)

++
5️⃣.6️⃣.4️⃣ Merge Sort
Time: Best O(nlogn), Worst O(nlogn), Avg O(nlogn)
Space: O(n)

5️⃣.6️⃣.5️⃣ Quick Sort
Time: Best O(nlogn), Worst O(n²), Avg O(nlogn)
Space: O(logn)

5️⃣.6️⃣.6️⃣ Counting Sort
Time: Best O(n), Worst O(n), Avg O(n)
Space: O(max)

++
5️⃣.6️⃣.7️⃣ Radix Sort
Time: Best O(n), Worst O(n), Avg O(n)
Space: O(max)

5️⃣.6️⃣.8️⃣ Bucket Sort
Time: Best O(n), Worst O(n²), Avg O(n)
Space: O(n)

++
5️⃣.6️⃣.9️⃣ Heap Sort
Time: Best O(nlogn), Worst O(nlogn), Avg O(nlogn)
Space: O(1)

5️⃣.6️⃣.1️⃣0️⃣ Shell Sort
Time: Best O(nlogn), Worst O(n²), Avg O(nlogn)
Space: O(1)
6️⃣ Other Array based Data Structures

✪ Stack
✪ Queue
✪ Dequeue
✪ Priority Queue
7️⃣ Array based Problems

✪ Rotating an Array
✪ Split an array and attach the first part after the second part
✪ Rearrange an array (based on array value, index etc)
✪ Find kth maximum and minimum item
✪ Find mean, median and mode
✪ Find number of occurrences of an item
We have come to the end of the very first thread of DSA series. I hope you enjoyed going through it.

Share your feedbacks. Like and Retweet the very first tweet to support and encourage me.

Follow @swapnakpanda to receive more threads from DSA series.

See you soon 👋

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Swapna Kumar Panda ✨

Swapna Kumar Panda ✨ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @swapnakpanda

23 Oct
Tree, Binary Tree and Binary Search Tree

Know the difference. 👇
0️⃣ Introduction to a Tree

✪ A Tree is a data structure where each element is called as a "Node".

✪ Unlike a Linked List, a Node in a Tree can point many (child) nodes.

✪ The first node from which traversal begins is called the Root Node.

++
✪ Each child node can be root of a separate tree. Each such trees are known as "Subtrees" of a given node.

✪ The number of parents, a node can have is called its "In-Degree" and it is always 1.

✪ The number of children, a node can have is called its "Out-Degree".
Read 7 tweets
22 Oct
Difference between an Array and a Linked List

These differences will make you grasp the fundamentals of both Array and Linked List really quick.

And if you are preparing for any interviews, it would definitely help you.

Let's explore 👇
1️⃣ Storage
2️⃣ Size
3️⃣ Access of Elements
4️⃣ Insertion/Deletion of Elements
5️⃣ Search for Elements
6️⃣ Memory Allocation
7️⃣ Memory Usage
8️⃣ Memory Utilisation
9️⃣ Use case

Read 12 tweets
21 Oct
🔥 MATRIX Operations implemented in JavaScript 🚀

Welcoming you to this super exciting 🧵 where we will implement various matrix operations in JavaScript along with their Complexity Analysis (both Time and Space).

Are you excited to know? 👇
We will cover 👇

🔹 Dimension
🔹 Square Matrix
🔹 Diagonal Matrix
🔹 Upper Triangular
🔹 Lower Triangular
🔹 Identity Matrix
🔹 Zero Matrix
🔹 Transpose Matrix
🔹 Scalar Multiplication
🔹 Matrix Addition
🔹 Matrix Subtraction
🔹 Matrix Multiplication
🔹 Orthogonal Matrix

0️⃣ Introduction

Matrix is a 2-dimensional (array) arrangement of numbers and it has vast use in Linear Algebra.

Example:
[[a₁₁, a₁₂, a₁₃],
[a₂₁, a₂₂, a₂₃],
[a₃₁, a₃₂, a₃₃]]

Each element in the inner array is called an element of the matrix. Eg, a₁₁

++
Read 19 tweets
19 Oct
7️⃣5️⃣ Numeric Problems to strengthen your *COMPETITIVE CODING* skill

✪ Are you planning to be a competitive coder?
✪ But not sure how to start?

Don't worry. Here are 75 numeric problems that will certainly improve your competitive coding skill.

Problems listed 👇
1️⃣ Number

1️⃣ Find a digit at a specific place in a number
2️⃣ Find count of digits in a number
3️⃣ Find the largest digit
4️⃣ Find the 2nd largest digit
5️⃣ Find the smallest digit
6️⃣ Find the 2nd smallest digit
7️⃣ Find generic root (sum of all digits) of a number

++
8️⃣ Reverse the digits in a number
9️⃣ Rotate the digits in a number
1️⃣0️⃣ Is the number a palindrome?
1️⃣1️⃣ Find the binary, octal and hexadecimal equivalent
1️⃣2️⃣ Convert a binary, octal and hexadecimal to a decimal
1️⃣3️⃣ Find sum of 'n' numbers

++
Read 13 tweets
18 Oct
1️⃣0️⃣ List Sorting Techniques

Let's explore 10 famous sorting techniques through this introductory of Data Structures and Algorithms (DSA) series.

🧵 👇
We will discuss about

1️⃣ Bubble Sort
2️⃣ Selection Sort
3️⃣ Insertion Sort
4️⃣ Merge Sort
5️⃣ Quick Sort
6️⃣ Counting Sort
7️⃣ Radix Sort
8️⃣ Bucket Sort
9️⃣ Heap Sort
1️⃣0️⃣ Shell Sort

1️⃣ Bubble Sort

✪ Compare 2 consecutive elements. Swap if 1st one is larger than 2nd one.

✪ At the end of each iteration, largest element in the list bubbles up to the top of the list.
Read 13 tweets
17 Oct
4️⃣ CRUD Operations described wrt SQL, REST API and UI

🧵 👇
0️⃣ Introduction

CRUD stands for Create, Read, Update and Delete.

These are the 4 basic operations of persistent storage.

The term CRUD is also used for Database and UI.

Let's explore these 👇
1️⃣ C for Create

SQL: INSERT into TABLE_NAME VALUES (V1, V2, V3)

REST HTTP Method: POST

UI Form: User Sign Up, Creating a Blog Post etc.
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(