Sunday, 30 June 2013

differences between Graphs and Trees? [excluded Graphical Concept]

Topic
Graph
Tree


Rules & Restriction:
In general graph doesn’t really have any rules and restrictions.
Tree is the restricted specialized version of graph with numerous rules specially how to connect nodes.

Direction :
Graph can have Uni-directional or Bi-directional paths between nodes.
Tree has linear direction (only one path between each two vertices) that comes along with “Parent-children” relationship.

*point to be noted: one child can have only one parent (as it is in real.)

Circles and all :
Can be cyclic (or acyclic) or have loop, circuit and self loop.
Tree doesn't have any circles back or self loop or circuit or cycles.

Recursive Data :
No such thing.
Tree is Recursive Data Structure due to the nodes with children.

DAG:
Can only be cyclic or acyclic
Tree fits within the category of Directed Acyclic Graphs in short DAG (graph that has no cycles).

Complexity:
Graphs are more complex due to all the loops and cycles it got.

Trees are really easy to understand.
Connection:
In graph objects connects themselves by Links.

*in mathematical abstractions it calls Vertices or in between same pair it calls edges.

Tree is actually Minimally connected graph. In easy English its: one path between each two vertices.
Outlook:
It’s more likely a diagrammatic overview.
It’s more likely a flow looking overview.
(e.g. flow chart)

Root node:
No such thing.
Exactly only one root node.

Parent child relation:
No such thing.
In tree, there is parent child relationship for the sake of flow so there can be the direction top to bottom or vice versa.

Traversal kinds:
Graph traversed by DFS (depth First Search) and BFS (Breadth First Search) algorithm.
3 types:
a. Pre order
b. In order
c. post order
*all of these are in DFS or BFS algo.

Different types:
Basically only two types can be highlighted:
a. Directed graph
b. Undirected graph

There are actually too many. Like, Binary tree, Binary Search Tree, AVL tree, Heaps etc.
Number of edges:
No boundary.
Always have to have n-1 numbers of edges.

Model type:
Network model.
Hierarchical model




Wednesday, 26 June 2013

what is Stack and Queue? [ simplest yet every detail]

Stack:
a list of elements where insertion (push) or deletion (pop) is and can only be done at one same end.
the bookish name of it is LIFO. stands for Last In First Out.

special terminology:

  1. push: to insert any element into the stack.
  2. pop  ; to delete any element from the stack.

example:
its like a cookie jar. Top most cookie in the jar is only accessible.

application:
the whole "UNDO" concept or the thing we do by pressing CTRL+ Z is done by stack, or like in Maze puzzles.



Queue;
linear list of elements where insertion (rear)  and deletion (front) can only be done by different ends.
bookish name of it is FIFO, stands for First In First Out. queue has head and tail.

special terminology:

  1. enqueue (rear) : to operate insertion operation.
  2. dequeue (front): to operate deletion operation.

example:
like people waiting in a line for movie tickets, new ( or last) person will stand at the end of the line every time. or like a fancy restaurant where i can enter and get out using 2 different way, and can't mess it up :P .

application:
like in BFS( breadth first search) or DFS( deapth first search).

Algorithm: Pseudo-code to find the Smallest element form a list of items stored in a linear array.

a nonempty array DATA with N numerical values is given. an algorithm to find the location LOC and the value MIN of the smallest element of array DATA. a variable K is gonna be use as counter.

  1. set K :=1, LOC :=1 and MIN :=DATA[0].    [ initialization ]
  2. While K<=N, repeat step 3
  3. IF MIN > DATA[K], then set LOC :=K and MIN :=DATA[K]                                         ELSE K :=K+1.
  4. Write: LOC, MIN
  5. Exit.

difference between Algorithm, Pseudo-code and Program? [ simple and short but yet everything ]

algorithm: ( set of logic statement/method ) :
is a detailed sequences of steps from beginning to end to carry out the whole process.
logic or the basic plan of the action, behind of getting something done.it has rules to follow.

pseudo-code: ( function of describing/outlining the algorithm ) :
pseudo code is kinda like "intermediary" between algorithm and implemented program.
algorithm is the semantic of the process while pseudo code is the syntax to communication sake to solve any problem or do any task. no rules

program:
a detailed set of instruction for a machine (in this case the computer itself) to carry out the task.
its the real implement of computer algorithms. program start working after when the  algorithm is done making.


in short:
algorithm is the "skeleton" of the plan/task and program  is like "giving it it's shape" and pseudo code is telling the program how the algorithm wants the plan/ task to turn out to be.

among these three PSEUDO-CODE is the most easiest for human brain to understand or to make.

Tuesday, 25 June 2013

what is Doubly and Circular linked list? [ simple explanation ]

doubly linked list:
linked list containing nodes that carries two pointer one (left side one) for the previous node and the other for (right side one) the next node. so Doubly liked list's node carries 3 field.
  1. link to point the previous node
  2. integer value carrying field 
  3. link to point the next node.
this picture might help to understand :






circular linked list:
in short, linked list of which 1st node's link is stored in the link part of the last node.


little help with a diagram:


heads up:
non circular is mostly known as acyclic 

Algorithm: Pseudo-code to find a particular item form a list of items stored in a linear array.

a nonempty linear array DATA with N elements in it and a ITEM of information / element are given. a linear search algorithm is to find the ITEM in DATA and if so then location LOC of ITEM in DATA to print out.

  1. set K :=1 and LOC:=0. [ initialize ]
  2. while LOC=0 and K<=N, repeat step 3 and 4.
  3. if ITEM = DATA[K], then set LOC :=K.
  4. set K:=K+1. [increment counter ] [end of step 2 loop ]
  5. If : LOC=0 then:  Write: ITEM isn't in the array DATA.                                                       Else: Write: LOC is the location of ITEM..
  6. Exit.



differences between Array and Linked list? [with simple explanation ]

topics
Array
Linked list

1.continuity
Array has continuous memory.
Linked list may or may not be continuous. It’s not really necessary for any linked list to fulfill continuity condition.

2.insertion/
deletion
Quite difficult.
Pretty much easier. Easy insertion and deletion is sort of the main base on why linked list concept was built.

3.space wastage
Spaces get to waste quite often.
There actually no chance for it.


4.expensity
Comparatively expensive.
Less expensive.

5.size accuracy
Size in array is always fixed.
Not fixed. (unless anything explicitly announced.)

6.extra memory requirement
Extra memory doesn’t really needed.
Linked list stores bit extra memory due to the pointer that comes along at the end of its’ nodes.

7.space expansion
Can’t be extended or reduced.
Linked list is quite flexible in this case.

8.access timing
Same amount of time takes to access each element.


Different amount of time takes to access each element.

9.accessing point
Directly reachable to the exact element.
Have to go through all the nodes come on the way to go the certain node’s information.

10.movement requirement
Needs movement of elements for insertion and deletion.

No needed.
11. space requirement
Requires less space as only the information shall be stored.
Comparatively takes more space as the pointers are stored along with every information.