sorting networks
play

Sorting networks Lecture 24 November 12, 2013 Sariel (UIUC) CS573 - PowerPoint PPT Presentation

CS 573: Algorithms, Fall 2013 Sorting networks Lecture 24 November 12, 2013 Sariel (UIUC) CS573 1 Fall 2013 1 / 32 Model of Computation . . Q: Perform a computational task considerably faster by using a 1 different architecture? Yep.


  1. CS 573: Algorithms, Fall 2013 Sorting networks Lecture 24 November 12, 2013 Sariel (UIUC) CS573 1 Fall 2013 1 / 32

  2. Model of Computation . . Q: Perform a computational task considerably faster by using a 1 different architecture? Yep. . . Spaghetti sort ! 2 Sariel (UIUC) CS573 2 Fall 2013 2 / 32

  3. Model of Computation . . Q: Perform a computational task considerably faster by using a 1 different architecture? Yep. . . Spaghetti sort ! 2 Sariel (UIUC) CS573 2 Fall 2013 2 / 32

  4. Model of Computation . . Q: Perform a computational task considerably faster by using a 1 different architecture? Yep. . . Spaghetti sort ! 2 Sariel (UIUC) CS573 2 Fall 2013 2 / 32

  5. Spaghetti Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  6. Spaghetti Pastafarianism Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  7. Spaghetti Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  8. Spaghetti Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  9. Spaghetti The spaghetti tree hoax was a three-minute hoax report broadcast on April Fools’ Day 1957 by the BBC current-affairs programme Panorama, purportedly showing a family in southern Switzerland harvesting spaghetti from the family ”spaghetti tree”. At the time spaghetti was relatively little-known in the UK, so that many Britons were unaware that spaghetti is made from wheat flour and water; a number of viewers afterwards contacted the BBC for advice on growing their own spaghetti trees. Decades later CNN called this broadcast ”the biggest hoax that any reputable news establishment ever pulled.” Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  10. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  11. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  12. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  13. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  14. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  15. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  16. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  17. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  18. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  19. Spaghetti sort . . Input: S = { s 1 , . . . , s n } ⊆ [1 , 2] . 1 . . Have much Spaghetti (this are longish and very narrow tubes of 2 pasta). . . cut i th piece to be of length s i , for i = 1 , . . . , n . 3 . . take all these pieces of pasta in your hand.. 4 . . make them stand up vertically, with their bottom end lying on a 5 horizontal surface . . lower your handle till it hit the first (i.e., tallest) piece of pasta. 6 . . Take it out, measure it height, write down its number 7 . and continue in this fashion till done. 8 . . Linear time sorting algorithm. 9 . . 10 ...but sorting takes Ω( n log n ) time. Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  20. What is going on? . . Faster algorithm achieved by changing the computation model. 1 . . allowed new “strange” operations 2 (cutting a piece of pasta into a certain length, picking the longest one in constant time, and measuring the length of a pasta piece in constant time) . . Using these operations we can sort in linear time. 3 . . So, are there other useful computation models? 4 Sariel (UIUC) CS573 5 Fall 2013 5 / 32

  21. What is going on? . . Faster algorithm achieved by changing the computation model. 1 . . allowed new “strange” operations 2 (cutting a piece of pasta into a certain length, picking the longest one in constant time, and measuring the length of a pasta piece in constant time) . . Using these operations we can sort in linear time. 3 . . So, are there other useful computation models? 4 Sariel (UIUC) CS573 5 Fall 2013 5 / 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend