Preview

Lecture Notes on Design & Analysis of Algorithms

Powerful Essays
Open Document
Open Document
3413 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Lecture Notes on Design & Analysis of Algorithms
Lecture Notes on Design & Analysis of Algorithms

G P Raja Sekhar Department of Mathematics I I T Kharagpur
Acknowledgements : Ahmad Abdullah, Pronoy Sikdar, Anshul Kamra, Sugam Agrawal & Students of DAA course 2006-07, Data Structures & Algorithms 2006-07.

BUBBLE SORT
The bubble sort is the oldest and simplest sort in use. The bubble sort works by comparing each item in the list with the item next to it, and swapping them if required. The algorithm repeats this process until it makes a pass all the way through the list without swapping any items. This causes larger values to "bubble" to the end of the list while smaller values "sink" towards the beginning of the list.

Pros: 1) Simplicity and ease of implementation. 2) Auxiliary Space used is O (1). Cons: 1) Very inefficient. General complexity is O (n2). Best case complexity is O(n).

Bubble Sort Efficiency

INSERTION SORT
The insertion sort works just like its name suggests - it inserts each item into its proper place in the final list. The simplest implementation of this requires two list structures - the source list and the list into which sorted items are inserted. To save memory, most implementations use an in-place sort that works by moving the current item past the already sorted items and repeatedly swapping it with the preceding item until it is in place.

Pros: Auxiliary space used is O (1). Cons: General Complexity is O (n2). Best Case is O(n) when the list is already sorted.

Insertion Sort Efficiency

HEAP SORT
All elements to be sorted are inserted into a heap, and the heap organizes the elements added to it in such a way that either the largest value (in a max-heap) or the smallest value (in a min-heap) can be quickly extracted. Moreover, because this operation preserves the heap's structure, the largest/smallest value can be repeatedly extracted until none remain. Each time we delete (extract) the maximum, we place it in the last location of the array not yet occupied, and

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Nt1310 Unit 8 Lab 1

    • 421 Words
    • 2 Pages

    5. Some of the advantages are: Straight-forward Concept, Chain-length limit, and less time to obtain a usable certificate within the CA…

    • 421 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    a) What are the values produced by the following Matlab expressions: i) x = -1e+200; ans1 = log(exp(x)) ii) v = [-1:1] ans2 = v./v.^(1/2) iii) x = 200; h = 1e-14; ans3 = x + h > x b) The computational complexity of some common operations with n by n matrices are Operation Matrix multiplication LU factorization Cholesky factorization Back/forward substitution Tridiagonal solve Flops 2n3…

    • 10483 Words
    • 42 Pages
    Good Essays
  • Satisfactory Essays

    CS 220 – Programming w/ Data Structures: You have missed one assignment and one quiz. Your instructor has extended your assignment due date to this Sunday, April 10. Your instructor has also let you to take your Quiz # 2 during his office hours during this week. Let me know if you need additional support to study for this quiz. Your grade to date in this class is 30.2/37 81.62% B.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Searching and Sorting Streams and Files Graphics GUI Components and Events Mouse, Keyboard, Sounds, and Images Big-O Analysis of Algorithms The Java Collections Framework Lists and Iterators Stacks and Queues Recursion Revisited Binary Trees Lookup Tables and Hashing Heaps and Priority Queues Design Patterns…

    • 3908 Words
    • 16 Pages
    Powerful Essays
  • Satisfactory Essays

    4) Make another copy of the data values listed in column 1 and paste those into column 3. Then sort only…

    • 622 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Fedora 15 chapter 7 & 8

    • 375 Words
    • 2 Pages

    (ls -S sorts by size - largest first. Other useful options: -r reverse current sorting. -s adds the size before filename. -l long listing. -t sort by creation time.)…

    • 375 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Alphabetical listings are effective and organized systems of filing information. Some find the system unfair because it singles out people with last names starting with letters at the end of the alphabet. This person doesn't want to admit that it could start from Z to A. Alphabetical order is an easy system and should not be banned because of the ludicrous thought of unfairness.…

    • 348 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Cost is not the only factor to be considered when selection between these two operability and compatibility has to be considered when choosing one over the other. Unix several years ago…

    • 852 Words
    • 4 Pages
    Good Essays
  • Good Essays

    big o notation

    • 939 Words
    • 4 Pages

    The Big-O-Notation is used in many different structures to calculate the efficiency of algorithms which are:-…

    • 939 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    sort. It was used widely in the past and still exists in some areas today. It…

    • 1412 Words
    • 6 Pages
    Powerful Essays
  • Satisfactory Essays

    A bubble sort algorithm loops through a set of data items. Comparing items and switching them if they are in the wrong order. This process is repeated until the list is sorted. It is called a bubble sort because the smaller items “bubble up” towards the top of the list.…

    • 328 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Ghghghj

    • 1445 Words
    • 6 Pages

    * Your program might be asking the user for input, or gathering input from a web site. As it finds objects (strings, books, values, etc.) you will add them to the array…

    • 1445 Words
    • 6 Pages
    Powerful Essays
  • Powerful Essays

    The goal of the Turnpike Problem is to reconstruct those point sets that arise from a given distance multiset. Although the Turnpike Problem itself is of unknown complexity, variants of it have been proven to be NP-complete, and there are no existing polynomial algorithms for it. P systems with active membranes and P systems with membrane creation are parallel computing models based on the characteristics of living cells; both have been used to solve NPcomplete problems in polynomial time or better by trading time for an exponential workspace. In this paper we present a P system with active membranes and membrane creation that implements an O(2n n log n)-time backtracking algorithm for the Turnpike Problem in linear time. multiset; according to [9], when these point sets are unique (that is, none of them is a reflection of another), they are called homometric sets. TP first appeared in the 1930’s as a problem in X-ray crystallography, and reappeared in DNA sequencing as the Partial Digest Problem (PDP). The exact computational complexity of TP remains an open problem, although certain variants of it, as well as the decision problem of whether n points in R realize a multiset of n distances, have been proven to be NP-complete 2 in [9]. (Similarly, PDP’s own computational complexity is an open problem; variants of it are proven to be NP-hard or NP-complete in [2].) However, no polynomial-time algorithm has been found that solves TP. Among the algorithms that have been proposed is a polynomial factorization algorithm presented by Rosenblatt and Seymour in [8], and a backtracking algorithm presented by Skiena et al in [9]. The polynomial factorization algorithm…

    • 10209 Words
    • 41 Pages
    Powerful Essays
  • Good Essays

    Bubble Sort – Sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, most other algorithms are more efficient for sorting large lists.…

    • 1473 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Wireless Bomb Disposal Robot

    • 11425 Words
    • 46 Pages

    Our project is represented the most by the third definition. The robot that we have…

    • 11425 Words
    • 46 Pages
    Good Essays