Partial preview of the text
Download Data structures and algorithms and more Thesis Data Structures and Algorithms in PDF only on Docsity!
Algorithms and Data Structures This minisite contains notes taken by Chris Northwood whilst studying Computer Science at the University of York between 2005-09 and the University of Sheffield 2009-10. They are published here in case others find them useful, but | provide no warranty for their accuracy, completeness or whether or not they are up-to-date. The contents of this page have dubious copyright status, as great portions of some of my revision notes are verbatim from the lecture slides, what the lecturer wrote on the board, or what they said. Additionally, lots of the images have been captured from the lecture slides. Problems and Solutions A problem is a description of the: ¢ assumptions on the inputs e requirements on the outputs A solution is a description of an algorithm and associated data structures that solve that problem, independant of language. e.g., given a non-negative integer n, calculate output: . You could solve this: e s_0 fori—-1ton dos~stfé e Ss. nx (n+ 1)/2 e ifdp.n=2p then s — n/2 S—sx(nt1) else s — (n+ 1)/2 S—xXXxNn Are these correct? If we assume they are, better than others is by measuring resource usage. For our solution: T1 = An: (2i+a+ On+ (2a+ ft) andT2=T3 = An: m+i+d. sis the time to increment by 1, ais the time to assign a value, fis the time to perform the loop test, mis the time to multiply two numbers and dis the time to divide by 2. Therefore, we can see that the time resource usage for the second and third algorithms is constant and for the first algorithm it is linear. If we plotted a graph of T1 against T2 (and T3) we see that for a finite value of nthen T1 has less usage, but for an infinite value of n T1 has greater usage. From this, we can assume that either T2 or T3 are the better algorithms. Jime v1 T2, T3 Asymptotic Complexity dn0,c. n0]©N*ceERt+* Yn.n0 s. Linear Priority Queues Bags of items Bags are sometimes called multisets. They are similar to sets. Sets have members, but bags have the same member more than once (multiplicity) - however order is not important so it is not a series.