Wednesday 30 October 2013

Linked Lists and their efficiency


Aren't Python lists just based on arrays that consist of contiguous chunks of memory? But what if they didn't have to be contiguous ? What if we just want to add new elements into the memory without having to change the location of others ?

Now we can introduce a new data structure called Linked Lists which is simply a chain of connected nodes where each node contains a data field and a next field which points to the next node in the list. How do we reach to the end of the list ? We traverse the list by following each node's next pointer until we reach the end of our linked list. In most cases we have access to the first node which is called the head.

Adding and removing from Linked Lists
Adding a node replaces the last node reference to the new node that's being added and makes our old last node point to the new node as the next node in the list.
Deleting a node is a process that iterates the list looking for the node and and we look around the deleted node to make sure that the previous node now points to the following node as its next node.

Linked list efficiency:
Most operations that we apply to either end of our linked list do not depend on the size of the list but only one operation does which is removing from the end of the list .
Why ?!
Because removing from the end of the list requires a full traversal since we can't obtain our new tail just from tail.



Saturday 19 October 2013

Difference between abstraction and encapsulation

After introducing the concept of Object Oriented Programming and its main parts, lets compare and contrast abstraction and encapsulation :

Abstraction :

  • Solves our problem using an outer shell in terms of  "design"
  • Its used to hide the unwanted and un relevant data from the user.
  • Focuses more on what the object actually does rather on how it does it.
  • Example : The display of a touch screen.
Encapsulation:

  • Solves our problem in the implementation level instead.
  • It is used to hide the code and data into one single unit and hide it from the external world.
  • Focuses on hiding the internal details and mechanics of an object, i.e. how the object does it.
  • Example : How the display screen is connected with dialling option using circuits.


Monday 14 October 2013

Object Oriented Programming

Usually , for us computer scientists programs are organized around the idea of action and logic but Object Oriented Programming is a programming model that organizes them around objects and data.
How is that possible ?
Well , OOP allows decomposition of a problem into a number of entities called Object and then builds data and function around these objects and these objects can only be accessed by the functions associated with it. A class however is a blueprint for an object that contains variables for storing data and functions to performing operations on these data.
There are three main concepts to the understanding of the concept of object oriented programming :
1) Encapsulation
2) Abstraction
3) Inheritance
We will explain briefly each concept putting in mind that all languages that support OOP will support these three concepts.
 Encapsulation:

Wrapping up data member and method together into a single unit (e.g..class)  is called Encapsulation.
Encapsulation is like enclosing in a capsule. That is enclosing the related operations and data related to an object into that object. Encapsulation is hiding internal details of the object i.e it doesn't care how the object does something as long as it does it !!
Abstraction:

Abstraction lets you focus on what the object does instead of how it does it. It is the process of hiding the working style of an object, and showing the information of an object in an understandable manner.
Inheritance:
Inheritance is the process of reusing objects and its methods. Its how classes can acquire property from other "parent" classes.

Summary 
Unlike Structured Programming Languages, in which programs are designed with collections of functions that are called in different parts of the program, more like a script or job list , OOP programs are designed with the concept of objects, where each object contains its own set of variables and functions.