WEET-IT Alpha version – Demo


it’s WEET-IT Again , as mentioned in the previous post WEET-IT  is a Semantic knowledge engine  based on semantic web and open linked data that supports different use cases like Question answering , Keyword search , Comparisons and Relations our project achieved very promising results compared to the benchmarks of “Aqua log” and “Freya”  projects – the top places projects in the QALD-1 workshop depending on their evaluation datasets .

this demo demonstrates the first Question answering algorithm  of weet-it as well as the comparison  and Relation algorithms .

the answers are Full profiles in case of one answer like “what is the capital of Egypt ? ” the answer would be one entity which is Cairo
the full profile will contain the full abstract description of the entity and the high ranked properties for that entity , similar related entities grabbed from the data graph

some answers would be a mini profile  , this is the case when the answer would be one entity or two , maybe three let’s say it’s a short description with one or two of the most relevant property to that entity

finally in case of keyword search when answers number is large we prefer to preview the micro profile which contains only the picture and a little part of the abstract .

some results would be comparison tables in case of queries like ” compare between messi and beckham ”

or relation graphs previewing relations between two entities or more like : ” what is the relation between messi , ronaldinho , xavi”  the answer most probably would be that they are fooballers , played for barcelona and other relations found in the graph .

enough of talking ,, here’s the demo : please watch in HD

we are searching for funding for hosting on larger servers and expansions issues , for interesting organizations| persons  you can contact any of the team members  @hadyelsahar @Ali_Hosny  @HatemMira @sherifkandeel @oafifi @eslamsamymeg
as well feedback , offers & interaction is very welcomed

WEET-IT the semantic knowledge engine , a 9 months story


9Months Ago .. i was still remembering all the talks about Semantic web and Web 3.0 .. all those definitions , some were true and some were false.

it was the time i was searching for a Graduation project lots of ideas were popping out and lots of fears of spending a year of work in a traditional thing.

i was proceeding my internship @ CMIC lab and in fact i felt my self annoying keeping asking every one about his opinion in some ideas that popped out in my head . hoping that in a way or anohter we could  get into an idea that seemed to be very cool.

after less than a month and more than a dozen of chats & meetings and more than hundreds of articles read , the idea was clear . it was a  Semantic search engine that is capable of answering Questions in a semantic way not by Text matching answers like most of traditional Search engines do. something the user could search in with terms like ” give me all android phones with capacitive touch ” or “what is the salary of cristiano ronaldo ”  or “presidential candidates in US presidential elections 2010 ”

the idea was a little vague and it’s domains of search were unclear and unknown ,  this  one day i was asking a Developer about some  keywords i could search about in the domain . then he told me an answer that seemed to be off the topic at the first time , however it was very helpful afterwards . ” why not searching in the domain of semantic web , it’s a fresh research domain that alot of people are searching in”  he said , i did a little research in semantic web at that time  , but that answer made me rethink of semantic web. a little time until i found that it’s a very promising domain with a millions of dumps of semantically annotated data , disambiguation handled  that makes  every project  tasks  easy for the researchers in the domain of data mining and information retrieval . This makes me think now it would be very nice for them to shift Into  semantic web , that would end their suffer from finding corpus free from noise  in multi languages or preprocessing dumps and categorizing them .

The idea became clear and we were  3 in the team and now came the time for finding a professor to accept this project as our graduation project , it was a tiring phase  we contacted literally  11 professors  , some were uninterested and others liked the idea but didn’t want to involve in something they have no background in , until came the day before the deadline of proposal submission that time , when a 12th professor of our contact list accepted the proposal and willingly wanted to mentor our idea .

After loads and loads of exploration,  we found some promising papers  done by a  professor named kaufmann and others related to a workshop for semantic web “QALD-1”  , We had an apartment and began development  , we made a process , we had our source controller bug tracker and a little server for hosting the database server .

I don’t remember the number of meetings we had  they were nearly every day for 10 hours  less or more a day , but I’m sure we exceeded  20 meetings a month .

Long story short , yesterday was the project defense , we were presenting  ” WEET-IT ”  (know – it )   our semantic knowledge engine , weet-it  handles  natural language queries in lots of domains  , letting the using ask  natural language free questions  for example like :

  • What is the birth place of barack obama  ?
  • What is the area of Egypt  ?
  • What are the countries that the river nile flows through ?
  • What is the profession of the wife of barack obama ?
  • What is the birth place of the children of hosni mubarak ?
  • What is the position of Messi ?

Previewing answers in form of profiles for the entities returned

As well as  questions that needs special visualization other than direct answers  like

  • Compare between Egypt and United states ?
  • What is the relation between Egypt and aboutreka ?

Our bench marks were very promising relatively to the evaluation of  “aqua log ” and ” FREYA ” the top question answering systems  in the QALD  workshops for semantic web

We believe that our results are  competitive to  EVI  the famous  Question answering application .

In the next days , we will be searching for fund for hosting on servers  as well as  some expansion and refinement

Our next steps would be adding more interesting statistics and datasets to our data base as well as exploration of new algorithms to enhance some search queries , aiming to handle subjective queries like   ” what is the best android phone with capacitive touch ”   or  ” tell me what people think of saddam hussien ? ”

” presidential candidates of Egypt ? ”  , previewing answers of charts and statistics elaborating people sentiment and reviews about those products and entities

ps : we are searching for funding for hosting on larger servers and expansions issues , for interesting organizations you can contact me   or any of the team members .

Building and Consuming Web services in Windows phone 7


this post doesn’t assume that u have any background on what the services is , so let’s start with a simple definitions

Service-oriented architecture :

simply it’s when your architecture is divided into separated components of code each one have it’s own functionality and they communicate together through a standard protocol of communication  , so these services or components can communicate interoperably also each component can serve multiple clients so it can be reused from different domains

Main benefits from SOA  

  • interoperability : for example a Java based project could use a .net based web service , because the use same communication standard
  • reuse : let’s assume a translator web service written once and could serve   millions of applications ( phone , desktop , web applications )
  • scalability  and agility : the same translator web service when i change in it’s functions or add new dictionaries or languages i don’t need to contact all the clients that use this service to rechange their code . i can just change the service and it’s changed in all clients because they don’t copy the code they only use the service . as long as i keep the same contract

WEB services : 

it’s a standard way for communication between web based applications in two  devices over a network (internet ) using XML , SOAP , WSDL  . XML is used to tag data and SOAP is the protocol of sending data  and WSDL is the web services describing language used to describe the available webservice . unlike normal web applications  WEBservices don’t need a browser also it doesn’t offer a GUI

web services examples :

  • bing search service
  • Microsoft translator service
  • IMDB service
  • AMAZON services
  • Twitter / Facebook services
  • Google API services

some drawbacks of WEBservices :

  • internet connection is required
  • transfer of large data across the internet may affects the performance

WCF services : 

a part of the .NET Framework that provides a unified programming model for rapidly building service-oriented applications that communicate across the web and the enterprise.


  • address : it’s the uri of the service or where you can find the service on the web
  • binding : Specifies how a service is accessible. In other words: how the two parties will communicate in terms of transport (HTTP , TCP ,NamedPipe , Peer2Peer ,MSMQ)
  • contract : it’s simply what the service can do  ( the data and methods that the service can provide )
and now comes the Fun Part

DEMO1 : Building a WCF service:

open microsoft visual studio and open a new project
from the open window choose C# , WCF  and from the left choose new WCF service
after creating the new project  you will find the project explorer file called IService.cs
which is the Interface the service  the “web contract”  mentioned before which contains all the methods and data variables
that the service offers
methods offered by the services their definition is written and  followed by [OperationContract]
to add a new method in the service  add the function definition in the Iservice.cs  file followed by [OperationContract]
and in the file  service1.cs  add the function code inside the service1 class that implements the Iservice1 interface   
now you can run the service this is the landing page of the created  service in which you can find the service address from the service url of written in the page

DEMO2 : Consuming a WCF service from Windows phone 7 :

this will be a sample demo on how to consume a webservice in windows phone 7

the only difference between normal consumption of webservices  in WP7 and in any normal application

is that in normal application the communication is synchronous  ( application calls web services and services responds in the same time to the application )   but in WP7 it’s asynchronous communication ( in which when windows phone calls the webservice the response in not in the same time but when the web service is done with the response it fires an event in the windows phone and we need to write in the event handler the code that needed to utilize the response ) don’t get confused with the above comparison , it will be elaborated in the code below

to consume a webservice , let’s take for an example microsoft translator web service which we can find on this link


the service uri  (adress) is : http://api.microsofttranslator.com/V2/Soap.svc

now open a new windows phone project

from the project explorer right click the project icon and add service reference

copy paste the service URL :  http://api.microsofttranslator.com/V2/Soap.svc   in the address field and click Go

then change the namespace to  TranslatorService for example  in which all the Generated code will be under this namespace

once you added a reference to the web service now you can create new object of the service client class this object you will use it to call all the methods of the service

so open the mainpage.xaml.cs file and let’s write some code

let’s assume that the program that we are writing will translate  the sentence in the textbox1   in french and show it in a text Block called textblock1 when we click a button called button1

from the toolbox drag  a textbox  textblock and a button  , it’s supposed to look like this  after changing the page title and subtitle and labels of the components

double click the button to handle the on click event

in the on click event  , initialize a new object from the service  by writing the following code :

        private void button1_Click(object sender, RoutedEventArgs e)
            TranslatorService.LanguageServiceClient myclient = new TranslatorService.LanguageServiceClient(); 


after this myclient object is the object that i’ll use to call all the service methods

now we are going to call the translateasync  function to translate  it takes appid , text , from , to , contenttype , category

you can create your own appid or just feel free to use my temp one i’d generated

you can see the function documentation in the service website

        private void button1_Click(object sender, RoutedEventArgs e)
            TranslatorService.LanguageServiceClient myclient = new TranslatorService.LanguageServiceClient();

            myclient.TranslateAsync("5F5CBEB15E4D9847AEB2C93B525EAC9B2A89465", textBox1.Text, "en", "fr", "text/plain", "general");

we know that when the service is done with the response  a translatecompleted  event will be fired so we will add to this event a new event handler  with arguments inside the <>  and  the function name to be executed between the ()

        private void button1_Click(object sender, RoutedEventArgs e)
            TranslatorService.LanguageServiceClient myclient = new TranslatorService.LanguageServiceClient();

            myclient.TranslateAsync("5F5CBEB15E4D9847AEB2C93B525EAC9B2A89465", textBox1.Text, "en", "fr", "text/plain", "general");

            myclient.TranslateCompleted += new EventHandler<TranslatorService.TranslateCompletedEventArgs>(translatecompleted);

  • <TranslatorService.TranslateCompletedEventArgs>  is the event args to be passed to the invoked function when executed 
  • tanslatecompleted is then name of the function to be executed  of the new event handler 

and we will add the function implementation in a separate function

        private void translatecompleted(object obj , TranslatorService.TranslateCompletedEventArgs e )

            textBlock1.Text = e.Result.ToString();


the object ” e ” of type  TranslatorService.TranslateCompletedEventArgs

contains the event arguments and it’s attribute Result contains the results of the invoked method in the webservice

which will be the translated text which then we will convert it to string and display it in the textblock1

the whole file would look like this :

now we are done let’s compile Run and try to see if there will be any bugs

now you are supposed to know:

  • what’s the SOA , and webservices , WCF services
  • how to build a WCF services
  • how to consume a web service in windows phone 7 applcations
imagine the unlimited number of applications that you can build and creative ideas you can generate depending on existing webservices that gives u a lot of capabilities
and always remember those available services when Generating ideas for WP7 applications
for any Questions or feedback don’t hesitate to ask me here or  on twitter @hadyelsahar 
and to keep updated with all Microsoft  similar Events  follow the hashtag #mspegypt and the twitteraccount   @mspegypt  on twitter  or our Fanpage

sorting algorithms #2


and we are back 🙂 , now let’s continue with  some other sorting algorithms  if you haven’t read part one of this Blog post you can  find it here  Sorting algorithms 

selection sort O(n^2)  : 

Selection sort worst case  \mathcal{}  n^2  average case  \mathcal{}  n^2  best case   \mathcal{}  n^2  disadvantages : it doesn’t ever benefit from presorted arrays 

lets start again with a stupid slow  sorting algorithm  , it’s the selection sort   it’s a very basic algorithm even more basic than bubble sort , it’s logic like when you have a bunch of numbers  and you want to sort them , you take the smallest one  , then the second smallest one , then the 3rd smallest one and so on .

and from here comes the naming  ( selection ) , and every time you have to loop on the array to decide the smallest item  (complexity O(n) ) and you repeat this n times in order to pick  n items ,   so the overall complexity will be O( n^2 )






why the selection turtle is dumber than the Bubble turtle  ?   

selection sort never takes benefit from  presorted arrays or even presorted elements every time it loops on the total array to decide the minimum rest element to pick it   so if we have a presorted array  which will be the best case 
the bubble sort  will sort it in  n iterations  , while Bubble sort will have complexity of  n^2 which makes it the dumbest ever 😀  


Quick Sort  : 

Quicksort  best case  : \mathcal{} n \log n   average case : \mathcal{} n \log n  worst case : \mathcal{} n^2







Quick sort  , who called it Quick ?    

 dunno . maybe it was the Quickest then ?  😀 

kidding 😀 , Quick sort is one of the most efficient algorithms  it has n^2  as a worst case but it often reaches it’s worst case it’s also faster than those  nlogn algorithms in practice 
 because its inner loop can be efficiently implemented by most architectures ( array , linked list ..etc ) 

actually : Quick sort also  competes with merge sort  ,  that Quick sort could be implemented on Linked lists  and as well as that it takes a little Memory utilization needed usually ( Log(n) )  unlike merge sort wich needs  (n) extra memory when using arrays 

let’s see how does Quick sort works : 

Quick  sort Algorithm :

it is from (divide and conquer algorithms , like the  Merge sort )

  1. Divide : using a pivot ( random number selected )
  2. sort  all the numbers less than the Pivot on  before it  
  3. sort all the numbers greater than the pivot after it 
  4. then you have two arrays one all it’s element smaller than the pivot and the other larger than the pivot 
  5. repeat all those steps recursively on the two arrays 

step  2  and  3  are done as following : 

*we use two pointers , one points to the top of the array  ,and the other at the bottom  and in the middle lies the pivot  move the left pointer until you find an element greater than the pivot ( it should to to the next side )

* on the other side move the right pointer until it hit a number less than the pivot  ( it should go to the next side )

*replace the two numbers

*  repeat those steps until you reach the pivot then the left array will become less than the pivot , and the right is more than the pivot

check this video it elaborates will the using of two pointers : 

 you can check this video for further demonstration  and some code snippets :



Heap Sort :

Heapsort  best case \mathcal{} {n \log n}  average case \mathcal{} {n \log n}  worst case \mathcal{} {n \log n}

this post is supposing that you have a pre-knowlege of what’s heap if you don’t , you can check this video  or this  

Heap sort is an efficient  kind  of  Selection sort  ( yeah the Dumbest one ever ) 😀 

How ? ? 

in selection sort we used to search for the smallest number in the array  so it was a complex algorithm of complexity n^2 

but in heaps you can easily search for elements inside it .  i needs number of iterations = height of the Tree = log(n) 

so it Gives an overall complexity of  O(nlog(n)) 

this is how it works 

  • Step 1: Build a heap
  • Step 2: removeMin()

the minimum item in the heap will be always the Root of the Heap so we will always remove it and reconstruct the heap again and it will be super easy when you are dealing with a Heap class that have remove Function

removing item from the heap

when you remove the root of the heap you and replace it with the last element in the heap

then you compare it with it’s two children , and replace the root with the minimum of it’s two children

then repeate those steps with the replaced item untill the root is smaller than it’s children

( if you don’t Get this , it’s recommended to revise the Heap removal )

the worst case here is when you compare the item to the Bottom element of the TREE , then you will do log(n) iterations

for removing n items you will have and overall complexity of O(nlog(n)) which is the complexity of the heap sort

comparing to the Selection sort (O(n^2)) it’s a Huge progress, although both based on the same logic


till now we are Done 🙂

yet let’s do some conclusions 😀
from different searching algorithms above and in the last post we found that

in the average case :

our three heroes will be the : Merge sort , Quick Sort , Heap sort

and our Loosers will be : the Bubble sort and the Selection sort and the insertion sort

in case of a preordered array :

the true heroes will be : the bubble and the Intersion sort for having a O(n) complexity

and the looser will be : the dumb turtle 😀 the Insertion sort

Finally that most of us before using the Algorithms was using the Bubble sorting algorithm to sort Arrays

so it once again will be the Hero as the Most Famous Sorting Algorithm 


DO IT yourself  😀 


those people who do folk  algorithmic dances watch their youtube channel 

those Guys are awesome 🙂

it’s the best practice now to watch their Dances and try to map them to what you’ve  learnt on different sorting algorithms

also follow their fanpage


and once again Credit Goes to :

  • MIT opencourse ware :  introduction to algorithms course , with charles and Eric  🙂  i recommend to watch the Full playlist  or take a look on  the full course with the slides and exercises  the from the MIT opencourseware website  here  thank you MIT 🙂
  • thanks to wikipedia for the Amazing animated Gif  images  🙂
  • Google for images of  Rabbits and Bunnies  😀

Sorting algorithms

1 Comment

why different sorting algorithms ?

why people are in need of different sorting algorithms ?

there are a lot of metrics to compare sorting algorithms on  like :

  • complexity ( usually it resembles the time taken in sorting ) in the best cases , worst cases & random cases as well  
  • memory usage < some sorting algorithms need to make a temporary locations to store data which needs more memory >
  • adaptability  < there are some sorting algorithms that benefits from the presorted elements even they have high complexity  > it’s not reasonable to resort millions of entries when one element only is not sorted 
let’s take a look how complexity could be a big deal : 
if we have 3 sorting algorithms  n , nlogn , n^2  
















 6 X 10^6  

  7 X 10^7 

  8 X 10^ 8  










if we used the 3 sorting algorithms above to sort 10^8 elements   :

if  the first algorithm of complexity n  took 27 hours  

the second one of complexity nlogn  will take 8 times the time above 222 hours  ,

But the third algorithm  could take about  325114 YEARS  !!!!!!!!! 

Complexity Chart

before Going through different sorting algorithms , i wanted to share a Funny Video that demonstrates 

3 different sorting algorithms 🙂 , it will ease explanation of them afterwards . 

Bubble sort  (  complexity O(n^2 ) ) : 

Bubble sort best case complexity \mathcal{} n  average case complexity \mathcal{} n^2 worst case complexity  \mathcal{} n^2 advantages :  Tiny code size  

it’s a simple sorting algorithm to write it’s code yet it’s  very complex algorithm , it could take days to sort few millions of elements

even  Obama Know this  😀 

it depends on 3  simple steps :

 repeat those 3 steps until the array is sorted : 

  1. loop on the array 
  2. compare each to consecutive elements , and switch them if they are not sorted 
  3. go to step 1   

watch this video , it explains  a lot  ( you can skip the other kind of sorting ) 

you can check it’s code 

void bubbleSort (Array S, length n) {
 boolean isSorted = true ; 

while(!isSorted) { // repeat until it's sorted isSorted = true; 
for(i = 0; i<n-1; i++) { // step one loop on the elements 

if(S[i] > S[i+1]) // compare each two consecutive elements 
int temp = S[i];
S[i] = S[i+1]; 
S[i+1] = temp ; 

isSorted = false; // if all elements are sorted the flag wont change 

the best case here is when the array is already sorted or  consecutive elements are only unsorted  so it will be sorted by one while  loop only so it has complexity  

the worst case  here will occur if the array is reversed  , you will need to loop in the while loop for n times so it’s complexity will be n^2

insertion sort  (O(n^2)) : 

Insertion sort best case  \mathcal{}  n  average case  \mathcal{}  n^2  worst case   \mathcal{}  n^2

so it’s a  basic algorithm like sorting a pile of cards ,from left to right  you pick a card and insert in into the right place then the preceding another card  and so on till the pile is sorted

take a look on this video

yet another way of stupid slow sorting  algorithm 😀   the only difference than before is that Obama forgot to mention it  kidding 😀

actually insertion sort is faster than bubble sort when dealing with presorted elements in the array  , how ??

imagine you are handling the element that already in sorted in it’s place ,

all that you need it to compare it to the largest element in the left sorted array to recognize it’s bigger than it and it’s in the right place

Merge sort  ( O(nlog(n))  ):

Merge sort Best case  n log (n)  average case  n log (n)  worst case  n log (n)  advantages : too fast compared to n^2 complexity

it’s considered as a fast search algorithm and least complexity , it  depends on a basic rule , is that sorting and merging small arrays is too much faster than sorting large array .

it uses 3 basic rules :

  • arrays of one element only are already sorted
  • divide any array into two halves and so on till you have  n arrays  each of one element
  • merging each two consecutive arrays  in order //  so if we need to merge those two arrays in figure we will need to compare the first elements in each array then drop down the smaller into the new array

then compare the next two selected elements  and so on till the whole array is merged

take a look on this video :

so why it has complexity of  nlog(n) ??? :

 each level   consists of n elements  ,  merging depends on comparison of each to elements  so merging each  level will have complexity of  O(n)   and since we have  log(n) levels  , so merging will be repeated log(n) times
over all we will have complexity of  O(nlog(n)) .

…to be continued with more Sorting algorithms  ( quick sort , selection sort , heap sort , BST sort  )  =)

click here for part two 

thanks goes to :

NameSpaces “using namespace std “

Leave a comment

actually most of us when beginning to write a C++ code for example we write

using namespace std ;

but most of us doesn’t recognize what does that mean and what’s the Namespace  so this topic basically will talk about namespaces

what’s the NAMESPACE :

it’s and entity that can group inside it a number of classes , object and functions . it’s name is divided into two section ” name ” , ” space ” so actually it’s a space designed for the name of the variable , to prevent the collision of names , suppose you have a function called connect ()  and you want to make a newer version of it inside the same File , and you don’t want to go through alot of naming Connect_new , Connect_newer  …etc so we assign a namespace for  each one

to access elements inside the name space we need to use the operator  ” :: ”  ;

for example

namespace  mynamespace
int x , y ;
void main () {
mynamespace::x ;
mynamespace::y ;

multiple name spaces in the same file :

more things that make naming collision :

if you are including two header files, those header files have a common function naming inside it which function will get  executed when called ?  acutally nothing will get executed and and error appears calling

 error C2084: function 'connect()' already has a body

the using operator :

using operator is a keyword that introduces a certain namespace to a specific region so when you write

using namespace mynamespace  ;

you can call connect function without using the operator ::

mynamespace::connect () ;
using namespace mynamespace ;
connect() ;    // it should work now  =)

Namespace STD :

all standard libraries inside C++ standard library lies in the name space std , so we  always write the name space std to call the attributes at once  instead of writing

std::cout<<"hellow world " ;
std::cin>> x ;
using namespace std ;
cout <<"now no need to use std:: " ;

that’s it , this is acutally every thing about the explanation of ” using namespace std ; ” for any further questions  don’t hesitate to ask here or DM me  i always check my DMs  @hadyelsahar

Linked Lists in C++

Leave a comment

First of all :

working with linked lists requires a good knowledge about pointers so if you still finding pointers is a hard topic you can practice out this topic
linked listsLinked lists are type of data structures :

In computer science, a linked list (or more clearly, “singly-linked list”) is a data structure that consists of a sequence of nodes each of which contains a reference (i.e., a link) to the next node in the sequence.

source :wikipedia

so the linked list is a type of datastructure that can stand alone or used to create other data structures it consists of Nodes and each node has the reference to the next node ie : “linked to it ”  until the final node where it doesn’t have anything to point to

you can Create a linked list using Classes or Structures but we are using structure and may it be a good thing just to remember how to deal with structures

here’s a little example about how to initialize a Linked list Item and fill any of it’s data

#include <iostream>
#include <string>
using namespace std ;

 struct  listItem {
 string  name  ;  // name of the item 
listItem * next ;  // pointer points to the next node 
 } ;

void main (){
listItem * head ; // pointer will always points on the first node
listItem * myListItem ;   // creating a new instant from ListItem  
myListItem.name = " Greetings Egyptian Geeks "  ; //filling it's data 
cout << myListItem.name ;
head = &myListItem ;  // making the pointer to the adress of the First Item

download from here

simple enough !! , it’s a normal Structure  ,  So let’s Move to the NEW part !

Adding New Item to the beginning of the LinkedList

listItem   myListItem2 ;   // creating a new instant from ListItem 
 myListItem2.name = " add me to the beginnning  "  ; //filling it's data 

 myListItem2.next = head ; // making it point to the Next item -that was first- 

 head = & myListItem2 ;  // making the Head pointer points to the new head one

Adding new element to the End

mylastListItem.Next = &newLastItem ;

Addin new element in the Middle

we have two list items listitem1 and listitem2 we want to put middleListItem in the middle we create a new temp pointer to save the adress of listitem2 in it  – as we can’t access it unless by  listitem1.next

temp = listitem1.next ;
listitem1.next = & middleListItem ;
middlelistItem.next = temp ;

Delete elements after a specific number of nodes (n):

temp = head ;
For( i =0 ; i< n ; i++ )
temp = temp->next ;  //  hint : there's no something called *temp.next
temp = Null ;  // we usually check Temp.next = null then this is the final node

of course this topic doesn’t cover all the operations done on the linked lists , it’s all about the concept but other operations don’t contain any new concepts it’s a Mix between conditions and Pointers

for any suggestions or adds , feel free to post below  or DM me on twitter @hadyelsahar i do always check my DMs

Vectors ,the Dynamic Arrays “D & A episode #2 ”

Leave a comment

what’s a vector ?

simply not precisely we can say that the vector is a Dynamic array of variables, struct or objects in which you Insert data at the end ; and this shows a Great difference with arrays in which arrays was created with a fixed size , this is simply why would we use a vector

declaring vectors :

  • vector <int> myvector ;   >> declaring an empty vector of integers
  • vector <float > myvector (5)  >> declaring a vector of  floats having 5 spaces
  • vector <int> myvector (10,1) >> declaring a vector of  integers having 10 spaces all initialized with value 1

Accessing elements in a vectors :

we will focus on two ways to access elements inside the vector

the normal method ” indexing ” []  :

each element in the vector has an index beginning with index 0 for the first element  1 for the second and …etc till the final element and we use  square brackets to write the index inside it

myvector[1] ; // to select the second element
myvector[n-1] ; // to select the final element among n elements

the function   at ()   :

the vector class has a member method called at()  it takes the index of the element and returns the element having this element

myvector.at(1) ;  // to index the second element in the vector 

Are both  the same ? :

actually no  because in the first method  no index range checking happens in the standard library’s vector so an access out of  the array  index bounds is not caught by the compiler for example

vector<int> myvector(5,1) ; cout<< myvector[6] ;

this might be caught by compiler as an error and might not , maybe rubbish is printed

(Range check- ing can be done by using at method ;

ie : myvector.at ( i  )  is the same as a  [  i  ] ,  except that an exception is thrown  if  i  is out-of-bounds

How to fill  a vector :

dealing with vectors is the same as dealing with arrays so to fill a certain element in a vector you say
myvector[5] = 13 ;

Inserting and Deleting Elements inside the vector :

  • push_back() method is used to insert a new row in the vector  // it takes the value of the row as an argument  ex : myvector.push_back(15) ;

  • pop_back() method is used to remove the last row in the vector

click the image for larger view


Getting the size of  a vector  & changing it :

  • size() method is used to return the size of the vector = the number of elements in the vector
  • resize () takes two arguments  the new size as and the value of the new added elements  , if you didn’t add the second argument the new elements will have a value of zero by default

Getting Started with Jquery Ajax #1

Leave a comment

if you don’t already know what’s AJAX you can check my previous post about : what’s AJAX ?

Starting Jquery AJAX

jquery framework , offers an easy ways to make AJAX calls , alot easier than normal Javascript AJAX

1. “$.get” to handle Get request :

beginning with  some HTML to apply AJAX on  write this in a file called index.html

<button id="ajaxButton">Click me </button>
<div id = "datahere" style="width:200px; height:200px; background-color:Blue ; ">

make a php Page and call it default.php  , containing this code the response of the PHP page is a Text Box

<?php  echo"<input type="text" /> ; ?>

now to the Jquery Part in the file index.html

$(document).ready(function () {  
  $("#ajaxButton").click(function () {              
     $.get("default.php", function (data) {        
       alert(" request is sent sucessfully ");          
  • . ready is used to execute the code below after the document is Ready
  • attaching a click event on the button
  • $.get  takes two arguments -till now-

  1. the link to the server page to which the request will be sent
  2. call back function executed after the response comes  this call back function takes an argument called data which contains , the response of the server page  (ie : data variable is a string contains the response -the text box in this case – )
  • $(“datahere”).html(data);   // to load the write into the DIV

BY EXECUTION , THE TEXT box will appear inside the Blue box









till now you can download the Source Files from here : download the source code #1

NEXT PHASE , Sending data in the AJAX Request :

changing alittle bit to the Javascript :

$(document).ready(function () {  
  $("#ajaxButton").click(function () {              
     $.get("default.php",{"name":"hady","age":"20"} , function (data) {        
       alert(" request is sent sucessfully ");          

and changing the PHP code

echo "name is".$_GET['name']."<br/> age is : ".$_GET['age'] ;
 ; ?>
  • now we noticed here is that the $.get function takes a middle argument which is a JSON object
  • we can get the value of the sent Json attributes by function  $_GET[”the name of the attribute”] in the PHP code lines

the output will be like this :









you can download the code lines till now from here : download the source code #2

2. “$.POST” to handle POST request :

actually $.post is simillar to $.get  in everything so no need for repetition  the only difference it it’s responsible for post request to the server and $.get is responsible for the get request

if you don’t know the difference between post and get check this link .

those are not all the Jquery methods to send an AJAX request  acutally there are others that ease sending and requesting of a special kind of data ( JSON , FORM , Javascript …etc )

more will be Explained in Next posts so Stay tuned

What’s AJAX ?

1 Comment


it’s shorthand to ” Asynchronous JavaScript and XML ”

Historical Background :

in the early web stages , websites where all HTML based so any small change in the content of the web page needs the webpage to be all reloaded , this SUCKS  and adds loads to the bandwidth and the server , after Java applets are introduced , an asynchronous data reloading was available also Microsoft introduced in internet explorer 5 the  XMLHTTP control  then later on google deployed the AJAX when it used it in GMAIL and GOOGLE maps

check this out when Ajax what introduced to the public Ajax: A New Approach to Web Applications


src : http://www.adaptivepath.com/ideas/essays/archives/000385.php

AJAX Main achievements :

the transfer of data between servers and browsers became asynchronous no need to reload the page for each single change in the page ; you can find something like  suggested links in search Engines  , Google and Bing instance ,

however XML is not the only used for data interfered  often JSON or although other formats such as preformatted HTML or plain text can also be used.instead .

some Drawbacks :

  • clicked links are not saved into the browser history also it’s difficult to bookmark certain page at a certain position , because the pages changes without changing the URL of the main page so if you are building an Ajax gallery for example you can’t bookmark a single page , or go back or forward but alot of developers are Creating techniques to over come this , as by using the Hash Object


Ajax frameworks:

Ajax Frame works are  frame works Built to help users to Develop ajax applications Easily AJAX has different Frame works in different languages

  • Javascript AJAX  frameworks : like Jquery , MooTools , dojo toolkit , ASP.net AJAX
  • JAVA Frameworks for server side AJAX :  Google webkit , BackBase , Apache webkit
  • C++ : wt  webkit
  • ASP.NET AJAX : Microsoft Atlas formerly
  • Pyjamas , a widget library with a Python to JavaScript compiler





Older Entries