Ads

Saturday, 25 February 2017

Core Data -> Part-1

Hi Guys, today we are going to learn about CORE DATA.

What is Core Data?

Core Data is not a Data base, it is a framework used to manage the model layer objects in our application.

Advantages of Core Data:

-> Core Data decrease the over head of writing the code to support model layer by 50% to 70%.
-> "Faulting", by using Core Data only the objects that we are currently using will be loaded.
-> Related to this Faulting technique the changes made to the objects can only be saved, not all the objects to be saved.
-> Automatic validation.
-> Lazy loading of data.
-> Easy migration from different versions.
-> We can use complex query to fetch the records using NSPredicate.

Terms to be known:

Before going into future we have to know few things.

1. Core Data Stack
2. Managed Objects
3. Persistent Sore Coordinator
4. Managed Object Context
5. Persistent store.

Data Structure - Searching - Interpolation

Interpolation Search

It is one of the searching technique and it is the fast search algorithm.

-> The runtime complexity is O(log(log n)).
-> It follows divide and conquer principle
-> The elements in the array should be in sorted form and equally distributed.

The searching is similar to binary search but it is little advanced than the binary search.

It search with the formal shown below.

mid = Lo + ((Hi - Lo) / (A[Hi] - A[Lo])) * (X - A(Lo))

where 

A = List
Lo = Lowest index
Hi Highest index
A[n] = the nth element in the Array

Data Structure - Searching - Binary

Binary Search

It is one of the searching technique and it is the fast search algorithm.

-> The runtime complexity is O(log n).
-> It follows divide and conquer principle
-> The elements in the array should be in sorted form

How searching technique works

Let me explain with an example.

Array

14 22 31 68 72 88 89 92

and we want to search the element 22.

Step 1: get the value of middle element in the array

Value = 68 and X = 22, Since X is less than Value I have to move to left side of the array.

Step 2: Get the middle value from the left remaining array.

Value =22 and X=22. Since X and Value are same we return the index value as 1


Algorithm

Lets say we have an array of elements in sorted order called as A
And size of array is n
We have to find the value X

Step 1: Set i =0
Step 2: Set middleElement = A[(int)(i+n)/2]
Step 3: nStep 3: if X == middleElement then Print element found at middle Element Position and Exit
Step 4: if X> middleElement then Go to Step 6
Step 5: Set n = (int)(i+n)/2 and Go to Step 2
Step 6: Set i = (int)(i+n/2) and n = n-i








Data Structure - Searching - Linear

Linear Search

It is one of the searching technique.

It takes the element and it compares the all the elements in the array until the desired element is found.

Algorithm

We have an array A and we have to find the element X.

Step 1: Set i =1
Step 2: if i > n then Print element not found and EXIT
Step 3: if A[i] = X then Print element found and EXIT
Step 4: Set i=i+1 and Go to Step 2

Stack and Queue

Stack and Queue, both are abstract data structures.

Stack

It follows LIFO(Last In First Out)

The stack basic operations are

1. Push (adds an element at the end)
2. Pop (removes an element from the end)
3. Peek (reads the top element in the stack)
4. isFull (checks whether the stack is full or not)
5. isEmpty (checks whether the stack is empty or not)

Queue

It follows FIFO(Fisrt In First Out)

The stack basic operations are

1. enqueue (adds an element to the queue)
2. dequeue (removes an element to the queue)
3. Peek (reads the top element in the stack)
4. isFull (checks whether the stack is full or not)
5. isEmpty (checks whether the stack is empty or not)

Data Structure And Algorithm - Circular Linked List

Both Singly Linked and Doubly Linked list can be made to circular linked list.

Singly Linked List as circular is show as below
 Doubly Linked List as circular is show as below

Basic operations of circular linked lists are

1. Insert
2. Delete
3. Display


This ends the Linked list concept.

Thanks guys for reading this. Hope this helped you a liitle

Data Structure And Algorithm - Doubly Linked List

In doubly linked list, the navigation happens in both the ways, forward and backwards.

 In Doubly Linked list each link carries a data field and two link fields called next and prev.

Basic Operations are

1. Insertion(Add element at beginning)
2. Deletion(Delete element at beginning)
3. Insert Last(Add element at end)
4. Delete Last(Delete element at end)
5. Insert After(Insert after an element)
6. Delete(Delete after an element)
7. Display forward(Displays list in forward manner)
8. Display backward(Displays list in backward manner)


Data Structure And Algorithm - Simple Linked List

Today we are going to discuss about Linked Lists.

There are 3 kinds of linked lists.
1. Simple Linked List
2. Double Linked List
3. Circular Linked List

Why Linked List ?

Linked list are most commonly used after arrays. There are few advantages listed below over arrays.

1. Linked lists are dynamic data structures because they can grow by allocating memory and pruned by deallocating the memory dynamically.

2. Items in the linked list can be removed or added at any position of the linked list.

3. Insertion and deletion of elements are easier.


In linked list, the items are connected in a sequence via links and the basic operations are:

1. Insertion
2. Deletion
3. Display
4. Search
5. Delete

For Simple Linked list there are 3 basic operations and 2 operations are explained below
1. Insertion
2. Deletion
3. Reverse

I would like to explain Insertion here

Lets consider a Linked list with Node 1 and Node 2 as show in below figure

Now I want to insert a node in between node 1 and node 2


Now we have to attach Node1.2 next to the Node 2 as shown below



Now remove the connection between node 1 and node 2 and connect node 1 next to the node 1.2 as shown below


Finally we have inserted the node in the middle and the Linked list looks like below.

Similarly Deletion looks exactly reverse way of Insertion.

Lets consider we have node 1, node 2 and node 3. We want to remove node 2, so follow the steps below.

Step 1: Change the node1 next to node 3 from node 2

Step 2: Remove the connection of node 2 next from node 3

Step 3: Display the final list with node 1 and node 3.



Algorithm

Hi friends, In my previous post we have came to know what is Data Structure. If not, please go to this link.

Today we are going to know about Algorithm.

Algorithm Basis

Algorithm is step by step procedure, which defines a set of instruction to be executed in an order to get the required outputs.

Following are the important categories:

1. Search
2. Sort
3. Insert
4. Update
5. Delete

Characteristics of an Algorithm:

1. Should be clear in every step.
2. Well defined Inputs.
3. Well defined and required outputs.
4. Should be finite and it should be terminated after some steps
5. Independent of any language

Algorithm Analysis:

There are 2 different stages to find the efficiency of an algorithm.
They are

1. Before Implementation
2. After Implementation

Algorithm Complexity:

The complexity of the algorithm depends on 2 factors.

1. Time factor (Time taken to complete the number of operations)
2. Space factor (Maximum memory space taken for the elements in the algorithm)

Space Complexity:

Space Complexity depends on 2 factors.

1. Fixed part (C) -> Space required to store data for certain variables, constants, program size, etc.
2. Variable Part (S(I)) -> It depends on dynamic allocation of variables/ objects, stack space etc.

S(P) = C + SP(I)

Time Complexity:

Time required to complete the program. Usually time required to complete the program goes into 3 types of categories.

1. Best Case
2. Average Case
3. Worst Case

Asymptotic Notations

There are 3 main asymptotic notations to calculate the running time complexity of the algorithm.

1. O Notation (Represents the upper bound of the algorithm which represents worst case time)
2. Ω Notation (Represents the lower bound of the algorithm which represents best case time)
3. θ Notation (Represents the both upper and lower bound of the algorithm which represents best and worst case time respectively).





Data Structure

Hi Friends, Today in modern world Data Structures plays a major role. Many Companies thinks that the person with DSA knowledge is having the good capabilities in problem solving skill.

So today our topic is Data Structure.

Why Data Structure ?

Every application uses data structure in programmatic way to store data so that data can be used more effectively. Data Structure needs algorithm to design the complex applications.

Foundation Terms of a Data Structure

There are 2 different terms of a data structure.

1. Interface

In data structure, interface represents the set of operations that a data structure supports.

2. Implementation

In data structure, implementation represents the internal representation and the definition of the algorithm used in the operation of data structure.

Characteristics of Data Structure

1. Correctness
2. Time Complexity
3. Space Complexity

Basic Terms of Data Structure

Data Types

In Data Structure, data types are of 2 types

1. Build-in Data Types (Integers, Boolean, Floating, Character and Strings)
2. Derived Data Types (Array, List, Stack and Queues)

Basic Operations

The basic operations are follows:

1. Traversing
2. Searching
3. Insertion
4. Deletion
5. Sorting
6. Merging

SOLID Principles

SOLID principles are the basic essential thing to know for every developer before he/she starts coding in any IDE. Here is the full form S ...