25. Bubble sort
/Bubble sort
Bubble sort is one of the simplest algorithms and works by repeatedly
swapping the adjacent elements if they are in wrong order.
1st step
[7,5,9,0,3] —> [5,7,9,0,3]
2nd step
[5,7,9,0,3] —> [5,7,9,0,3]
3rd step
[5,7,9,0,3] —> [5,7,0,9,3]
4th step
[5,7,0,9,3] —> [5,7,0,3,9]
9 has “bubbled” up to the end of the array. Hence, bubble sort.
After iterating the highest number will bubble to the top of the array.
(Depends on the way the algorithm is implemented, either the highest
number goes to the back or the smallest number comes to the front)
27. Insertion sort
/Insertion sort
Fun fact: Insertion sort can sort arrays as it receives the elements, which
makes it a good algorithm for the internet if you receive real time data that
needs sorting (Don’t ask me how).
Insertion sort divides the array to two segments → sorted and unsorted segments
1st step
[11,-69,25,0,86,12,6] → [-69,11,25,0,86,12,6]
2nd step
[-69,11,25,0,86,12,6] → [-69,11,25,0,86,12,6]
3rd step
[-69,11,25,0,86,12,6] → [-69,0,11,25,86,12,6]
4th step
[-69,0,11,25,86,12,6] → [-69,0,11,25,86,12,6]
5th step
[-69,0,11,25,86,12,6] → [-69,0,11,12,25,86,6]
6th step
[-69,0,11,12,25,86,6] → [-69,0,6,11,12,25,86]
29. Quick sort
/Quick sort
Quick sort is also a divide and conquer algorithm which utilizing a pivot point (Item starting
from left > pivot, item starting from right < pivot)
[14,3,-56,42,56,21]
[-
56,3,14,42,56,21]
[-56,3,14] [42,56,21]
[21,42,56]
[-56,3,14,21,42,56]
Always remember, quicksort = pivot!
30. /Programming logic
Programming logic
/ Find unique integer
Given an array of positive integers. One integer is not
repeated while all others are repeated. Find the integer that
is not repeated.
Example: Input → [1,9,15,67,2,9,1,2,67] Output → 15 ( as 15
only appears once)
31. Programming logic
/ Rotate array
Given an array of integer numbers and a separate integer, n,
“rotate” the first n (0 <= n <= 10^5) elements in the array to
the end of the array.
Example: Input → [1,2,3,4,5,6], n = 2 Output → [3,4,5,6,1,2]
32. INDEX.HTML
/Basic dynamic programming
Memoization → It’s a “top-down” problem solving method
where the code stores the outputs of certain inputs thus
increasing the efficiency of future computations.
33. Dynamic
Programming
/Fibonacci Sequence
Create a function that takes in an integer argument and
recursively outputs the corresponding fibonacci sequence
number.
Example: Input —> n = 5, Output = 5
Input –> n = 8, Output = 21
35. CREDITS: This presentation template was created by Slidesgo,
including icons by Flaticon, and infographics & images by
Freepik
/THANKS!
/3DC
3dc@club.sutd.edu.sg
BYE BYE
Last in first out
Fundamentally important when you want to reverse the order of insertion, common day applications are simulation of cafeteria trays etc
Explain each function, open source code
Queueing up at a cafeteria imagery
Queueing up at a cafeteria imagery
FIFO
Commonly used in computer processes, e.g. printer queues
Explain each function, open source code for Stack
FIFO
Commonly used in computer processes, e.g. printer queues