Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bernstein Vazirani Algorithm + Readme Documentation #40

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Solution {
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;

operation Solve (N : Int, Uf : ((Qubit[], Qubit) => ())) : Int[]
{
body
{
mutable ans = new Int[N];
using (qs = Qubit[N+1]){
X(qs[N]);
ApplyToEachA(H, qs);
Uf(qs[0..N-1], qs[N]);
ApplyToEachA(H, qs);
X(qs[N]);
for (i in 0..N-1){
if (M(qs[i]) == One){
set ans w/= i <- 1;
}
}
ResetAll(qs);
}
return ans;
}
}
}
19 changes: 19 additions & 0 deletions qsharp/Bernstein Vazirani Algorithm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The Bernstein-Vazirani algorithm can be seen as an extension of the Deutsch-Josza algorithm we covered in the last section.

It shows that there can be advantages in using a quantum computer as a computational tool for more complex problems, Quantum computing can go far beyond the possibilities of today’s classical high performance computing.

Suppose we have a black box, by it we mean we cannot get any information from it, there is a binary string in this box and we want to know the number.

With classical computer very time we can perform a single and operation on box and see the output result and finally get to know the number. But with a Quantum computer and by using Bernstein-Vazirani Algorithm we can know the number just with on operation.

In order to implement Bernstein-Vazirani Algorithm, we need to take few steps:

Initialise the inputs qubits to the |0> state, and output qubit to |->.

Apply Hadamard gates to the input register

Query the oracle

Apply Hadamard gates to the input register

Measure