Posts

Showing posts from March, 2017

Animation for String search - KMP Algorithm

This is a beautiful and interactive animation to understand how KMP Algorithm works. Mix and match with different inputs and give a try. Failure Function: Represents function to lookup if there is a mismatch in pattern and txt strings. Search Button: Represents how search works . Animation for KMP Algorithm Credits & Copyright to : This is an embedded link from http://www.cs.usfca.edu/ . Credits to original contributor as given in below copyright. Copyright 2011 David Galles. Copyright 2015 Yves Lucet. Available under the FreeBSD license.

Interactive Data Structure visualizations/animations for algorithms

These are the beautiful and interactive animations to understand various data structure algorithms. Mix and match with different inputs and give a try. If you have any doubts about how these algorithms work, drop a comment. Will get back to you. Visualizations for Data-structure algorithms Credits & Copyright to : This is an embedded link from http://www.cs.usfca.edu/ . Credits to original contributor as given in below copyright. Copyright 2011 David Galles. Copyright 2015 Yves Lucet. Available under the FreeBSD license.

Solution - Rearrange characters in a string such that no two adjacent are same

Rearrange characters in a string such that no two adjacent are same: To view question , click here http://www.interviewrack.com/2017/03/rearrange-characters-in-string-such.html Prerequisite :  priority_queue . The idea is to put highest frequency character first (a greedy approach). We use a priority queue (Or Binary Max Heap) and put all characters and ordered by their frequencies (highest frequency character at root). We one by one take highest frequency character from the heap and add it to result. After we add, we decrease frequency of the character and we temporarily move this character out of priority queue so that it is not picked next time. We have to follow the step to solve this problem, they are: 1. Build a Priority_queue or max_heap,  pq  that stores characters and their frequencies. …… Priority_queue or max_heap is built on the bases of frequency of character. 2. Create a temporary Key that will used as the previous visited element ( prev...