Andre Badal – Homework 06 1) What is data structure? A: Way to organize data. 2) Write the Java code to assign the integer value 43 to a variable named myInt. A: int myInt = 43; 3) Write the Java code to get the value that is stored inside a variable named myInt. A: int myInt(){ Return myInt; } 4) Write the Java code to assign the String value "red" to a variable named color. NOTE: In Java, the data type String is spelled with a capital S. A: String color = “red”; 5) Write the Java code to get the value that is stored inside a variable named color. A: String color(){ Return color; } 6) What is an array? A: Collection of data. Suppose I have 3 pets named: rover, whiskers, and birdie Suppose I want to use an array to store the names of my 3 pets. Suppose I want to name my array "pets." 7) Using pencil and paper, or a computer, draw a sketch of the array. In your sketch, do not forget to include the name of the array. 8) Write the Java code to set the values of the array. pets[0] = “rover”; pets[1] = “whiskers”; pets[2] = “birdie”; 9) Write the Java code to get the values that are stored in the array. pet[0] pet[1] pet[2] 10) What is a stack? Type of list – last in, first out 11) Suppose I have a stack that looks like this: Suppose I push the string "mousey" onto this stack. With pencil and paper, or with a computer, draw what the stack looks like. Don't forget to include the stack pointer in your drawing. 12) Suppose I have a stack that looks like this: Suppose I pop the stack. What value is popped off? With pencil and paper, or with a computer, draw what the stack looks like. Don't forget to include the stack pointer in your drawing. 13) What is a queue? Special kind of list – new position can be inserted only at end of list and removed from the beginning 14) Suppose I have a queue that looks like this: Suppose I enqueue the string "mousey" onto this queue. With pencil and paper, or with a computer, draw what the queue looks like. Don't forget to include the pointers in your drawing. 15) Suppose I have a queue that looks like this: Suppose I dequeue the queue. What value is retrieved from the queue? With pencil and paper, or with a computer, draw what the queue looks like. Don't forget to include the pointers in your drawing. 16) What is a linked list? Special kind of list – new value can be inserted & removed anywhere. 17) Suppose I have a linked list that looks like this: Suppose I want to add the name "mousey" to the head of the linked list. With pencil and paper, or with a computer, draw what the linked list looks like. Don't forget to include the head pointer in your drawing. 18) Suppose I have a linked list that looks like this: Suppose I want to add the name "mousey" between "birdie" and "whiskers." With pencil and paper, or with a computer, draw what the linked list looks like. Don't forget to include the head pointer in your drawing. 19) Suppose I have a linked list that looks like this: Suppose I want to add the name "mousey" after "rover." With pencil and paper, or with a computer, draw what the linked list looks like. Don't forget to include the head pointer in your drawing. 20) Suppose I have a linked list that looks like this: Suppose I want to remove "birdie" from this linked list. With pencil and paper, or with a computer, draw what the linked list looks like. Don't forget to include the head pointer in your drawing. 21) Suppose I have a linked list that looks like this: Suppose I want to remove "whiskers" from this linked list. With pencil and paper, or with a computer, draw what the linked list looks like. Don't forget to include the head pointer in your drawing. 22) Suppose I have a linked list that looks like this: Suppose I want to remove "rover" from this linked list. With pencil and paper, or with a computer, draw what the linked list looks like. Don't forget to include the head pointer in your drawing. 23) What is a binary search tree? I had to search this on Wiki (https://en.wikipedia.org/wiki/Binary_search_tree) and learn more: “a binary search tree, also called an ordered or sorted binary tree, is a rooted binary tree whose internal nodes each store a key greater than all the keys in the node's left subtree and less than those in its right subtree” & “A binary search tree makes searching faster” Here is a binary search tree. 24) Search this binary search tree for the word mud. Which nodes does the search visit? HINT: A binary search starts at the top of the tree and slowly progresses downward until either the search finds the word or the search reaches the bottom of the tree. A: leg > sky > nit > mud 25) Who are children of sky? A: nit & vat 26) Who is the parent of sky A: leg 27) Who is the root node? A: leg 28) What is sorting? A: putting things in alpha/numerical order 29) Suppose I have this array. pets Suppose I sort this array. With pencil and paper, or with a computer, draw a sketch of the sorted array. 30) What is selection sort? Type of sort - Finds the smallest value and moves it to the top 31) Suppose I have this array. pets What is the smallest alphabetical value in the array? A: birdie 32) Suppose I have this array. pets Suppose I swap birdie with rover. With pencil and paper, or with a computer, draw the following 3 sketches: sketch of the array before the swap sketch showing the swap sketch of the array after the swap Please forgive the extra “s” on “rover” – I couldn’t figure out how to easily remove it but fixed it future. 33) Suppose I have this array. Suppose the array is divided into two halves: row 0 rows 1 and 2 pets What is the smallest alphabetical value in the lower half of the array? A: rover 34) Suppose I have this array. pets Suppose I swap rover with whiskers. With pencil and paper, or with a computer, draw the following 3 sketches: sketch of the array before the swap sketch showing the swap sketch of the array after the swap 35) What is bubble sort? bubble sort selects the bottom 2 elements and sorts them according to the lowest value and continues to move up, repeating the process. 36) Suppose I have this array. pets Which is alphabetically smaller: birdie or whiskers? A: birdie 37) Suppose I have this array. pets Suppose I swap birdie with whiskers. With pencil and paper, or with a computer, draw the following 3 sketches: sketch of the array before the swap sketch showing the swap sketch of the array after the swap 38) Suppose I have this array: pets Which is alphabetically smaller: rover or birdie? A: birdie 39) Suppose I have this array: pets Suppose I swap rover with birdie. With pencil and paper, or with a computer, draw the following 3 sketches: sketch of the array before the swap sketch showing the swap sketch of the array after the swap 40) Suppose I have this array: Which is alphabetically smaller: rover or whiskers? A: rover