/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 12: Snippets. Welcome!

Size: px
Start display at page:

Download "/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 12: Snippets. Welcome!"

Transcription

1 /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov Lecture 12: Snippets Welcome!

2 Today s Agenda: Self-modifying code Blind stupidity Of square roots and sorting Madness

3 INFOMOV Lecture 12 Snippets 3 Self-modifying Fast Polygons on Limited Hardware Typical span rendering code: for( int i = 0; i < len; i++ ) *a++ = texture[u,v]; u += du; v += dv; } How do we make this faster? Every cycle counts Loop unrolling Two pixels at a time

4 INFOMOV Lecture 12 Snippets 4 Self-modifying Fast Polygons on Limited Hardware How about switch (len) case 8: *a++ = tex[u,v]; u+=du; v+=dv; case 7: *a++ = tex[u,v]; u+=du; v+=dv; case 6: *a++ = tex[u,v]; u+=du; v+=dv; case 5: *a++ = tex[u,v]; u+=du; v+=dv; case 4: *a++ = tex[u,v]; u+=du; v+=dv; case 3: *a++ = tex[u,v]; u+=du; v+=dv; case 2: *a++ = tex[u,v]; u+=du; v+=dv; case 1: *a++ = tex[u,v]; u+=du; v+=dv; }

5 INFOMOV Lecture 12 Snippets 5 Self-modifying Fast Polygons on Limited Hardware What if a massive unroll isn t an option, but we have only 4 registers? for( int i = 0; i < len; i++ ) *a++ = texture[u,v]; u += du, v += dv; } Registers: i, a, u, v, du, dv, len }. Idea: just before entering the loop, replace len by the correct constant in the code; replace du and dv by the correct constant. Our code is now self-modifying.

6 INFOMOV Lecture 12 Snippets 6 Self-modifying Self-modifying Code Good reasons for not writing SMC: the CPU pipeline (mind every potential (future) target) L1 instruction cache (handles reads only) code readability Good reasons for writing SMC: code readability genetic code optimization

7 INFOMOV Lecture 12 Snippets 7 Self-modifying Hardware Evolution* Experiment: take 100 FPGA s, load them with random programs, max 100 logic gates test each chip s ability to differentiate between two audio tones use the best candidates to produce the next generation. Outcome (generation 4000): one chip capable of the intended task. NASA s evolved antenna** Observations: 1. The chip used only 37 logic gates, of which 5 disconnected from the rest. 2. The 5 disconnected gates where vital to the function of the chip. 3. The program could not be transferred to another chip. *: On the Origin of Circuits, Alan Bellows, 2007, **: Evolved antenna, Wikipedia.

8 Today s Agenda: Self-modifying code Blind stupidity Of square roots and sorting Madness

9 INFOMOV Lecture 12 Snippets 9 Application DotCloud Application breakdown, Tick: t.reset(); Transform(); elapsed1 = t.elapsed(); t.reset(); Sort(); elapsed2 = t.elapsed(); t.reset(); Render(); elapsed3 = t.elapsed(); Transform: for ( int i = 0; i < DOTS; i++ ) m_rotated[i] = m.transform( m_points[i] ); Sort: for ( int i = 0; i < DOTS; i++ ) for ( int j = 0; j < (DOTS - 1); j++ ) if (m_rotated[j].z > m_rotated[j + 1].z) Swap( j, j + 1 ); Render: for ( int i = 0; i < DOTS; i++ ) m_dot->drawscaled( (sx - size / 2), (sy - size / 2), size, size, screen );

10 INFOMOV Lecture 12 Snippets 10 Application DotCloud Application breakdown: Tick Sort Transform Render DrawScaled

11 INFOMOV Lecture 12 Snippets 11 Analysis Performance Analysis & Scalability ms per frame Transform Sort Render Clear ms per dot Transform Sort Render Clear

12 INFOMOV Lecture 12 Snippets 12 Research Solving the Sort Problem Current Sort: bubblesort ( O(N 2 ) ). Alternatives*: Quicksort Heapsort Mergesort Radixsort Insertionsort Selectionsort Monkeysort Countingsort Introsort Shell sort Binary tree sort Library sort Smoothsort Strand sort Cocktail sort Comb sort Block sort Odd-even sort Pigeonhole sort Bucket sort Spread sort Burstsort Flashsort Postman sort Bread sort Bitonic sort Stooge sort * See e.g.:

13 INFOMOV Lecture 12 Snippets 13 Research Solving the Sort Problem Current Sort: bubblesort ( O(N 2 ) ). Best case: O(N). Which case do we have here? Factors: Size of set Already sorted / almost sorted? Distributed (even / uneven) Type of data (just key / full records) Key type (float / int / string) How much effort should we spend on this? For small sets, sorting takes far less time than rendering Anything that is not O(N 2 ) will probably be fine. Would be nice if we can find something that fits well in the current code (safe time for other optimizations).

14 INFOMOV Lecture 12 Snippets 14 High-level Solving the Sort Problem Current Sort: bubblesort ( O(N 2 ) ). Alternative: QuickSort ( O( N log N ) ). void Swap( float3& a, float3& b ) float3 t = a; a = b; b = t; } int Pivot( float3 a[], int first, int last ) int p = first; float3 e = a[first]; for( int i = first + 1; i <= last; i++ ) if (a[i].z <= e.z) Swap( a[i], a[++p] ); Swap( a[p], a[first] ); return p; } void QuickSort( float3 a[], int first, int last) int pivotelement; if (first >= last) return; pivotelement = Pivot( a, first, last ); QuickSort( a, first, pivotelement - 1 ); QuickSort( a, pivotelement + 1, last ); }

15 INFOMOV Lecture 12 Snippets 15 Profile Repeated Profiling bubblesort Transform Sort (bubble) Sort (quick) Render Clear Note: Clear is implemented using a loop; a memset is faster for clearing to zero (~0.43).

16 INFOMOV Lecture 12 Snippets 16 Profile Repeated Profiling

17 INFOMOV Lecture 12 Snippets 17 Low-level Low Level Optimization of DrawScaled void Sprite::DrawScaled( float a_x, float a_y, float a_width, float a_height, Surface* a_target ) Pixel* dest = a_target->getbuffer() + (int)a_x + (int)a_y * a_target->getpitch(); Pixel* src = GetBuffer() + m_currentframe * m_width; for ( int y = 0; y < (int)a_height; y++ ) for ( int x = 0; x < (int)a_width; x++ ) int v = (int)((y * m_height) / a_height); int u = (int)((x * m_pitch) / a_width); if (src[u + v * m_pitch] & 0xffffff) *(dest + x + y * a_target->getwidth()) = src[u + v * m_pitch]; } } Functionality: for every pixel of the rectangular target image, find the corresponding source pixel, using interpolation, plot if it s not black.

18 INFOMOV Lecture 12 Snippets 18 Low-level Low Level Optimization of DrawScaled A few basic optimizations: void Sprite::DrawScaled( float a_x, float a_y, float a_width, float a_height, Surface* a_target ) Pixel* dest = a_target->getbuffer() + (int)a_x + (int)a_y * a_target->getpitch(); Pixel* src = GetBuffer() + m_currentframe * m_width; for ( int y = 0; y < (int)a_height; y++ ) int v = (int)((y * m_height) / a_height); for ( int x = 0; x < (int)a_width; x++ ) int u = (int)((x * m_pitch) / a_width); Pixel color = src[u + v * m_pitch] & 0xffffff; if (color) *(dest + x + y * a_target->getwidth()) = color; } } } Loop hoisting (variable v is constant inside x loop) Reading source pixel only once

19 INFOMOV Lecture 12 Snippets 19 Low-level Low Level Optimization of DrawScaled More basic optimizations: void Sprite::DrawScaled( float a_x, float a_y, float a_width, float a_height, Surface* a_target ) Pixel* dest = a_target->getbuffer() + (int)a_x + (int)a_y * a_target->getpitch(); Pixel* src = GetBuffer() + m_currentframe * m_width; float rw = (float)m_width / a_width; float rh = (float)m_height / a_height; int iw = (int)a_width, ih = (int)a_height; } for ( int y = 0; y < ih; y++ ) int v = (int)(y * rh); Pixel* line = dest + y * a_target->getwidth(); for ( int x = 0; x < iw; x++ ) int u = (int)(x * rw); Pixel color = src[u + v * m_width] & 0xffffff; if (color) line[x] = color; } } Precalculate m_height / a_height, m_width / a_width Calculate target address once per line; index using x

20 INFOMOV Lecture 12 Snippets 20 Low-level Low Level Optimization of DrawScaled Fixed point optimization: void Sprite::DrawScaled( int a_x, int a_y, int a_width, int a_height, Surface* a_target ) const int rh = (m_height << 10) / a_height, rw = (m_width << 10) / a_width; Pixel* line = a_target->getbuffer() + a_x + a_y * a_target->getpitch(); for ( int y = 0; y < a_height; y++, line += a_target->getpitch() ) const int v = (y * rh) >> 10; for ( int x = 0; x < a_width; x++ ) const int u = (x * rw) >> 10; const Pixel color = GetBuffer()[u + v * m_pitch]; if (color & 0xffffff) line[x] = color; } } } Fixed point works really well here but doesn t improve performance. Seems we reached the end here

21 INFOMOV Lecture 12 Snippets 21 Blind Stupidity Low Level Optimization of DrawScaled Now what? Plot multiple pixels at a time? How many different ball sizes do we encounter? Why don t we simply precalculate those frames?

22 INFOMOV Lecture 12 Snippets 22 More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason including blind stupidity. (W.A. Wulff)

23 INFOMOV Lecture 12 Snippets 23 High-level High Level Optimization of DrawScaled Sprite* scaled[64]; void Game::Init()... for( int i = 0; i < 64; i++ ) int size = i + 1; scaled[i] = new Sprite( new Surface( size, size ), 1 ); scaled[i]->getsurface()->clear( 0 ); m_dot->drawscaled( 0, 0, size, size, scaled[i]->getsurface() ); } } scaled[size]->draw( (sx - size / 2), (sy - size / 2), m_surface );

24 INFOMOV Lecture 12 Snippets 24 Profile Repeated Profiling bubblesort Transform Sort Render (old) Render (new)

25 INFOMOV Lecture 12 Snippets 25 Profile What about the compiler? bubblesort Transform Sort Render (vs 13) Render (vs 15) ? 26.30

26 INFOMOV Lecture 12 Snippets 26 Profile What about the compiler? bubblesort Transform Sort Render (vs 13) Render ( 15,32) ? Render ( 15,64)

27 INFOMOV Lecture 12 Snippets 27 Dotting i s Optimization of Dense Clouds Observation: beyond a certain dot count, a large number of particles is occluded. Specifically, we won t be able to see the back half. if (m_rotated[i].z > -0.2f) scaled[size]->draw( (sx - size / 2), (sy - size / 2), screen ); (perhaps we could also limit rendering to the outer shell of the cloud?) Rendering is now significantly faster, and sorting is significant again: At dots, we get 11ms for sorting, 3ms for rendering.

28 INFOMOV Lecture 12 Snippets 28 High-level Sorting in O(1) For this specific situation, we can sort in O(1), e.g., independent of particle count. Observation: dots do not move independently. Intuition: why rotate 64k dots if you can rotate a single camera?

29 INFOMOV Lecture 12 Snippets 29 High-level Sorting in O(1)

30 INFOMOV Lecture 12 Snippets 30 High-level Sorting in O(1)

31 INFOMOV Lecture 12 Snippets 31 High-level Sorting in O(1)

32 INFOMOV Lecture 12 Snippets 32 High-level Sorting in O(1)

33 INFOMOV Lecture 12 Snippets 33 High-level Sorting in O(1)

34 INFOMOV Lecture 12 Snippets 34 High-level Sorting in O(1) For each split: Process nearest half first Then farthest half Recurse Where nearest is the side that the camera is on.

35 INFOMOV Lecture 12 Snippets 37 High-level Optimizing Sphere Cloud - TakeAway Profile High level: bang for the buck Mind blind stupidity The fastest solution is sometimes not doing anything at all

36 Today s Agenda: Self-modifying code Blind stupidity Of square roots and sorting Madness

37 INFOMOV Lecture 12 Snippets 39 Sqrt & Sort Accurate reciprocal square roots 1.0f / sqrtf( 7 ) : / sqrt( 7 ) : _mm_rsqrt_ps( _mm_set1_ps( 7.0f ) ) : Newton iteration: y n+1 = y n(3 xy n 2 ) 2 In SSE: m128 y = _mm_rsqrt_ps( x ); m128 m = _mm_mul_ps( _mm_mul_ps( x, y ), y ); return _mm_mul_ps( _mm_mul_ps( half, y ), _mm_sub_ps( three, m ) );

38 INFOMOV Lecture 12 Snippets 40 Sqrt & Sort idxmask4 = _mm_set1_ps( 0xfffffffc ); idxadd4 = _mm_set_ps( 0, 1, 2, 3 ); void sse_sort( m128& v0 ) Sorting four key/item pairs Sorting three numbers a,b and c: if (a > b) swap( a, b ); if (b > c) swap( b, c ); if (a > b) swap( a, b ); Sorting four numbers a, b, c and d: if (a > c) swap( a, c ); if (b > d) swap( b, d ); if (a > b) swap( a, b ); if (c > d) swap( c, d ); if (b > c) swap( b, c ); } m128 v1, v2, v3, t; v0 = _mm_or_ps(_mm_and_ps( v0, idxmask4 ),idxadd4 ); v1 = _mm_movelh_ps( v1, v0 ), t = v0; v0 = _mm_min_ps( v0, v1 ), v1 = _mm_max_ps( v1, t ); v0 = _mm_movehl_ps( v0, v1 ); v1 = _mm_shuffle_ps( v1, v0, 0x88 ), t = v0; v0 = _mm_min_ps( v0, v1 ), v1 = _mm_max_ps( v1, t ); v2 = _mm_movehl_ps( v2, v1 ), v3 = v0, t = v2; v2 = _mm_min_ps( v2, v3 ), v3 = _mm_max_ps( v3, t ); v0 = _mm_shuffle_ps( _mm_movelh_ps( v1, v3 ), _mm_shuffle_ps( v0, v2, 0x ), 0x2d );

39 Today s Agenda: Self-modifying code Blind stupidity Of square roots and sorting Madness

40 INFOMOV Lecture 12 Snippets 42 Low Level Optimization of Sprite::Draw Pre-scaled sprites are faster than on-the-fly scaling. But, we still have loops, and if-statements, and look-ups. I wonder

41 INFOMOV Lecture 12 Snippets 43 Low Level Optimization of Sprite::Draw Extreme Optimization: We simply generate a function that plots every pixel, without the need for a loop. Side effect: L1 data cache is now used for the screen buffer; L1 instruction cache is used for the sprite data. void Sprite::DrawBall( int x, int y, int size, Surface* target ) uint* a = target->getbuffer() + x + y * SCRWIDTH; switch( size ) case 1: break; case 2: a[1]= ; a[800]= ; a[801]= ; break; case 3: a[801]= ; a[802]= ; a[1601]= ; a[1602]= ; break; case 4: a[2]= ; a[801]= ; a[802]= ; a[803]= ; a[1600]= ; a[1601]= ; a[1602]= ; a[1603]= ; a[2401]= ; a[2402]= ; a[2403]= ; break;

42 INFOMOV Lecture 12 Snippets 44 Low Level Optimization of Sprite::Draw Extreme Optimization: We simply generate a function that plots every pixel, without the need for a loop. FILE* f = fopen( "drawfunc.h", "w" ); fprintf( f, "void Sprite::DrawBall( int x, int y, int size, Surface* target )\n" ); fprintf( f, "\nuint* a = target->getbuffer() + x + y * SCRWIDTH;\nswitch( size )\n\n" ); for( int i = 0; i < 64; i++ )... fprintf( f, "case %i:\n", size ); for( int y = 0; y < size; y++) for( int x = 0; x < size; x++ ) int a = y * SCRWIDTH + x; if (scaled[i]->getbuffer()[x + y * size] & 0xffffff) fprintf( f, "a[%i]=%i;\n", a, scaled[i]->getbuffer()[x + y * size] & 0xffffff ); } fprintf( f, "break;\n" ); } fprintf( f, "}\n}\n" );

43 INFOMOV Lecture 12 Snippets 45 switch( size ) case 1: break; case 2: a[1]= ; a[800]= ; a[801]= ; break; case 3: a[801]= ; a[802]= ; a[1601]= ; a[1602]= ; break; case 4: a[2]= ; a[801]= ; a[802]= ; a[803]= ; a[1600]= ; a[1601]= ; a[1602]= ; a[1603]= ; a[2401]= ; a[2402]= ; a[2403]= ; break; case 5: a[2]=526344; a[3]=526344; a[801]= ; a[802]= ; a[803]= ; a[804]= ; a[1600]=526344; a[1601]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[2400]=526344; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; break; case 6: a[3]= ; a[801]= ; a[802]= ; a[803]= ; a[804]= ; a[805]= ; a[1601]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[2400]= ; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]=526344; break; case 7: a[3]= ; a[4]=526344; a[801]=526344; a[802]= ; a[803]= ; a[804]= ; a[805]= ; a[1601]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[2400]= ; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[3200]=526344; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; break; case 8: a[3]=526344; a[4]= ; a[801]=526344; a[802]= ; a[803]= ; a[804]= ; a[805]= ; a[806]= ; a[1601]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[2400]=526344; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[3200]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; break; case 9: a[4]= ; a[5]= ; a[802]= ; a[803]= ; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[1601]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]=526344; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[3200]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[4000]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[6402]=526344; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; break; case 10: a[4]=526344; a[5]= ; a[6]=526344; a[802]= ; a[803]= ; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]=526344; a[1601]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[3200]=526344; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[4000]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4800]=526344; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[6401]=526344; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; break; case 11: a[4]=526344; a[5]= ; a[6]= ; a[803]= ; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]=526344; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]=526344; a[3200]=526344; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[4000]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4800]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[6401]=526344; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]=526344; a[8003]=526344; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; break; case 12: a[5]= ; a[6]= ; a[7]=526344; a[803]= ; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]= ; a[1602]= ; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[2401]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]=526344; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[4000]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4800]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[4811]= ; a[5600]=526344; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[5611]= ; a[6401]= ; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[6410]= ; a[6411]=526344; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]= ; a[7210]= ; a[8002]= ; a[8003]= ; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; a[8008]= ; a[8009]= ; a[8010]=526344; a[8803]=526344; a[8804]= ; a[8805]= ; a[8806]= ; a[8807]= ; a[8808]=526344; break; case 13: a[5]=526344; a[6]= ; a[7]= ; a[8]=526344; a[803]=526344; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]= ; a[809]= ; a[1602]=526344; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[2401]=526344; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[3212]=526344; a[4000]=526344; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4012]= ; a[4800]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[4811]= ; a[4812]= ; a[5600]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[5611]= ; a[5612]= ; a[6400]=526344; a[6401]= ; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[6410]= ; a[6411]= ; a[6412]= ; a[7201]= ; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]= ; a[7210]= ; a[7211]= ; a[7212]=526344; a[8002]= ; a[8003]= ; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; a[8008]= ; a[8009]= ; a[8010]= ; a[8011]= ; a[8803]= ; a[8804]= ; a[8805]= ; a[8806]= ; a[8807]= ; a[8808]= ; a[8809]= ; a[8810]= ; a[9604]=526344; a[9605]= ; a[9606]= ; a[9607]= ; a[9608]= ; a[9609]=526344; break; case 14: a[5]=526344; a[6]= ; a[7]= ; a[8]=526344; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]= ; a[809]= ; a[810]= ; a[1602]=526344; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[1611]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]= ; a[2412]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[3212]= ; a[3213]=526344; a[4000]=526344; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4012]= ; a[4013]= ; a[4800]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[4811]= ; a[4812]= ; a[4813]= ; a[5600]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[5611]= ; a[5612]= ; a[5613]= ; a[6400]=526344; a[6401]= ; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[6410]= ; a[6411]= ; a[6412]= ; a[6413]= ; a[7201]= ; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]= ; a[7210]= ; a[7211]= ; a[7212]= ; a[7213]= ; a[8001]= ; a[8002]= ; a[8003]= ; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; a[8008]= ; a[8009]= ; a[8010]= ; a[8011]= ; a[8012]= ; a[8013]=526344; a[8802]= ; a[8803]= ; a[8804]= ; a[8805]= ; a[8806]= ; a[8807]= ; a[8808]= ; a[8809]= ; a[8810]= ; a[8811]= ; a[8812]=526344; a[9603]= ; a[9604]= ; a[9605]= ; a[9606]= ; a[9607]= ; a[9608]= ; a[9609]= ; a[9610]= ; a[9611]=526344; a[10404]=526344; a[10405]= ; a[10406]= ; a[10407]= ; a[10408]= ; a[10409]= ; a[10410]=526344; break; case 15: a[6]=526344; a[7]= ; a[8]= ; a[9]=526344; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]= ; a[809]= ; a[810]= ; a[811]=526344; a[1602]=526344; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[1611]= ; a[1612]= ; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]= ; a[2412]= ; a[2413]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[3212]= ; a[3213]= ; a[3214]=526344; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4012]= ; a[4013]= ; a[4014]= ; a[4800]=526344; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[4811]= ; a[4812]= ; a[4813]= ; a[4814]= ; a[5600]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[5611]= ; a[5612]= ; a[5613]= ; a[5614]= ; a[6400]= ; a[6401]= ; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[6410]= ; a[6411]= ; a[6412]= ; a[6413]= ; a[6414]= ; a[7200]=526344; a[7201]= ; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]= ; a[7210]= ; a[7211]= ; a[7212]= ; a[7213]= ; a[7214]= ; a[8001]= ; a[8002]= ; a[8003]= ; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; a[8008]= ; a[8009]= ; a[8010]= ; a[8011]= ; a[8012]= ; a[8013]= ; a[8014]=526344; a[8801]=526344; a[8802]= ; a[8803]= ; a[8804]= ; a[8805]= ; a[8806]= ; a[8807]= ; a[8808]= ; a[8809]= ; a[8810]= ; a[8811]= ; a[8812]= ; a[8813]= ; a[9602]= ; a[9603]= ; a[9604]= ; a[9605]= ; a[9606]= ; a[9607]= ; a[9608]= ; a[9609]= ; a[9610]= ; a[9611]= ; a[9612]= ; a[9613]=526344; a[10403]= ; a[10404]= ; a[10405]= ; a[10406]= ; a[10407]= ; a[10408]= ; a[10409]= ; a[10410]= ; a[10411]= ; a[10412]=526344; a[11204]=526344; a[11205]= ; a[11206]= ; a[11207]= ; a[11208]= ; a[11209]= ; a[11210]=526344; break; case 16: a[6]=526344; a[7]= ; a[8]= ; a[9]=526344; a[804]= ; a[805]= ; a[806]= ; a[807]= ; a[808]= ; a[809]= ; a[810]= ; a[811]= ; a[1602]=526344; a[1603]= ; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[1611]= ; a[1612]= ; a[1613]=526344; a[2402]= ; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]= ; a[2412]= ; a[2413]= ; a[3201]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[3212]= ; a[3213]= ; a[3214]= ; a[4001]= ; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4012]= ; a[4013]= ; a[4014]= ; a[4800]=526344; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[4811]= ; a[4812]= ; a[4813]= ; a[4814]= ; a[4815]=526344; a[5600]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[5611]= ; a[5612]= ; a[5613]= ; a[5614]= ; a[5615]= ; a[6400]= ; a[6401]= ; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[6410]= ; a[6411]= ; a[6412]= ; a[6413]= ; a[6414]= ; a[6415]= ; a[7200]=526344; a[7201]= ; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]= ; a[7210]= ; a[7211]= ; a[7212]= ; a[7213]= ; a[7214]= ; a[7215]=526344; a[8001]= ; a[8002]= ; a[8003]= ; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; a[8008]= ; a[8009]= ; a[8010]= ; a[8011]= ; a[8012]= ; a[8013]= ; a[8014]= ; a[8801]= ; a[8802]= ; a[8803]= ; a[8804]= ; a[8805]= ; a[8806]= ; a[8807]= ; a[8808]= ; a[8809]= ; a[8810]= ; a[8811]= ; a[8812]= ; a[8813]= ; a[8814]= ; a[9602]= ; a[9603]= ; a[9604]= ; a[9605]= ; a[9606]= ; a[9607]= ; a[9608]= ; a[9609]= ; a[9610]= ; a[9611]= ; a[9612]= ; a[9613]= ; a[10402]=526344; a[10403]= ; a[10404]= ; a[10405]= ; a[10406]= ; a[10407]= ; a[10408]= ; a[10409]= ; a[10410]= ; a[10411]= ; a[10412]= ; a[10413]=526344; a[11204]= ; a[11205]= ; a[11206]= ; a[11207]= ; a[11208]= ; a[11209]= ; a[11210]= ; a[11211]= ; a[12006]=526344; a[12007]= ; a[12008]= ; a[12009]=526344; break; case 17: a[6]=526344; a[7]= ; a[8]= ; a[9]= ; a[10]=526344; a[805]=526344; a[806]= ; a[807]= ; a[808]= ; a[809]= ; a[810]= ; a[811]= ; a[812]=526344; a[1603]=526344; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[1611]= ; a[1612]= ; a[1613]= ; a[2402]=526344; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]= ; a[2412]= ; a[2413]= ; a[2414]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[3212]= ; a[3213]= ; a[3214]= ; a[3215]=526344; a[4001]=526344; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4012]= ; a[4013]= ; a[4014]= ; a[4015]= ; a[4800]=526344; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ; a[4809]= ; a[4810]= ; a[4811]= ; a[4812]= ; a[4813]= ; a[4814]= ; a[4815]= ; a[4816]=526344; a[5600]= ; a[5601]= ; a[5602]= ; a[5603]= ; a[5604]= ; a[5605]= ; a[5606]= ; a[5607]= ; a[5608]= ; a[5609]= ; a[5610]= ; a[5611]= ; a[5612]= ; a[5613]= ; a[5614]= ; a[5615]= ; a[5616]= ; a[6400]= ; a[6401]= ; a[6402]= ; a[6403]= ; a[6404]= ; a[6405]= ; a[6406]= ; a[6407]= ; a[6408]= ; a[6409]= ; a[6410]= ; a[6411]= ; a[6412]= ; a[6413]= ; a[6414]= ; a[6415]= ; a[6416]= ; a[7200]= ; a[7201]= ; a[7202]= ; a[7203]= ; a[7204]= ; a[7205]= ; a[7206]= ; a[7207]= ; a[7208]= ; a[7209]= ; a[7210]= ; a[7211]= ; a[7212]= ; a[7213]= ; a[7214]= ; a[7215]= ; a[7216]= ; a[8000]=526344; a[8001]= ; a[8002]= ; a[8003]= ; a[8004]= ; a[8005]= ; a[8006]= ; a[8007]= ; a[8008]= ; a[8009]= ; a[8010]= ; a[8011]= ; a[8012]= ; a[8013]= ; a[8014]= ; a[8015]= ; a[8016]=526344; a[8801]= ; a[8802]= ; a[8803]= ; a[8804]= ; a[8805]= ; a[8806]= ; a[8807]= ; a[8808]= ; a[8809]= ; a[8810]= ; a[8811]= ; a[8812]= ; a[8813]= ; a[8814]= ; a[8815]= ; a[9601]=526344; a[9602]= ; a[9603]= ; a[9604]= ; a[9605]= ; a[9606]= ; a[9607]= ; a[9608]= ; a[9609]= ; a[9610]= ; a[9611]= ; a[9612]= ; a[9613]= ; a[9614]= ; a[9615]= ; a[10402]= ; a[10403]= ; a[10404]= ; a[10405]= ; a[10406]= ; a[10407]= ; a[10408]= ; a[10409]= ; a[10410]= ; a[10411]= ; a[10412]= ; a[10413]= ; a[10414]= ; a[11203]= ; a[11204]= ; a[11205]= ; a[11206]= ; a[11207]= ; a[11208]= ; a[11209]= ; a[11210]= ; a[11211]= ; a[11212]= ; a[11213]= ; a[11214]=526344; a[12004]=526344; a[12005]= ; a[12006]= ; a[12007]= ; a[12008]= ; a[12009]= ; a[12010]= ; a[12011]= ; a[12012]= ; a[12806]=526344; a[12807]= ; a[12808]= ; a[12809]= ; a[12810]=526344; break; case 18: a[7]=526344; a[8]= ; a[9]= ; a[10]= ; a[11]=526344; a[805]=526344; a[806]= ; a[807]= ; a[808]= ; a[809]= ; a[810]= ; a[811]= ; a[812]=526344; a[1603]=526344; a[1604]= ; a[1605]= ; a[1606]= ; a[1607]= ; a[1608]= ; a[1609]= ; a[1610]= ; a[1611]= ; a[1612]= ; a[1613]= ; a[1614]= ; a[2402]=526344; a[2403]= ; a[2404]= ; a[2405]= ; a[2406]= ; a[2407]= ; a[2408]= ; a[2409]= ; a[2410]= ; a[2411]= ; a[2412]= ; a[2413]= ; a[2414]= ; a[2415]= ; a[3202]= ; a[3203]= ; a[3204]= ; a[3205]= ; a[3206]= ; a[3207]= ; a[3208]= ; a[3209]= ; a[3210]= ; a[3211]= ; a[3212]= ; a[3213]= ; a[3214]= ; a[3215]= ; a[3216]=526344; a[4001]=526344; a[4002]= ; a[4003]= ; a[4004]= ; a[4005]= ; a[4006]= ; a[4007]= ; a[4008]= ; a[4009]= ; a[4010]= ; a[4011]= ; a[4012]= ; a[4013]= ; a[4014]= ; a[4015]= ; a[4016]= ; a[4801]= ; a[4802]= ; a[4803]= ; a[4804]= ; a[4805]= ; a[4806]= ; a[4807]= ; a[4808]= ;

44 INFOMOV Lecture 12 Snippets 46 Madness!? This is INFOMOV!

45 /INFOMOV/ END of Snippets next lecture: Grand Recap

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 10: Practical. Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 10: Practical. Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2015 - Lecture 10: Practical Welcome! Today s Agenda: DotCloud: profiling & high-level (1) DotCloud: low-level and blind stupidity DotCloud: high-level

More information

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 5: SIMD (1) Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 5: SIMD (1) Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2018 - Lecture 5: SIMD (1) Welcome! INFOMOV Lecture 5 SIMD (1) 2 Meanwhile, on ars technica INFOMOV Lecture 5 SIMD (1) 3 Meanwhile, the job market

More information

Sorting. Riley Porter. CSE373: Data Structures & Algorithms 1

Sorting. Riley Porter. CSE373: Data Structures & Algorithms 1 Sorting Riley Porter 1 Introduction to Sorting Why study sorting? Good algorithm practice! Different sorting algorithms have different trade-offs No single best sort for all scenarios Knowing one way to

More information

Welcome to PR3 The Art of Optimization

Welcome to PR3 The Art of Optimization Lecture 2 February 11th, 2014 IGAD Hopmanstraat, Breda > Recap > Demo Time > Basic Optimizations > Fixed Point Math Primer > Coding Time Lecture 2 February 11th, 2014 IGAD Hopmanstraat, Breda + Don t Optimize

More information

Quicksort (Weiss chapter 8.6)

Quicksort (Weiss chapter 8.6) Quicksort (Weiss chapter 8.6) Recap of before Easter We saw a load of sorting algorithms, including mergesort To mergesort a list: Split the list into two halves Recursively mergesort the two halves Merge

More information

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort Principles of Imperative Computation V. Adamchik CS 15-1 Lecture Carnegie Mellon University Sorting Sorting Sorting is ordering a list of objects. comparison non-comparison Hoare Knuth Bubble (Shell, Gnome)

More information

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place? Sorting Binary search works great, but how do we create a sorted array in the first place? Sorting in Arrays Sorting algorithms: Selection sort: O(n 2 ) time Merge sort: O(nlog 2 (n)) time Quicksort: O(n

More information

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 5: Caching (2) Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 5: Caching (2) Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2016 - Lecture 5: Caching (2) Welcome! Today s Agenda: Caching: Recap Data Locality Alignment False Sharing A Handy Guide (to Pleasing the Cache)

More information

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 4: Caching (2) Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 4: Caching (2) Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2017 - Lecture 4: Caching (2) Welcome! Today s Agenda: Caching: Recap Data Locality Alignment False Sharing A Handy Guide (to Pleasing the Cache)

More information

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Visibility. Welcome!

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Visibility. Welcome! INFOGR Computer Graphics J. Bikker - April-July 2016 - Lecture 11: Visibility Welcome! Smallest Ray Tracers: Executable 5692598 & 5683777: RTMini_minimal.exe 2803 bytes 5741858: ASM_CPU_Min_Exe 994 bytes

More information

CSE 373: Floyd s buildheap algorithm; divide-and-conquer. Michael Lee Wednesday, Feb 7, 2018

CSE 373: Floyd s buildheap algorithm; divide-and-conquer. Michael Lee Wednesday, Feb 7, 2018 CSE : Floyd s buildheap algorithm; divide-and-conquer Michael Lee Wednesday, Feb, 0 Warmup Warmup: Insert the following letters into an empty binary min-heap. Draw the heap s internal state in both tree

More information

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 10: GPGPU (3) Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 10: GPGPU (3) Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2018 - Lecture 10: GPGPU (3) Welcome! Today s Agenda: Don t Trust the Template The Prefix Sum Parallel Sorting Stream Filtering Optimizing GPU

More information

Lecture 16: Sorting. CS178: Programming Parallel and Distributed Systems. April 2, 2001 Steven P. Reiss

Lecture 16: Sorting. CS178: Programming Parallel and Distributed Systems. April 2, 2001 Steven P. Reiss Lecture 16: Sorting CS178: Programming Parallel and Distributed Systems April 2, 2001 Steven P. Reiss I. Overview A. Before break we started talking about parallel computing and MPI 1. Basic idea of a

More information

Real-world sorting (not on exam)

Real-world sorting (not on exam) Real-world sorting (not on exam) Sorting algorithms so far Insertion sort Worst case Average case Best case O(n 2 ) O(n 2 ) O(n) Quicksort O(n 2 ) O(n log n) O(n log n) Mergesort O(n log n) O(n log n)

More information

Sorting. Weiss chapter , 8.6

Sorting. Weiss chapter , 8.6 Sorting Weiss chapter 8.1 8.3, 8.6 Sorting 5 3 9 2 8 7 3 2 1 4 1 2 2 3 3 4 5 7 8 9 Very many different sorting algorithms (bubblesort, insertion sort, selection sort, quicksort, heapsort, mergesort, shell

More information

Sorting Algorithms Day 2 4/5/17

Sorting Algorithms Day 2 4/5/17 Sorting Algorithms Day 2 4/5/17 Agenda HW Sorting Algorithms: Review Selection Sort, Insertion Sort Introduce MergeSort Sorting Algorithms to Know Selection Sort Insertion Sort MergeSort Know their relative

More information

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 8: Data-Oriented Design. Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 8: Data-Oriented Design. Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2016 - Lecture 8: Data-Oriented Design Welcome! 2016, P2: Avg.? a few remarks on GRADING P1 2015: Avg.7.9 2016: Avg.9.0 2017: Avg.7.5 Learn about

More information

Mergesort again. 1. Split the list into two equal parts

Mergesort again. 1. Split the list into two equal parts Quicksort Mergesort again 1. Split the list into two equal parts 5 3 9 2 8 7 3 2 1 4 5 3 9 2 8 7 3 2 1 4 Mergesort again 2. Recursively mergesort the two parts 5 3 9 2 8 7 3 2 1 4 2 3 5 8 9 1 2 3 4 7 Mergesort

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

More information

InserDonSort. InserDonSort. SelecDonSort. MergeSort. Divide & Conquer? 9/27/12

InserDonSort. InserDonSort. SelecDonSort. MergeSort. Divide & Conquer? 9/27/12 CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James Lecture 11: SorDng //sort a[], an array of int for (int i = 1; i < a.length; i++) { int temp = a[i]; int k; for (k =

More information

Mergesort again. 1. Split the list into two equal parts

Mergesort again. 1. Split the list into two equal parts Quicksort Mergesort again 1. Split the list into two equal parts 5 3 9 2 8 7 3 2 1 4 5 3 9 2 8 7 3 2 1 4 Mergesort again 2. Recursively mergesort the two parts 5 3 9 2 8 7 3 2 1 4 2 3 5 8 9 1 2 3 4 7 Mergesort

More information

Better sorting algorithms (Weiss chapter )

Better sorting algorithms (Weiss chapter ) Better sorting algorithms (Weiss chapter 8.5 8.6) Divide and conquer Very general name for a type of recursive algorithm You have a problem to solve. Split that problem into smaller subproblems Recursively

More information

Chapter 7 Sorting. Terminology. Selection Sort

Chapter 7 Sorting. Terminology. Selection Sort Chapter 7 Sorting Terminology Internal done totally in main memory. External uses auxiliary storage (disk). Stable retains original order if keys are the same. Oblivious performs the same amount of work

More information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018

Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018 Integrated Introduction to Computer Science Fisler, Nelson Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018 Contents 1 In-Place Sorting 1 2 Swapping Elements in an Array 1 3 Bubble

More information

08 A: Sorting III. CS1102S: Data Structures and Algorithms. Martin Henz. March 10, Generated on Tuesday 9 th March, 2010, 09:58

08 A: Sorting III. CS1102S: Data Structures and Algorithms. Martin Henz. March 10, Generated on Tuesday 9 th March, 2010, 09:58 08 A: Sorting III CS1102S: Data Structures and Algorithms Martin Henz March 10, 2010 Generated on Tuesday 9 th March, 2010, 09:58 CS1102S: Data Structures and Algorithms 08 A: Sorting III 1 1 Recap: Sorting

More information

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms Comparison Based Sorting Algorithms Algorithms and Data Structures: Lower Bounds for Sorting Definition 1 A sorting algorithm is comparison based if comparisons A[i] < A[j], A[i] A[j], A[i] = A[j], A[i]

More information

Optimisation. CS7GV3 Real-time Rendering

Optimisation. CS7GV3 Real-time Rendering Optimisation CS7GV3 Real-time Rendering Introduction Talk about lower-level optimization Higher-level optimization is better algorithms Example: not using a spatial data structure vs. using one After that

More information

Overview of Sorting Algorithms

Overview of Sorting Algorithms Unit 7 Sorting s Simple Sorting algorithms Quicksort Improving Quicksort Overview of Sorting s Given a collection of items we want to arrange them in an increasing or decreasing order. You probably have

More information

SORTING AND SEARCHING

SORTING AND SEARCHING SORTING AND SEARCHING Today Last time we considered a simple approach to sorting a list of objects. This lecture will look at another approach to sorting. We will also consider how one searches through

More information

CSE 143. Two important problems. Searching and Sorting. Review: Linear Search. Review: Binary Search. Example. How Efficient Is Linear Search?

CSE 143. Two important problems. Searching and Sorting. Review: Linear Search. Review: Binary Search. Example. How Efficient Is Linear Search? Searching and Sorting [Chapter 9, pp. 402-432] Two important problems Search: finding something in a set of data Sorting: putting a set of data in order Both very common, very useful operations Both can

More information

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019 CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting Ruth Anderson Winter 2019 Today Sorting Comparison sorting 2/08/2019 2 Introduction to sorting Stacks, queues, priority queues, and

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1 Algorithms and Data Structures: Lower Bounds for Sorting ADS: lect 7 slide 1 ADS: lect 7 slide 2 Comparison Based Sorting Algorithms Definition 1 A sorting algorithm is comparison based if comparisons

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS Fast sorting algorithms Heapsort, Radixsort Summary of the previous lecture Fast sorting algorithms Shellsort Mergesort Quicksort Why these algorithm is called FAST? What

More information

Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort

Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort 1 Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort Michael Albert michael.albert@cs.otago.ac.nz Keywords: sorting, quicksort The limits of sorting performance Algorithms which sort

More information

Sorting. Dr. Baldassano Yu s Elite Education

Sorting. Dr. Baldassano Yu s Elite Education Sorting Dr. Baldassano Yu s Elite Education Last week recap Algorithm: procedure for computing something Data structure: system for keeping track for information optimized for certain actions Good algorithms

More information

Lecture 8: Mergesort / Quicksort Steven Skiena

Lecture 8: Mergesort / Quicksort Steven Skiena Lecture 8: Mergesort / Quicksort Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Give an efficient

More information

CSE 373: Data Structure & Algorithms Comparison Sor:ng

CSE 373: Data Structure & Algorithms Comparison Sor:ng CSE 373: Data Structure & Comparison Sor:ng Riley Porter Winter 2017 1 Course Logis:cs HW4 preliminary scripts out HW5 out à more graphs! Last main course topic this week: Sor:ng! Final exam in 2 weeks!

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Session 24. Earth Day, 2009 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3137 Announcements Homework 6 due before last class: May 4th Final Review May

More information

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing

More information

ECE 242 Data Structures and Algorithms. Advanced Sorting I. Lecture 16. Prof.

ECE 242 Data Structures and Algorithms.  Advanced Sorting I. Lecture 16. Prof. ECE 242 Data Structures and Algorithms http://www.ecs.umass.edu/~polizzi/teaching/ece242/ Advanced Sorting I Lecture 16 Prof. Eric Polizzi Sorting Algorithms... so far Bubble Sort Selection Sort Insertion

More information

CS1 Lecture 30 Apr. 2, 2018

CS1 Lecture 30 Apr. 2, 2018 CS1 Lecture 30 Apr. 2, 2018 HW 7 available very different than others you need to produce a written document based on experiments comparing sorting methods If you are not using a Python (like Anaconda)

More information

ECE 2574: Data Structures and Algorithms - Basic Sorting Algorithms. C. L. Wyatt

ECE 2574: Data Structures and Algorithms - Basic Sorting Algorithms. C. L. Wyatt ECE 2574: Data Structures and Algorithms - Basic Sorting Algorithms C. L. Wyatt Today we will continue looking at sorting algorithms Bubble sort Insertion sort Merge sort Quick sort Common Sorting Algorithms

More information

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) For this lab you may work with a partner, or you may choose to work alone. If you choose to work with a partner, you are still responsible for the lab

More information

Algorithmic Analysis. Go go Big O(h)!

Algorithmic Analysis. Go go Big O(h)! Algorithmic Analysis Go go Big O(h)! 1 Corresponding Book Sections Pearson: Chapter 6, Sections 1-3 Data Structures: 4.1-4.2.5 2 What is an Algorithm? Informally, any well defined computational procedure

More information

Lecture Notes 14 More sorting CSS Data Structures and Object-Oriented Programming Professor Clark F. Olson

Lecture Notes 14 More sorting CSS Data Structures and Object-Oriented Programming Professor Clark F. Olson Lecture Notes 14 More sorting CSS 501 - Data Structures and Object-Oriented Programming Professor Clark F. Olson Reading for this lecture: Carrano, Chapter 11 Merge sort Next, we will examine two recursive

More information

Sorting Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Sorting Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Sorting Algorithms CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 QuickSort Divide-and-conquer approach to sorting Like

More information

CS125 : Introduction to Computer Science. Lecture Notes #40 Advanced Sorting Analysis. c 2005, 2004 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #40 Advanced Sorting Analysis. c 2005, 2004 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #40 Advanced Sorting Analysis c 2005, 2004 Jason Zych 1 Lecture 40 : Advanced Sorting Analysis Mergesort can be described in this manner: Analyzing

More information

CMPSCI 187 / Spring 2015 Sorting Kata

CMPSCI 187 / Spring 2015 Sorting Kata Due on Thursday, April 30, 8:30 a.m Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 Contents Overview 3 Learning Goals.................................................

More information

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Merge Sort & Quick Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures ITEC2620 Introduction to Data Structures Lecture 5a Recursive Sorting Algorithms Overview Previous sorting algorithms were O(n 2 ) on average For 1 million records, that s 1 trillion operations slow! What

More information

Algorithmic Analysis and Sorting, Part Two

Algorithmic Analysis and Sorting, Part Two Algorithmic Analysis and Sorting, Part Two Friday Four Square! 4:15PM, Outside Gates An Initial Idea: Selection Sort An Initial Idea: Selection Sort 4 1 2 7 6 An Initial Idea: Selection Sort 4 1 2 7 6

More information

Practical SIMD Programming

Practical SIMD Programming Practical SIMD Programming Supplemental tutorial for INFOB3CC, INFOMOV & INFOMAGR Jacco Bikker, 2017 Introduction Modern CPUs increasingly rely on parallelism to achieve peak performance. The most well-known

More information

Performance Improvement. The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 7

Performance Improvement. The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 7 Performance Improvement The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 7 1 For Your Amusement Optimization hinders evolution. -- Alan Perlis

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

ECE 242 Data Structures and Algorithms. Advanced Sorting II. Lecture 17. Prof.

ECE 242 Data Structures and Algorithms.  Advanced Sorting II. Lecture 17. Prof. ECE 242 Data Structures and Algorithms http://www.ecs.umass.edu/~polizzi/teaching/ece242/ Advanced Sorting II Lecture 17 Prof. Eric Polizzi Sorting Algorithms... so far Bubble Sort Selection Sort Insertion

More information

CS61B Lectures # Purposes of Sorting. Some Definitions. Classifications. Sorting supports searching Binary search standard example

CS61B Lectures # Purposes of Sorting. Some Definitions. Classifications. Sorting supports searching Binary search standard example Announcements: CS6B Lectures #27 28 We ll be runningapreliminarytestingrun for Project #2 on Tuesday night. Today: Sorting algorithms: why? Insertion, Shell s, Heap, Merge sorts Quicksort Selection Distribution

More information

CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING

CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING ASSORTED MINUTIAE HW6 Out Due next Wednesday ASSORTED MINUTIAE HW6 Out Due next Wednesday Only two late days allowed ASSORTED MINUTIAE HW6 Out Due

More information

COMP2012H Spring 2014 Dekai Wu. Sorting. (more on sorting algorithms: mergesort, quicksort, heapsort)

COMP2012H Spring 2014 Dekai Wu. Sorting. (more on sorting algorithms: mergesort, quicksort, heapsort) COMP2012H Spring 2014 Dekai Wu Sorting (more on sorting algorithms: mergesort, quicksort, heapsort) Merge Sort Recursive sorting strategy. Let s look at merge(.. ) first. COMP2012H (Sorting) 2 COMP2012H

More information

Sorting and Searching Algorithms

Sorting and Searching Algorithms Sorting and Searching Algorithms Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - Faner 3131 1 Outline Introduction to Sorting

More information

Pipeline implementation II

Pipeline implementation II Pipeline implementation II Overview Line Drawing Algorithms DDA Bresenham Filling polygons Antialiasing Rasterization Rasterization (scan conversion) Determine which pixels that are inside primitive specified

More information

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting)

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting) IS 709/809: Computational Methods in IS Research Algorithm Analysis (Sorting) Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Sorting Problem Given an

More information

INFOGR Computer Graphics. Jacco Bikker - April-July Lecture 3: Ray Tracing (Introduction) Welcome!

INFOGR Computer Graphics. Jacco Bikker - April-July Lecture 3: Ray Tracing (Introduction) Welcome! INFOGR Computer Graphics Jacco Bikker - April-July 2016 - Lecture 3: Ray Tracing (Introduction) Welcome! Today s Agenda: Primitives (contd.) Ray Tracing Intersections Assignment 2 Textures INFOGR Lecture

More information

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care? Where does a picture come from? Rasterization and Graphics Hardware CS559 Course Notes Not for Projection November 2007, Mike Gleicher Result: image (raster) Input 2D/3D model of the world Rendering term

More information

Data structures. More sorting. Dr. Alex Gerdes DIT961 - VT 2018

Data structures. More sorting. Dr. Alex Gerdes DIT961 - VT 2018 Data structures More sorting Dr. Alex Gerdes DIT961 - VT 2018 Divide and conquer Very general name for a type of recursive algorithm You have a problem to solve: - Split that problem into smaller subproblems

More information

Information Coding / Computer Graphics, ISY, LiTH

Information Coding / Computer Graphics, ISY, LiTH Sorting on GPUs Revisiting some algorithms from lecture 6: Some not-so-good sorting approaches Bitonic sort QuickSort Concurrent kernels and recursion Adapt to parallel algorithms Many sorting algorithms

More information

Sorting Pearson Education, Inc. All rights reserved.

Sorting Pearson Education, Inc. All rights reserved. 1 19 Sorting 2 19.1 Introduction (Cont.) Sorting data Place data in order Typically ascending or descending Based on one or more sort keys Algorithms Insertion sort Selection sort Merge sort More efficient,

More information

Lecture 17: Array Algorithms

Lecture 17: Array Algorithms Lecture 17: Array Algorithms CS178: Programming Parallel and Distributed Systems April 4, 2001 Steven P. Reiss I. Overview A. We talking about constructing parallel programs 1. Last time we discussed sorting

More information

LECTURE 17. Array Searching and Sorting

LECTURE 17. Array Searching and Sorting LECTURE 17 Array Searching and Sorting ARRAY SEARCHING AND SORTING Today we ll be covering some of the more common ways for searching through an array to find an item, as well as some common ways to sort

More information

CSE 373: Data Structures & Algorithms More Sor9ng and Beyond Comparison Sor9ng

CSE 373: Data Structures & Algorithms More Sor9ng and Beyond Comparison Sor9ng CSE 373: Data Structures & More Sor9ng and Beyond Comparison Sor9ng Riley Porter Winter 2017 1 Course Logis9cs HW5 due in a couple days à more graphs! Don t forget about the write- up! HW6 out later today

More information

What is sorting? Lecture 36: How can computation sort data in order for you? Why is sorting important? What is sorting? 11/30/10

What is sorting? Lecture 36: How can computation sort data in order for you? Why is sorting important? What is sorting? 11/30/10 // CS Introduction to Computation " UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department Professor Andrea Arpaci-Dusseau Fall Lecture : How can computation sort data in order for you? What is sorting?

More information

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Acceleration. Welcome!

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Acceleration. Welcome! INFOGR Computer Graphics J. Bikker - April-July 2015 - Lecture 11: Acceleration Welcome! Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH

More information

Drawing Fast The Graphics Pipeline

Drawing Fast The Graphics Pipeline Drawing Fast The Graphics Pipeline CS559 Spring 2016 Lecture 10 February 25, 2016 1. Put a 3D primitive in the World Modeling Get triangles 2. Figure out what color it should be Do ligh/ng 3. Position

More information

INFOGR Computer Graphics

INFOGR Computer Graphics INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - April-July 2018 Lecture 4: Graphics Fundamentals Welcome! Today s Agenda: Rasters Colors Ray Tracing Assignment P2 INFOGR Lecture 4 Graphics Fundamentals

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Sorting o Simple: Selection Sort and Insertion Sort o Efficient: Quick Sort and Merge Sort Searching o Linear o Binary Reading for this lecture: http://introcs.cs.princeton.edu/python/42sort/

More information

COMP 250. Lecture 7. Sorting a List: bubble sort selection sort insertion sort. Sept. 22, 2017

COMP 250. Lecture 7. Sorting a List: bubble sort selection sort insertion sort. Sept. 22, 2017 COMP 250 Lecture 7 Sorting a List: bubble sort selection sort insertion sort Sept. 22, 20 1 Sorting BEFORE AFTER 2 2 2 Example: sorting exams by last name Sorting Algorithms Bubble sort Selection sort

More information

CS251 Spring 2014 Lecture 7

CS251 Spring 2014 Lecture 7 CS251 Spring 2014 Lecture 7 Stephanie R Taylor Feb 19, 2014 1 Moving on to 3D Today, we move on to 3D coordinates. But first, let s recap of what we did in 2D: 1. We represented a data point in 2D data

More information

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014 CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting Aaron Bauer Winter 2014 The main problem, stated carefully For now, assume we have n comparable elements in an array and we want

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)

More information

CS 61C: Great Ideas in Computer Architecture. The Flynn Taxonomy, Intel SIMD Instructions

CS 61C: Great Ideas in Computer Architecture. The Flynn Taxonomy, Intel SIMD Instructions CS 61C: Great Ideas in Computer Architecture The Flynn Taxonomy, Intel SIMD Instructions Guest Lecturer: Alan Christopher 3/08/2014 Spring 2014 -- Lecture #19 1 Neuromorphic Chips Researchers at IBM and

More information

Project 1, 467. (Note: This is not a graphics class. It is ok if your rendering has some flaws, like those gaps in the teapot image above ;-)

Project 1, 467. (Note: This is not a graphics class. It is ok if your rendering has some flaws, like those gaps in the teapot image above ;-) Project 1, 467 Purpose: The purpose of this project is to learn everything you need to know for the next 9 weeks about graphics hardware. What: Write a 3D graphics hardware simulator in your language of

More information

CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting. Dan Grossman Fall 2013

CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting. Dan Grossman Fall 2013 CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting Dan Grossman Fall 2013 Introduction to Sorting Stacks, queues, priority queues, and dictionaries all focused on providing one element

More information

Active Learning: Sorting

Active Learning: Sorting Lecture 32 Active Learning: Sorting Why Is Sorting Interesting? Sorting is an operation that occurs as part of many larger programs. There are many ways to sort, and computer scientists have devoted much

More information

2/26/2016. Divide and Conquer. Chapter 6. The Divide and Conquer Paradigm

2/26/2016. Divide and Conquer. Chapter 6. The Divide and Conquer Paradigm Divide and Conquer Chapter 6 Divide and Conquer A divide and conquer algorithm divides the problem instance into a number of subinstances (in most cases 2), recursively solves each subinsance separately,

More information

Sorting. Bubble Sort. Selection Sort

Sorting. Bubble Sort. Selection Sort Sorting In this class we will consider three sorting algorithms, that is, algorithms that will take as input an array of items, and then rearrange (sort) those items in increasing order within the array.

More information

Sorting. Quicksort analysis Bubble sort. November 20, 2017 Hassan Khosravi / Geoffrey Tien 1

Sorting. Quicksort analysis Bubble sort. November 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Sorting Quicksort analysis Bubble sort November 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Quicksort analysis How long does Quicksort take to run? Let's consider the best and the worst case These differ

More information

Sorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements.

Sorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements. Sorting Sorting is ordering a list of elements. Types of sorting: There are many types of algorithms exist based on the following criteria: Based on Complexity Based on Memory usage (Internal & External

More information

Elementary maths for GMT. Algorithm analysis Part II

Elementary maths for GMT. Algorithm analysis Part II Elementary maths for GMT Algorithm analysis Part II Algorithms, Big-Oh and Big-Omega An algorithm has a O( ) and Ω( ) running time By default, we mean the worst case running time A worst case O running

More information

GPU Computation Strategies & Tricks. Ian Buck NVIDIA

GPU Computation Strategies & Tricks. Ian Buck NVIDIA GPU Computation Strategies & Tricks Ian Buck NVIDIA Recent Trends 2 Compute is Cheap parallelism to keep 100s of ALUs per chip busy shading is highly parallel millions of fragments per frame 0.5mm 64-bit

More information

Visualizing Data Structures. Dan Petrisko

Visualizing Data Structures. Dan Petrisko Visualizing Data Structures Dan Petrisko What is an Algorithm? A method of completing a function by proceeding from some initial state and input, proceeding through a finite number of well defined steps,

More information

Sorting. Task Description. Selection Sort. Should we worry about speed?

Sorting. Task Description. Selection Sort. Should we worry about speed? Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest

More information

Giri Narasimhan. COT 5993: Introduction to Algorithms. ECS 389; Phone: x3748

Giri Narasimhan. COT 5993: Introduction to Algorithms. ECS 389; Phone: x3748 COT 5993: Introduction to Algorithms Giri Narasimhan ECS 389; Phone: x3748 giri@cs.fiu.edu www.cs.fiu.edu/~giri/teach/5993s05.html 1/13/05 COT 5993 (Lec 2) 1 1/13/05 COT 5993 (Lec 2) 2 Celebrity Problem

More information

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines COMP30019 Graphics and Interaction Scan Converting Polygons and Lines Department of Computer Science and Software Engineering The Lecture outline Introduction Scan conversion Scan-line algorithm Edge coherence

More information

Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang

Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Last class Review some algorithms learned in previous classes idea => pseudocode => implementation Correctness? Three sorting algorithms:

More information

This is a set of tiles I made for a mobile game (a long time ago). You can download it here:

This is a set of tiles I made for a mobile game (a long time ago). You can download it here: Programming in C++ / FASTTRACK TUTORIALS Introduction PART 11: Tiles It is time to introduce you to a great concept for 2D graphics in C++, that you will find very useful and easy to use: tilemaps. Have

More information

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist.

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist. Sorting Popular algorithms: Selection sort* Insertion sort* Bubble sort* Quick sort* Comb-sort Shell-sort Heap sort* Merge sort* Counting-sort Radix-sort Bucket-sort Tim-sort Many algorithms for sorting

More information

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Scan Converting Lines, Circles and Ellipses Hello everybody, welcome again

More information

Hidden surface removal. Computer Graphics

Hidden surface removal. Computer Graphics Lecture Hidden Surface Removal and Rasterization Taku Komura Hidden surface removal Drawing polygonal faces on screen consumes CPU cycles Illumination We cannot see every surface in scene We don t want

More information

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY Lecture 10 CS2110 Fall 2016 Miscellaneous 2 A3 due Monday night. Group early! Only 325 views of the piazza A3 FAQ yesterday morning. Everyone should

More information