Category Archives: Algorithm

Bubble Sort

This video is good to help:

I have also taken help from DS Made Easy by Karumanchi book to find the algo pesudocode.

Pseudocode:

Implementation:

I need to improve this algorithm as it is not passing all the sizes of array so there will be some vacant position in array which increases the complexity in the running time so we need to out of the loop when it has nothing to swap, so our improvised algorithm will be:

Pseudocode:

 

Implementation:

This below video can help for better optimization that implemented in the above code:

Time Complexity in Running Time:

Worst Case: O(n^2)
BEst Case without improve: O(n^2)
Best Case(Improvised): O(n)
Average Case: O(n^2)
Space Complexity: O(1)
Simulation Tried to be drawn by me:

 

Selection Sort

PSeudoCode:

Implemented Code:

output:

 

QuickSort

Youtube Video:

Analaysis though it seems little bit tough to me:

HackerRank video:

MIT video:
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/lecture-4-quicksort-randomized-algorithms/

Pseudo Code from upper Youtube vid:

 

Implementation:

Slightly edited in *A to A[]:

Some change with before and after show:

Complete Quicksort Implementation and taking user input:

Output from the above code:

Geeks for geeks:
http://quiz.geeksforgeeks.org/quick-sort/
http://www.practice.geeksforgeeks.org/problem-page.php?pid=700151

From geeks for geeks but may be there might be some problems there

Another good one for understanding(I think it’s the best one):

Pseudocode available in the above video:

implemented code:

 

 


Quick Sorting in Process

Time and Space complexity: Best Case : omega(nlogn)
Worst case: O(n^2)

See this video to clear up the skills:

ideone example: http://ideone.com/oWbONR
Others Code:
http://www.cc.gatech.edu/classes/cs3158_98_fall/quicksort.html
Recursive:
http://www.algolist.net/Algorithms/Sorting/Quicksort
CLRS:
http://www.bowdoin.edu/~ltoma/teaching/cs231/fall09/Lectures/5-quicksort/quicksort.pdf

Google Search Terms:
https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1PRFC_enBD706BD706&ion=1&espv=2&ie=UTF-8#q=quick+sort+pseudocode&*

Stevie Hackerearth

code:

 

Basics of Implementation – Hackerearth

Vowel count in a string:
code:

Count Digit:

 

C++ Vector push_back()…pop_back()

Algo – Linked List

Best Video Explained:

code:

some bugs  here but understood the implementation:

 

Algorithm: Euler’s GCD


code:

more optimized:

 

Recursive:

 

http://www.progkriya.org/gyan/basic-number-theory.html#section3

Algo: Prime factorization of a number

code:

I/O:

 

Prime Number: Trial division | Prime check upto N in C

code:

Help can be find:
http://www.studystreet.com/c-program-print-prime-numbers/
http://www.codingalpha.com/prime-number-c-program/
https://en.wikipedia.org/wiki/Primality_test

Prime Finding: Sieve of Erastosthenes

I have watched the videos from mycodeschool and implemented it:
code:

Video:

Algo DS: Circular Queue

 

code:

Data Structure: Queue

Stack VS Queue difference:

 

code:

My implementation:

Another Video:

Code from the video Mycodeschool(Using circular queue):

 

Algorithm: BFS(Breadth First Search)

Theory:

http://scanftree.com/Data_Structure/Breadth-First-Search

Bangla:

গ্রাফ থিওরিতে হাতেখড়ি-৪(ব্রেডথ ফার্স্ট সার্চ)

Video:

code implementation:

Some other links may help:

Breadth First Search Algorithm

code:

Input:

Output:

Another code tried to write from the pseudocode is:

reference from java code: http://www.programmingboss.com/2014/06/breadth-first-search-bfs-in-java.html

ppt slide: https://drive.google.com/file/d/0B0sCkwd_qKgJSzZyUWVYZU5GWlk/edit

Fibonacci in C with Recursion

code from 1:

Code from 0:

 

Youtube source: