Category Archives: ACM

Swap without a temp variable

It’s possible with addition:

It’s also possible with multiplication:

 

 

 

Source:
http://www.geeksforgeeks.org/swap-two-numbers-without-using-temporary-variable/

 

AVL Tree

B+ Tree

Floyd Warshall Algorithm

Bellman Ford

It works on negative cycle.

Implemented Code:

Time Complexity:

O([E].[V])

Reference:
http://cyberlingo.blogspot.com/2015/07/bellman-ford-algorithm.html

Dijkstra

output:

Complexity:
O(E+V^2)

We are using here adjacency matrix list

Topological Sort

code:

Output:

Time Complexity: O(V+E)
Space Complexity: O(V)
V for vertex E for edge

code courtesy:

Topological Sorting

I understood the theory but need to understand the code well later

HackerEarth: Batman and Tick-tack-toe

This is a basic implementaation problem but need to think critically and I used editorial + previous solved code to understand the logic

code:

 

Bucket Sort

Pseudocode:

Implemented Code:

output:

 

Tuts:

Reference:
CLRS: http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/bucketSort.htm

Bucket Sort

Harumanchi Book implementation:

output:

 

Time and Space complexity: O(n)

Radix Sort

best video:

pseudocode:

implementation: (I need to clear the radix sort part later..took help to implement)

Reference:

Radix Sort – Explanation, Pseudocode and Implementation

Time complexity: O(d*n)==O(n)
Where d is the digit of the number

Counting Sort

Algo:

Implemented Code:

 

Reference:
http://scanftree.com/Data_Structure/Counting-sort

Counting Sort in C

CLRS:
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/countingSort.htm

Tuts:

Complexity:
Time: O(k)+O(n)+O(k)+O(n)=O(n) if K=O(n)
Space: O(n)

Binary Search Tree: Successor in Inorder Traversal

code:

 

Delete a node in Binary Search Tree

code:

Traversal in Binary Search Tree

Height of a binary tree:

 

Level Order BFS in Binary Search Tree:

output:


DFS in Preorder, Inorder, Postorder:

output:

 

 

Binary Search Tree

youtube :

code: