Monthly Archives: March 2016

Data Structures 04

BINARY TREE

binarytree

Picture1 <skewed Binary tree

  • Node at the top is called as root.
  • A line connecting the parent to the child is edge.
  • Nodes that do not have children are called leaf.
  • Nodes that have the same parent are called sibling.
  • Degree of node is the total sub tree of the node.
  • Height/Depth is the maximum degree of nodes in a tree.
  • If there is a line that connects p to q, then p is called the ancestor of q, and q is a descendant of p.

 

  • Binary tree is a rooted tree data structure in which each node has at most two children.

There are 4 types of Binary Tree:

  • Perfect Binary Tree
  • Complete Binary Tree
  • Skewed Binary Tree and
  • Balanced Binary Tree

 

  • Each Node of a binary tree has a maximum of 2 childs.MeMzS

Perfect :

  • This Binary Tree has the same depth for every level

Complete:

  • This Binary Tree is almost perfect except the last level.
  • Perfect Binary tree is also a Complete Binary tree

Skewed :

  • Every level only has one node.

Balanced :

  • binary tree in which no leaf is much farther away from the root than any other leaf (different balancing scheme allows different definitions of “much farther”).

Properties of Binary Tree

  • Every level of the binary tree, has its own maximum nodes.
  • Those levels start from 0.
  • In level 0, maximum 1 node.
  • In level k, maximum 2^k nodes.

How to count the maximum nodes in a tree according to its height:

height -> 2^(h+1) – 1

Maximum nodes in binary tree of height 3 is

2^4 – 1 = 15

Maximum height = n-1

Minimum height = 2log(n)

Sources : Binus University

Data Structures 03

Today we are talking about: LINKED LIST IMPLEMENTATION

Linked List

  • there are 2 types of linked list; they are Stack (LIFO) and Queue (FIFO).
  • push and pop are linked list functions that are used when adding and clearing datas, push for adding a data, pop for clearing or delete a data.
  • there are single and double linked list.

What are the differences between stack and queue?

  • Stack:
    • First in, last out
    • Last in, first out
  • Queue:
    • First in, first out
    • Last in, last out
    • there is a queue called priority Queue = first in not always first out according to the prioritiness.

Push and Pop

  • Push – is also called enstack in stack and enqueue in queue is for adding datas into the linked list.
  • Pop – is also called destack in stack and dequeue in queue is for delete datas in the linked list.

Single and Double Linked List

  • Single
    • single linked list is a one direction linked list, it only goes to one next either right or left according to the programmer
  • Double
    • Double linked list is a 2 direction linked list, it has a next and a prev, meaning it will be easier to add data in anywhere.

INFIX, POSTFIX, AND PREFIX NOTATION

  • Infix notation (commonly used) usually we used it in maths equation
  • Prefix notation, also known as Reverse Polish notation.
  • Postfix notation, also known as Polish notation.

Infix: operator is written between operands example 3+12

Prefix: operator is written before operands example + 3 12

Postfix: operator is written after operands example 3 12 +

Why must prefix and postfix exist?

  • Prefix and postfix notations dont need brackets to prioritize operator precedence.
  • Prefix and postfix is much easier for computer to evaluate.

SEARCHING

  • Deep First Search : searching to the deepest data first then just going up
  • Breadth First Search : searching side to side.

CLOUD and BIG DATA

Data Structures 02

Guest:  Pak Bong Defendy, Binusian 2007

Topics:

  • Big Data (Structured & Unstructured)
  • Cloud Platform

Cloud Platform:

  • Cloud uses 2 centers to store datas: Data Center and Data Recovery Center.
  • Data Center is used to store new datas from customers/users.
  • Data Recovery Center is used to prevent in missing or corrupted datas.
  • Cloud Platform is a platform for cloud computing.

Cloud Computing

Cloud Computing

  • is a kind of Internet-based computing that provides shared processing resources and data to computers and other devices on demand.
  • Every data we have can be stored in cloud storages that will be stored in a Data Center.
  • Microsoft Azure and Google Cloud Platform are the examples of Cloud. The nearest Microsoft’s data center is at Singapore.
  • Cloud computing has become a highly demanded service or utility due to the advantages of high computing power, cheap cost of services, high performance, scalability, accessibility as well as availability.

Disadvantages of Cloud Computing

  • DOWNTIME :

This may be one of the worst disadvantages of cloud computing. No cloud provider, even the very best, would claim immunity to service outages. Cloud computing systems are internet based, which means your access is fully dependent on your Internet connection.

  • SECURITY AND PRIVACY :

Any discussion involving data must address security and privacy, especially when it comes to managing sensitive data. We mustn’t forget code space and what happened to it after its AWS EC2 console was hacked and its data eventually deleted, forcing the company to close doors forever. Of course, your cloud service provider is expected to manage and safeguard the underlying hardware infrastructure of a deployment, however remote access is your responsibility and, in any case, no system is perfectly secure. You’ll have to carefully weigh all the risk scenarios.

  • Etc

Advantages of Cloud Computing

  • Flexible
  • Disaster Recovery
  • Work from ANYWHERE
  • Etc

BIG DATA

bd11

  • Big datais a term for data sets that are so large or complex that traditional data processing applications are inadequate. Challenges include analysis, capture, data curation, search, sharing, storage, transfer, visualization, querying and information privacy.
  • Big Data are growing rapidly in part because they are increasingly gathered by cheap and numerous information-sensingmobile devices, aerial (remote sensing), software logs, cameras, microphones, radio-frequency identification (RFID) readers and wireless sensor networks.
  • Big Data has structured and unstructured data, every data connects to each other.
  • Big data usually includes data sets with sizes beyond the ability of commonly used software tools to capture, curate, manage, and process data within a tolerable elapsed time.

 

 

 

Data Structures 01

Pointer, Array and Introduction to Data Structures

  • Array: stores data in consecutive memory locations and are referenced by index. It is more efficient then storing manually. Index always starts from 0.

In example:

Program manually stored without array:

#include <stdio.h>

main()
{
   int  number1;
   int  number2;
   int  number3;
   int  number4;
   int  number5;
   
   number1 = 10;      
   number2 = 20;   
   number3 = 30;   
   number4 = 40; 
   number5 = 50;     

   printf( "number1: %d\n", number1);
   printf( "number2: %d\n", number2);
   printf( "number3: %d\n", number3);
   printf( "number4: %d\n", number4);
   printf( "number5: %d\n", number5);
}

Program using array: 

#include <stdio.h>
 
int main ()
{
   int number[10]; /* number is an array of 10 integers */
   int i = 0;
 
   /* Initialize elements of array n to 0 */         
   while( i < 10 )
   {
      /* Set element at location i to i + 100 */
      number[ i ] = i + 100;
      i = i + 1;
   }
   
   /* Output each array element's value */
   i = 0;
   while( i < 10 )
   {
      printf("number[%d] = %d\n", i, number[i] );
      i = i + 1;
   }
 
   return 0;
}

There are some operation that can be performed in arrays :

  • Traversal
  • Insertion
  • Sorting
  • Searching
  • Deletion
  • Merging

Pointer: is a programming language object, whose value refers to (or “points to”) another value stored elsewhere in the computer memory using its address

2 symbols in pointer:

&: Address Operator

*: Deferencing Operator

Using Pointer:

in example a declaration:

  1. int x;
  2. int*p = &x;

So there is an integer x, and a pointer p. P took a value from an integer that is pointed. In this case P is pointed to x’s address. In conclusion, the value of x will be also the value of pointer P.

If we declare that x=10; or we can write *p = 10;

then *p and x has a value of 10.

Data Structure:

  • A data structure is an arrangement of data, either in the computer’s memory or on the disk storage
  • is a particular way of organizing data in a computer so that it can be used efficiently

Here are some examples of data structures:

  • Arrays
  • Linked Lists
  • Queues
  • Stacks
  • Binary Trees
  • Hash Tables

Linked Lists:

  • is a linear collection of data elements, called nodes pointing to the next node by means of pointer
  • Each element is called a node
  • is a data structure that consists of a sequence of data records such that each record there is a field that contains a reference to the next record in the sequence
  • Linked lists are the best and simplest example of a dynamic data structure that uses pointers for its implementation
  • Linked lists have a few advantages over arrays:
    1. Items can be added or removed from the middle of the list
    2. There is no need to define an initial size

    However, linked lists also have a few disadvantages:

    1. There is no “random” access – it is impossible to reach the nth item in the array without first iterating over all items up until that item. This means we have to start from the beginning of the list and count how many times we advance in the list until we get to the desired item.
    2. Dynamic memory allocation and pointers are required, which complicates the code and increases the risk of memory leaks and segment faults.
    3. Linked lists have a much larger overhead over arrays, since linked list items are dynamically allocated (which is less efficient in memory usage) and each item in the list also must store an additional pointer.

The pointer always points to the next member of the list. If the pointer is NULL, then it is the last node in the list.

A linked list is held using a local pointer variable which points to the first item of the list. If that pointer is also NULL, then the list is considered to be empty.

Queue:

  • is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position
  • The elements in a queue are added at one end called the rear and removed from the other end called the front

Binary Trees:

  • is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
  • data structure which is defined as a collection of elements called the nodes
  • Every node contains a left pointer, a right pointer, and a data element

Abstract Data Types:

  • is a mathematical model for data types where a data type is defined by its behavior (semantics) from the point of view of a user of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations.
  • C/C++ has a concept called class and struct which assist the programmer in implementing abstract data type.
  • For example, integers are an ADT, defined as the values …, −2, −1, 0, 1, 2, …, and by the operations of addition, subtraction, multiplication, and division, together with greater than, less than, etc., which behave according to familiar mathematics (with care for integer division), independently of how the integers are represented by the computer.

Talking about Structure:

  • Structure
  • Nested Structure
  • and Array of Struct

Example of a Structure:

struct x{

int x;

char b;

};

x data;

x is a data type like integer and float, and data is the variable.

Example of a Nested Structure:

There is a struct inside a struct.

struct profile {

int   age;

char  name[100];

};

struct student {

struct profile p;

int  score;

char grade;

};

student x;

x.score = 92;

x.grade = ‘A’;

x.p.age = 20;

strcpy(x.p.name,”budi”);

Example of Array of Structure:

struct profile {

int   age;

char  name[100];

};

struct student {

struct profile p;

int  score;

char grade;

};

student arr[10];

arr[0].score = 92;

arr[0].grade = ‘A’;

arr[0].p.age = 20;

strcpy(arr[0].p.name,”budi”);

arr[1].score = 83;

arr[1].grade = ‘b’;

arr[1].p.age = 19;

strcpy(arr[1].p.name,”chandra”);