Data structure 1 - Array

One most basic and most popular data structure is array. It is so hard to find a programming language where there is no arrays defined.  Normally arrays can hold primitive data types such as ints, floats, booleans and such but you can create arrays to hold more complex user defined data types as well. In here the focus is not to show you how to create an array, how to insert an item to array and such. Those depends on the prog language you are using. More focus in here is to analyse the data structure and basic actions that can be performed on arrays.

So to have it formally start, array with n elements can have addresses ranging from 0th index to (n-1)th index. Thats it. :) And basically you can insert an item to an array, search for an item and delete an item from array. Here we will look an un-ordered array. We will look at ordered array data structure in a another example. This is because when it is ordered it has some certain advantages. ;)

No duplicates

You can insert duplicate data to an array.There is no problem with that. Lets see such a scenario.

Insert - you can insert your data item to next available space. 1 move.
Search - When you want to search a data item it can be at the first index. So 1 move. Worst case is it can be at the last index. So n moves. So depending on where it resides number of steps differs. So it is fair to say it takes n/2 moves on average for searching.
Delete - Before you search you have to first find it. And after deletion you have to restructure the array so that items from right side of the deleted item are moved 1 place left. So on average for search the item it takes n/2 moves.  So using the same logic it takes on average n/2 moves to restructure. 


With duplicates

Insert -  You can just insert an item to an array. no matter it is a duplicate or not. So 1 move.
Search - You cant just stop finding the first element that you are looking for. Because there can more of that in the array. So you will have to search fro the whole array to search a specific item. So n moves.
Delete - Just like no duplicates example logic, n moves to search. Then on average n/2 moves to restructure after deletion.   
Share:

Data structures and Algorithms overview

In order to proceed with DSA (Data structures and Algorithms) you have to have some basic programming background. It is not always the case. You  can learn the concepts of DSA prior to learning programming. But personally I do not recommend the latter. Just an personal opinion. Lets understand the things very simply. ;)


Data structure 

Normally in a computer program, no matter in what language you write it we need data to work with. These data can be variables (int x= 25, String firstName = "kalpa" , boolean isSignedIn = false) or data that we store in a database (may be in an xml file , database like mySQL or simply a text file). Amount of data and the complexity of data increase the with program scale and complexity. For example when you code a basic calculator you may need some ints doubles, floats. But when it comes to enterprise level real time banking mobile application nature of data differs. 

So not all the data are alike. These data has to be stored in some sort of manner in order to use it. Hence we need some kind of structure to hold on that data. (no matter the data is in variables or a database).





Simply saying you cant store eggs and oranges in the same manner. You need specific structures to each type. Read more about DS from here.

Algorithms

Well, the name seems cool mathematicy, cody and geeky. But in simple terms an algorithm is way of solving a problems. In day to day life we use algorithms all the time. For example when we want to tie our shoes we have certain way answering that problem. You take the shoe laces tie it in a certain fashion. VIOLA ! your shoe is laced. :D all the time, in every nook and corner in the world this algorithm is the same. 
Algoithm can be simple as this

or it can be complex as this. :D

Normally algorithms are kind complex. ;)

Algorithms can be used with data structure also.
  • To insert a new data item (Adding a new orange to the orange basket basket)
  • To search for a specific data item (search a specific orange from the basket. This may take some time depending in how you have strucutred your oranges)
  • To delete a data item (get an odd yellow colored orange and throw it to garbage can.)
For more on algos read some from here. 



Share:

Android Emulator not starting on ubuntu - Android studio

If you are using Android studio on ubuntu there are can be number of reasons why Android studio cant  start an instance of AVD. Emulator is a one needy insane bugger you always want to work with and you have to tolerate with.  Here the focus is on a specific issue of

"PANIC: HOME is defined but could not find TESTPHONE.ini file in $HOME\.android\avd
(Note: avd is searched in the order of $ANDROID_AVD_HOME,$ANDROID_SDK_HOME\.android\avd and $HOME\.android\avd)"

Normally what happens in Ubuntu is you either download Android Studio + Open JDK or Orcale JDK via bash or you download the zip files and install java and install Android-studio.

If java is there Android studio will work just fine. Most probably you will have to go to 
<Android-studio extracted location>/bin/   and ./studio.sh there. Most of the time you will do this as root.

If you have successfully installed Android in your system what it does is in your profile it makes a hidden directory called .android and your avd instance settings will be saved in a directory called avd and there you can find your your_test_avd.ini file

If you are root when you are installing android what happens in these .android/avd directories are created under root users folder and when you try to execute avd manager and start a avd as a normal users there are no .ini files in  <your profiile>/.android/avd.

There are 2 things that you can do to get it over with.

1. Copy /root/.android/avd content to $HOME/.android/avd. Just a matter of simple command and worked for me. :D

2. Before android search .ini files in $HOME/.android/avd it looks for environmental variables called 
$ANDROID_AVD_HOME. SO you can set its value to root/.android/avd. :) (y)



Share:

Sneak peak at Arduino platform


Just like I said. Arduino basically composed of two parts.

  1. 1. hardware (Arduino board)
  2. 2.software (The programs we write to Arduino)

Imagine Arduino is like a mother board of your computer. Each mother board has its form factor. Meaning each board is made according to a specification like these number of components should be there, these components should be placed there, these are the voltages to be used like that.
Well Arduino boards also has its own classifications.

Basically there are 5 hardware classes in which any Arduino board falls in.  These hardware are classed according to their functionality and specifications. So each class is used for specific tasks. Of course, you cant have simple LED blinking Arduino board to enterprise level highly complex robots. Can you ? :D
Each hardware class has Arduino models and here are the classes and some models.

Hardware class - Models - Functions

Basic - Uno, Leanardo - Most popular class. Good for experiments

Mega - Mega2560, MegaADK - Good for complex robots, More external device connections

Mini - MiniPro, Nano - Ideal for space utilization when building small robots

Breadboard - Boarduino - A solderless breadboard, Good for ever changing projects because you can attach parts anytime

Specialty - Lilypad, Fio, Ethernet - For specific application usages


This is some model comparison from Arduino site.
http://arduino.cc/en/Products.Compare

More on these components later. :D





These are some comparisons of Arduino models I`ve found on the web. Check them also.

http://www.robotshop.com/blog/en/arduino-microcontroller-feature-comparison-2-3631
https://learn.adafruit.com/adafruit-arduino-selection-guide/arduino-comparison-chart





Share:

Intro to Arduino



As a simplified version Arduino can be introduced to some novel people to hardware, micro controller, electronic,computer field as a mini computer. It is 100% not true. But lets just stick to it now. So just like a normal computer you have everything there. A memory, hard disk, usb connections, CPU like all of them.

But when it comes to micro controllers one thing not as normal computing is everything is micro-ed. :D. Meaning you have RAM but not as a large one like 4GB. You have only 2KB or so. You dont have 500GB hard disk. Instead you have 40 KB flash memory. Yeah , it may seem not enough. But when it comes to micro things like sensor works, robotics it is more than enough. :)

Micro Controller is a small computer like thingy which is embedded in an IC (Integrated Circuit). Lets just leave it at that. Arduino is a micro controlled platform where you can connect with external components like usb, sensors, motors. Arduino is an open source platform which was initiated by some Itallian fellows for an art project. You can read the history of Arduino in the wiki also. How ever now it has expanded its wings and now it can build robots also.

Arduino is piece of electronic junk with out its software .Arduino software is his soul mate. Together they live or without they die, in this case not function. You can plug your Arduino board to you computer, run Arduino software there and upload it to the Arduino board and viola. Arduino is live it can do stuff.  

You can get to know about more on Arduino from its official site and wiki.
Share:

New Android Studio


I think Google just made all the android tutorials related with eclipse that are available on the internet obsolete just like that with the launch of the android studio.

What is android studio ?

If you are familiar with android development with Eclipse IDE and ADT  (Android Development Tools) , new android studio is a replacement for the both IDE and ADT. The stable version of the studio was released in 8th December 2014 named version 1.0.1.

In the earliest versions we had download eclipse for Java and then install android development related components via android web site.

Then Google made it easier. After that there was a eclipse version bundled with android development tools (ADT). Of course after setting up needed SDKs and related components had to be downloaded. This was much easier than eralier version because there was a AVD manager and SDK manager already installed. We just had to download a SDK we like and create an AVD and start coding. For now I did my lot of coding with this version.

Now with android studio it is much much easier. No need to download SDK or create an AVD at all.Because the latest SDK that is Lollipop (API 21 ) is already with the android studio and a sample Nexsus AVD is already created. Now you just have to download and start coding. 


But not so fast. There comes the HAXM problem. See this post to check it out.

Whats new about it ?


This may be a personal experience. But when I opened Android Studio for the first time I was amazed and a bit frightened at the same time.

1. UI is much more nicer now. Thats good. But at the same time its not exactly like same old eclipse. You have to do some round of navigation to get it right.

2. AVD seems much light weight and performance wise that is ok too. (So far :p)

3. Good VCS support is there. Its says on the developer site. Haven't tested that yet.

4. New AVD manager is cool. It allows to create devices like TV,Tablets,mobile and even wearable device.

So those are the things so far. Havent done much of coding with studio as it has been like 2 weeks its released and  this is Christmas vacation. :p If you too know anything, lets share it via comments.

Happy coding. :D


Share:

What is MVC ???

So lets just dive right in. No **** talks. Just the things needed. :P

First and foremost I have to tell you this. Most of the things I explain here (at least Im trying to :p)
I learnt by my self. No other parties. Just me and the sweet old internet spending long hours with my poor baby laptop.

Unlike other stuff, When you try to understand something like MVC without any help from others, I`ve gotta tell you thats something tedious and that will probably make you wanna quit your life, literally. So one time I stopped learning this MVC thing. But you never give up anything in life and become quitter, DO ya ???. Now after like 2 years I have build CodeIgniter, OOP MVC framework apps and ASP.NET MVC 5 apps.

Bottom line is dont quit, you will get it eventually. :D


What is MVC?? 

"MVC is Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user." 
Thats Wikipedia right there :p
Ok.Lets make it simple as possible.

Imagine you are developing a large scale application.A web application. You cant do it alone because its gigantic. Lot of developers have to work together. And lot of languages have to be integrated. Interfaces have to be written in HTML,CSS,JavaScript. For databses you will have to use SQL. For application you may have to use, C# or Java or PHP or anyother programming language that is available.

So if you don't use these things carefully separated you will have to use all these languages and developers working in one place. You will make a quite tangled ugly mess out of it. :D
Imagine a source code where HTML,CSS,JS,PHP,SQL is there. Thats just 5 languages right there. Thats a developers nightmare.If you want to have a clean neat development process you need to separate these various elements.

Thats what MVC has done. Thats it. No big deal. 

Ok lets dive hard again.

M is for Model. All the Database related things will be done here. (SQL and programming language.(eg: JAVA))
V is for Views. All the user interface related things will be done here. (HTML,CSS,JS)
C is for Controller. All the application logic is written here. (Java or PHP or C# or Python or whatever prgramming language)

When we seperate things like this we have the following advantages.

1. Database logic and UI logic and application logic is not mixe up. Simply programming languages dont mix.

2. Database people can work on Models, UI guys can work on Views and Other developing guys can work on Controllers at the same time.
 Because it is separated.


But although  M and V and C is separated from each other, in order to application to run these things have to be linked together somehow.

This is how it is done.
For example lets say we want log on to facebook and this is what happens according to MVC.(This is just the simple version)

1.You enter www.facebook.com on your browser. (according to MVC you are requesting a view.  In other words a web page)
2.Your request will go to the facebook controller.
3.Controller will send you the requested login web page.
4.Now you have the Login page (a View). You can interact with the views.
5.So you enter you email and password in the view (web page) and sends it to application. (In this case your application is facebook)
6.This respond is sent to a Controller again.
7.And controller now knows this web page needs to have some sort of database things done.
8.So the controller connects to a Model.
9. Now the Models does all the database operation. (looks for a user in the DB with given email and password)
10.If there is a user with that login, Model sends these data to the controller.

11. Now controller sends the related web page to user with those details that was recived from the model.
12. VOLA.! now you have your facebook profile page.


Take notes on these.
# Users dont intearct with Controllers and Models. They can only interact with the views.
# Contoller can be the broker between Model and Views.
# Model is not a necesity for an application to work. You can make it work with a Controller and Views. But there is no point in having an application 
without a Database.Is there ???

Thats MVC ladies and gentleman. :D
Share: