/* Ajith - Syntax Higlighter - End ----------------------------------------------- */

## 3.16.2013

Flashback

Long Long ago when INTERNET is booming up with so many websites its really hard to follow the interesting one. Its quite clumsy to go around miliions of sites to check for new posts.

Am I Doomed ?

## 3.14.2013

### Divide a number by 3 without using any arithmetic operators

How to divide a number by 3 without using + - / * %

NOTE: I am just trying to collect various answers down in this post available across multiple sites in internet as mentioned in references.

Solution 01:
```#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fp=fopen("temp.dat","w+b");
int number=12346;
int divisor=3;
char *buf = calloc(number,1);
fwrite(buf,number,1,fp);
rewind(fp);
printf("%d / %d = %d", number, divisor, result);
free(buf);
fclose(fp);
return 0;
}```

## 12.25.2012

### Deleting a Node from a Singly Linked List

Previous Article: Implementation of Singly Linked List.
Next Article: Reversing a Singly Linked List

Deletion of a Node from a Singly Linked List
Similar to insertion we have three cases for deleting a Node from a Singly Linked List.

• Deleting First Node in Singly Linked List

To complete deletion of firstNode in the list we have to change Head pointing to Next of firstNode.

Pseudocode:
```firstNode = Head

free firstNode```
Complexity:
Time Complexity: O(1)
Space Complexity: O(1)

### Detecting First Node in a Loop in the List

Previous Article: Detecting a Loop in Singly Linked List - Tortoise and Hare.
Next Article: Finding Nth node from end of a Singly Linked List.

Once we confirm that there is a Loop in a Singly Linked List we will see how to determine first node of the loop.

## 11.14.2012

### Finding Nth node from end of a Singly Linked List

Previous Article: Finding first node in a Loop in Singly Linked List.

Solution 01 - Brute Force Approach:
1. Start at First Node of the List (call it curNodePtr).
2. Assign curNodePtr to tmpPtr and count number of nodes after the curNodePtr.
3. If number of nodes after curNodePtr are equal to N nodes or tmpPtr reaches END then break. If tmPtr reaches END but count not equal to N then return since we can't find the Nth node from the end of the Singly Linked List.
4. Move the curNodePtr one step forward in the Linked List i.e curNodePtr now points to its next node in the list and start again from STEP-2.

## 11.07.2012

### Reversing a Singly Linked List

Previous Article: Deleting a Node from a Singly Linked List.
Next Article: Detecting a Loop in Singly Linked List - Tortoise and Hare.

Let us see how to reverse a Singly Linked List.

Pseudocode:
```cur_ptr = HEAD->NEXT
prev_ptr = NULL

forever:

if cur_ptr == NULL
break

tmp_ptr  = prev_ptr
prev_ptr = cur_ptr
cur_ptr  = cur_ptr->NEXT

prev_ptr->NEXT = tmp_ptr

Complexity:
Time Complexity: O(n)
Space Complexity: O(3)

If we try on the example in Figure-1 we get the output as shown below

 Figure-2: After reversing the Singly Linked List

Previous Article: Deleting a Node from a Singly Linked List.
Next Article: Detecting a Loop in Singly Linked List - Tortoise and Hare.

## 9.22.2012

### Detecting a Loop in Singly Linked List - Tortoise & Hare

Previous Article: Reversing a Singly Linked List.
Next Article: Finding first node in a Loop in Singly Linked List.

Floyd's Cycle-Finding Algorithm
In simple terms it is also known as "Tortoise and Hare Algorithm" or "Floyd's Cycle Detection Algorithm" named after its inventor Robert Floyd. It is one of the simple cycle detection algorithm. It's a simple pointers based approach.

 Robert Floyd