Design and Analysis of Algorithm

Hamiltonian Cycle

 Hamiltonian Path in an undirected graph is a path that visits each vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path such that there is...

Travelling Salesman Problem

Travelling Salesman Problem (TSP): Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route that visits every city...

Finite Automaton Method

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat, char txt) that prints all occurrences of pat in txt. You may assume that n >...

Naive Method

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat, char txt) that prints all occurrences of pat in txt. You may assume that n >...

Method for string matching

  Naïve Method Rabin Karp Method Finite automaton Method  

String Matching

Finding all occurrences of a pattern in a text is a problem that arises frequently in text-editing programs. Typically, the text is a document being edited, and the pattern...

Knapsack problem using Backtracking

Given n positive weights wi, n positive profits pi , and a positive number M which is the knapsack capacity, the 0/1 knapsack problem calls for choosing a subset...

N Queens Problem

The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. For example, following is a solution...

Tree Traversals

Tree Traversals Unlike linear data structures (Array, Linked List, Queues, Stacks, etc) which have only one logical way to traverse them, trees can be traversed in different ways. Following...

Depth First Search (DFS)

The DFS forms a depth-first forest comprised of more than one depth-first trees. Each tree is made of edges (u, v) such that u is gray and v is...