Advertisement
Auios

Untitled

Dec 12th, 2018
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. ~~~~~~~~~~~~~~~~~~~~~~~
  2. ~~~ Data Structures ~~~
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Week 1 - Friday, September 7th, 2018:
  5. Class:
  6. Introduction to the course
  7.  
  8. Week 2 - Monday
  9.  
  10. Week 3 -
  11.  
  12. Week 4 - Monday, September 24th, 2018:
  13. Class:
  14. Stacks and Queues
  15. Stack - FILO
  16. Queue - FIFO
  17.  
  18. Operation Stack Queue
  19. -------------------------------------------------------
  20. add an item push enqueue
  21. remove an item pop dequeue
  22. access the "next" item to be removed top front
  23.  
  24. Socket Programming
  25.  
  26. Week 4 - Friday, September 28th, 2018:
  27. Class:
  28. Lab 4 is bracket checking.
  29. Make a function that examines a string and determines if all the open brackets get closed.
  30. - They must also close in the proper order
  31. Use a stack data structure to push open brackets and pop closing brackets. Upon popping you check if the current one you are
  32. popping match the current closing bracket character.
  33.  
  34.  
  35. Introduction to HashTables
  36.  
  37.  
  38.  
  39. Assignment 1 - Priority queue
  40. Everytime you search something the access count is increased by 1. The node is moved closer to the front such that the access cunt within the
  41. linked list i
  42.  
  43. Part 1 - print 10 sheets of paper, draw on it. - Due monday
  44.  
  45. erase(first, last) - it erases starting at first but does not delete the last one
  46.  
  47. search(14) - find node that has data 14, increase the access count. Move the node up the list to where it belongs
  48.  
  49. Week 5 - Monday, October 1st, 2018:
  50. * Copy constructor vs copy assignment
  51. * Biggest advantage for hash table - get access to any row given that you know its hash. O(1) operation
  52.  
  53. Dealing with collisions
  54. * Bucketing
  55. You can make it a two dimensional array in a sense.
  56. It is very inefficient because there will be lots of wasted space.
  57.  
  58. Lambda is the number of entries divided by the number of buckets
  59. 8 entries / 6 buckets = 1.33
  60. avg search = (4 + 2 * 3 + 3) / 8
  61. 13 / 8 = 1.625
  62.  
  63. Week 5 - Friday, October 5th, 2018:
  64. ---
  65.  
  66. Week 6 - Friday, October 12th, 2018:
  67. Quick Sort
  68. Pick a value from the array as the pivot
  69.  
  70. Let i=front, j= back
  71.  
  72. advance i until you find a value arr[i] > pivot
  73.  
  74. move j towards front of array until arr[j] < pivot
  75.  
  76. swap these arr[i] and arr[j].
  77.  
  78. repeat step 3 to 5 until i and j meet
  79.  
  80. The meeting point is used to break the array up into two pieces
  81.  
  82. QuickSort these two new arrays
  83.  
  84. Part 3 is easy to do if you use recursion
  85. Fill until you reach a different color
  86.  
  87. Image height that he was using was something
  88.  
  89. 7, 4, 3, 6, 1, 2, 5, 8
  90. ^
  91. Pivot
  92.  
  93. Make two arrays:
  94. Array 1: Everything < than the pivot
  95. Array 2: Everything > than the pivot
  96.  
  97.  
  98.  
  99. bool fill(PixMap& image, const Pixel& fillColour, unt x, int y, const Pixel& orig)
  100. {
  101. bool rc = false;
  102. if(x < 0 || y >= image.height() || x >= image.width() || y < 0)
  103. {
  104. rc = false
  105. }
  106. else if(image.getPixel(x,y) == orig)
  107. {
  108. rc = true;
  109. image.setPixel(fillColour, x, y);
  110. fill(image, fillColour, x + 1, y, orig);
  111. fill(image, fillColour, x-1, y, orig);
  112. fill(image, fillColou, x, y+ 1, orig);
  113. fill(image, fillColour, x, y-1, orig);
  114. }
  115. return rc;
  116. }
  117.  
  118. bool fill(PixMap& image, const Pixel& fillColour, int x, int y)
  119. {
  120. Pixel originColor = image.getPixel(x,y);
  121. return fill(image, fillColour, x, y, origColour);
  122. }
  123.  
  124. Week 5 - Monday, October 15th, 2018:
  125. === Midterm review ===
  126. Q1:
  127. What is the run time of the following functions:
  128.  
  129. int f1(int n){
  130. int rc=1; // 1
  131. for(int i=0;i<5;i++){ // 3
  132. rc+=1; // 1
  133. }
  134. return rc;
  135. }
  136.  
  137. Does the number of operations depend on n?
  138. No
  139. O(1)
  140.  
  141. Q2:
  142. int f1(int n){
  143. int rc=1; // 1
  144. for(int i=0;i<n;i+=2){ // n * 3
  145. rc+=1; // n * 1
  146. }
  147. return rc;
  148. }
  149. O(n/2)
  150. O(n)
  151.  
  152. Q3:
  153.  
  154. Suppose that the function function1(n) has a run time of O(n) and function2(n) has a run time of O(n^2) What is the run time of the following function?
  155.  
  156. int f1(int n){
  157. function1(n); // O(n)
  158. function2(n); // O(n^2)
  159. }
  160.  
  161. O(n + n^2)
  162. O(n^2)
  163.  
  164. Q4:
  165.  
  166. Write the following function recursively:
  167.  
  168. bool isPalindrome(const char* s)
  169.  
  170. s is a null terminated character string. This function returns true if s is a palindrome.
  171. A palindrome is a string that reads the same forwards and backwards.
  172. Thus: noon, mom, dad are all palindromes. table, texture, glass are not palindromes.
  173.  
  174. the above function can be a wrapper to a function that actually does the work
  175.  
  176. Try to write the function to O(n) run time where n is the length of s.
  177.  
  178. //BAD
  179. bool isPalindrome(const char* s){
  180. for(i=0; i < strlen(s); i++)
  181. if(s[i] != s[strlen(s)-i])
  182. return false;
  183. return true;
  184. }
  185. //
  186.  
  187. bool isPalindrome(const char* s){
  188. int len = strlen(s);
  189. return isPalindrome(s, len);
  190. }
  191.  
  192. bool isPalindrome(char* str, int len){
  193. bool res = false;
  194. if(len == 0 || len == 1)
  195. res = true;
  196. else
  197. if((str[0] == str[len - 1]) && (isPalindrome(&str[1], len - 2)))
  198. res = true;
  199. else
  200. res = false;
  201. return res;
  202. }
  203.  
  204. O(n)
  205.  
  206. Q5:
  207.  
  208. Given the following:
  209.  
  210. class Stack{
  211. ...
  212. public:
  213. void push(int v);
  214. void pop();
  215. int top();
  216. bool isEmpty();
  217. };
  218.  
  219. and
  220.  
  221. class Queue{
  222. ...
  223. public:
  224. void enqueue(int v);
  225. void dequeue();
  226. int front();
  227. bool isEmpty();
  228.  
  229. };
  230.  
  231. Write the function:
  232.  
  233. void ReOrder(int newarr[], int arr[],int size);
  234.  
  235. This function creates newarr from the values in arr using the following rules:
  236.  
  237. size is length of arr
  238. The value 0 separates arr into "chunks"
  239. Each "chunk" can hold both positive and negative values in any order
  240.  
  241. When creating newarr, each chunk must satisfy the following rules
  242.  
  243. All negative values go before all positive values
  244. All negative values are added in the same order as their original order.
  245. All positive values are added opposite to their original order
  246. The 0 that was used to separate each chunk is not added to newarr.
  247.  
  248. Example:
  249.  
  250. Suppose arr={-3,2,-1,5,1,-4,0,11,12,13,-11,-12};
  251. then when you create newarr, newarr should have the following:
  252. {-3,-1,-4,1,5,2,-11,-12,13,12,11}
  253.  
  254. Week 7? - Monday, October 29th, 2018:
  255.  
  256. Lab 5 is basically quick sort.
  257. Given lab5.cpp and timer.cpp and timer.h
  258.  
  259. rand() generates a random unsigned integer.
  260. srand() seeds the random values
  261.  
  262. void generateRandom(int array[], int sz)
  263. {
  264. for(int i = 0; i < sz; i++)
  265. {
  266. array[i] = rand();
  267. }
  268. }
  269.  
  270. Change position of the pivot point to see if the position of the pivot matters
  271. (Beginning, middle, end, random pivot)
  272.  
  273. --- Assignment 2 --- Due November 14th, 2018 (or 2 weeks, 2 days from now)
  274.  
  275. Assignment is about hashing
  276. You are given a table class
  277. Use linear probing as its collision method
  278.  
  279. Determine the runtime of the functions. Functions are not implemented in the best way possible.
  280. So we have to make them more efficient.
  281. Part A - Determine runtime
  282. Part B - Suggest 3 improvements (Do it in code and comment - Probably should use a Wiki)
  283. Part C - Hash table organizes
  284. Part D - Measure performance
  285.  
  286. Load factor:
  287. You have 100 available slots but only have 5 items. The load factor is 5%
  288. If the load factor is very low youll expect few or no collisions (Good)
  289. If you have a load factor of 90% you should expect many collisions (Bad)
  290.  
  291. ---------------------------------------------------------------
  292.  
  293. === Heap and Heap Sort ===
  294. The binary heap is an implementation of a Priority Queue.
  295.  
  296. Basic operations on the binary Heap include:
  297. insert - add an item to the binary heap O(n log n)
  298. delete - removed the item with the highest priority in the binary heap O(n log n)
  299.  
  300. sort - O(n log n)
  301.  
  302. Everytime you insert something into this heap you must re-organize it.
  303.  
  304. Week 8 - Monday, November 5th, 2018
  305. Binary trees
  306.  
  307. A binary tree is where every node has a left and right child.
  308.  
  309. A sub tree is a tree within itself
  310.  
  311.  
  312. inOrder(left, root, right);
  313. 1. Traverse the lft subtree in inOrder
  314. 2. Process the root
  315. 3. Traverse the right subtree in inOrder
  316.  
  317. ---------------------------------------------------------------
  318.  
  319. Week 8 - Friday, November 9th, 2018
  320.  
  321. AVL Trees
  322. The principle behind AVL trees is that the depth of the nodes on the left and right should not be off more than 1
  323. If their depths are off by a depth of more than 1 then it's unbalanced.
  324. Search time of a perfectly balanced tree is O(log n)
  325. Insert and delete can also be done in O(log n)
  326.  
  327. Height balance = height of right - height of left
  328. of node subtree subtree
  329.  
  330. if Height balance is positive then rotate left
  331. if Height balance is negative then rotate right
  332.  
  333. ---------===========---------==========------------==========
  334.  
  335. Final Exam Review
  336.  
  337. No sorting
  338. Recursion
  339. Order of magnitude analysis
  340. No linear probing
  341. Heaps
  342. All the trees
  343. Graphs
  344. P vs NP problem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement