Algorithm Lab Report

15
Algorithm Anaysis & Design Lab Report (2010) Rohit Man Amatya 107CS056

Transcript of Algorithm Lab Report

Page 1: Algorithm Lab Report

Algorithm Anaysis & Design

Lab Report(2010)

Rohit Man Amatya107CS056

Page 2: Algorithm Lab Report

Probability

Prove that the probablity of the coin is 0.5

Input:• Automatically generate random no.

Output:• Graph

Programming:GNU Octave, version 3.0.5Octave was configured for "x86_64-pc-linux-gnu".

Page 3: Algorithm Lab Report
Page 4: Algorithm Lab Report
Page 5: Algorithm Lab Report

Sorting Analysis

Compariting the no of comparition made by the different Sorting Algorithm in Different Data inputs

Sorting Method:• Selection Sort• Insertion Sort• Bubble Sort• Quick Sort• Merge Sort

Data Input:• Random• Reverse ordered• Almost Sorted (Rearraging 10% of the element from sorted list)• Nearly sorted

Programming:GNU Octave, version 3.0.5Octave was configured for "x86_64-pc-linux-gnu".

Description:• All sorting algorithm have been written in Octave.• Program Automatically generates the input for analysis and plots the graph.• For changing the range change the value of line 114, 115, 116

Page 6: Algorithm Lab Report
Page 7: Algorithm Lab Report
Page 8: Algorithm Lab Report

TSP Tour Verification

Verifing the TSP tour

Input:• No of Cities• Adjacency Matrix• Tour

Output:Validate Tour

Programming:C++

Page 9: Algorithm Lab Report
Page 10: Algorithm Lab Report

Quicksort algorithm

Use the Quicksort algorithm to develop a program to conduct the following experiment:Repeatedly fill an array of size 4096 with randomly generated integers and record the count of the number of compares needed to sort the list each time. Run this test inside of a loop 50 times, and when finished, record the average number of compares, the best value, the worst value, and the standard deviation. You will have to increment a counter every time you make a comparison inside the partition function. The standard deviation is given by the following formula:

σ= Standard deviationμ= mean

Input:• Automatically generate random no.

Output:• Mean• Standard Deviation

Programming:GNU Octave, version 3.0.5Octave was configured for "x86_64-pc-linux-gnu".

Page 11: Algorithm Lab Report
Page 12: Algorithm Lab Report
Page 13: Algorithm Lab Report

Quicksort algorithm

Modify your sorting algorithm in the previous problem to stop partitioning the list in Quicksort when the size of the (sub)list is less than or equal to 12 and sort the remaining sublist using insertionSort. Your counter will now have to count compares in both the partition function and in each iteration of insertionSort. Again, run the experiment for 50 iterations and record the same set of statistics. Compare your results for the two different sorting techniques and comment upon your results.

Input:• Automatically generate random no.

Output:• Mean• Standard Deviation

Programming:GNU Octave, version 3.0.5Octave was configured for "x86_64-pc-linux-gnu".

Comment:Improvement in the time.

Page 14: Algorithm Lab Report
Page 15: Algorithm Lab Report