0% found this document useful (0 votes)
18 views

Data Algo

Uploaded by

Arun Arun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Data Algo

Uploaded by

Arun Arun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

-------------------------------------------------------------------------DATA

STRUCTURES-------------------------------------------------------------------------
-----
DATA STRUCTURE :
Data structure is different way of organizing the data in an computer
More effective

TYPES OF DATA STRUCTURE :

PRIMITIVE : These are Basic Data types and that cannot be broken into small data
type.
* Int
* Float
* String
* Boolean

NON PRIMITIVE : These are Complex Data types and that can be broken into smaller
data type.
--> LINEAR :
* list {Built in Data type}
* Tuple {Build in Data type}
* Array
* Linked List
* Stack
* Queue

--> NON LINEAR :


* Set {Built in Data type}
* Dictionary {Built in Data type}
* Tree
* Graph

ALGORITHM :
Set of instruction perform a task.

EXAMPLE : Day-To-Day Activities


1. Go to the Bus Stop
2. Take a Bus
3. Go to Office.

TYPES OF ALGORITHM :

--> SORTING : To sort the data in Ascending or Decending order.


EXAMPLE : Bubble sort, Selection sort , Insertion sort etc..

--> SEARCHING : To find a specific value from the data set.


EXAMPLE : Linear search , Binary search etc..

--> GRAPH : To work with data can be represented as Graph.


EXAMPLE : Depth first search, breath first search, Dijkstra etc..

--> DYNAMIC PROGRAMMING : To solve the problem by breaking down into smaller sub-
problems.
EXAMPLE : Knapsack Problems etc..

--> DIVIDE AND CONQUER : To solve the problem by breaking down into smaller sub-
problems, solving them independently each and combining the results.
EXAMPLE : Merge sort or Quick sort etc..
--> RECURSIVE : To solve the problem by breaking down into smaller sub-problems,
same as in Nature.

BIG O :
Big O is a language and metric system , that use to describe the efficiency of
an Algorithm.

EXAMPLE : Code 1 : 30 sec ; Code 2 : 60 sec


Here code 1 is faster than code 2 . Time taken by code 1 is less
compare to code 2 , then its called as Time Complexity.

Big O would not consider the Time complexity, its based on NUMBER OF
OPERATIONs.

EXAMPLE : code 1: 40 sec ; code 2 : 60 sec


code 1 may took high memory due to less time to response than code
2 , code 2 took less memory compare to code 1, then its called Space Complexity.

1 2 3 4 5 6 7 8
omega Theta O

BIG OMEGA : Best case Complexity


BIG THETA : Average case complexity
BIG O : Worst case Complexity

In Big O notation we will use to Worst case scenario only.

|-------------|-------------|------------------------------------------|
| COMPLEXITY | NAME | SAMPLE |
|-------------|-------------|------------------------------------------|
| O(1) | Constant | Simple add numbers Functions |
|-------------|-------------|------------------------------------------|
| O(n) | Linear | Loop through numbers from 1 to n numbers |
|-------------|-------------|------------------------------------------|
| O(LogN) | Lograthmic | Find element in a sorted Array |
|-------------|-------------|------------------------------------------|
| O(N^2) | Quadratic | Nested loops |
|-------------|-------------|------------------------------------------|
| O(2N) | Exponential | Double recursion in Fibonacci |
|-------------|-------------|------------------------------------------|

1. O(1) --> Order of 1 Complexity


This means that for any input ,execution will not change.It remain
Constant.
EXAMPLE : def multiply(m):
return m*m
print(multiply(5))

In above example input may increasing but number of


operations remain same.

2. o(n) -- > Order of N Complexity


This means that for any input increases , excution of number of
operation increases.
EXAMPLE : def print_items(m):
for i in range(m):
print(i)

In above example input increases, number of operation


also increases.

3. O(N^2) --> Order of N^2 Complexity


EXAMPLE : def mul(n):
for i in range(n): ----------> O(n)
for j in range(n): ------> O(n)
print(i,j)

mul(10)
In above Example i will run through n times and after
i j will runs for evry n times.totally its N^2

4. O(Log N) --> order of Log N Complexity


EXAMPLE : Consider the below list
[1 | 2 | 3 | 4 | 5 | 6 | 7 | 8]

In above list we have to find Number 1 , so we have


to split into two list as below

[1 | 2 | 3 | 4] [5 | 6 | 7 |8]

Remove the 2 nd splitted list because there is no


Number 1 presented ,again split the list 1 as below

[1 | 2] [3 | 4]

Remove the list 2 after spliting because there is


no Number 1 value present and we are splitting list 1 again

[1] [2]

Finally we have found the Number 1.

To find the value of the 1 we made 3 steps to split


it to get the value.

Log 2^3 = 8

Here, 2--> Splitting into 2 divided parts


3--> three tymes we split to get value as
expected.
8--> 2^3 - 2*2*2 = 8(value)

ARRAY :
Array is collection of same Data types.Its same as list in python but in python
we can store diffrent data types towards an list.

--> Array can store same data type.


--> Elements in array are contiguous.
--> Each element in array has unique index value.

TYPES OF ARRAY :
---> ONE DIMENSIONAL ARRAY :
An Array with bunch of values having been declared with single
index.
It consists of 1 Row and N columns.

EXAMPLE : [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... N]

---> MULTI DIMENSIONAL ARRAY :


An Array with bunch of values having been declared with Double
index.
It consists of N Row and N columns.

EXAMPLE : [1 2 3 4 5 ]
[6 7 8 9 10]
[11 12 13 14 15]

ARRAY INSERT : Insert value in the particular index.


ARRAY TRAVERSE : Traverese is moving to next index like iteration over array.

You might also like