Connecting with Computer Science Chapter 8 Review: Chapter Summary Data Structures are used to organize data.. To define an array, you must specify the array: name, type and size..
Trang 1Connecting with Computer Science Chapter 8 Review:
Chapter Summary
Data Structures are used to organize data
Arrays are stored in continuous memory cells (one right after the other)
To define an array, you must specify the array: name, type and size
A single-dimensional array is a structure consisting of one level of array elements
A multiple-dimensional array is a structure consisting of more than one level, and each level consists
of an array
The array's size is stored internally by using an upper and lower bound
A pointer is a memory variable that points to a memory cell location
A linked list is a data structure that can be used when the size of the information to be stored is un-known or will change Stacks and queues are forms of linked lists
A stack uses a last in, first out (LIFO) structure
A queue uses a first in, first out (FIFO) structure
A tree data structure represents a hierarchical storage method
Each position in a tree is called a node
Binary search trees are efficient for searching information
There is a wide variety of sorting algorithms, including: selection, bubble, quick-sort, merge,
insertion and shell sorts.
Trang 2Key Terms:
value is greater than the parent node's
than the second it swaps them, and then repeats this process until it makes a pass all the way through the list without swapping any items
from the stack is the first item placed onto the stack
list points to the next element in line and does not have to be contiguous with the previous element
item in the next position to be filled
charts
Trang 3Test Yourself:
1.) Describe the uses of an array
in the order it was entered in the array Arrays can be used to store student grades, book titles, names of college courses, a space shuttle launch checklist, and so on
2.) How would you define an array to keep track of 5 students' ID numbers (integer value) and their final grades,
rounded to the nearest whole number (integer Value)?
3.) Using the array defined in question #2 write the statement to store information for the five students' ID
numbers and final averages in each array element
4.) Describe in your own words how a stack works
is spring loaded, and as the customer removes a plate from the stack, every plate moves up one position
5.) Describe in your own words how a queue works
a ride at an amusement park The first person in line is the first person to get on the ride and leave the line, whereas the last person in line waits the longest to get on the ride and leave the line
6.) Describe in your own words how a binary tree works
speeding up searches
7.) Show each step to sort the data by using a bubble sort [Use Fig 8-34]
Trang 41 4
8.) Show each step to sort the data by using a selection sort [Use Fig 8-34]
9.) Show each step to sort the data by using a bubble sort [Use Fig 8-35]
Trang 50 1
10.) Show each step to sort the data by using a selection sort [Use Fig 8-35]
11.) Label the root and leaf nodes [Use Fig 8-36]
12.) What the maximum height of the tree?
The height of the tree is: 4
13.) On what level is the node with the value 15? [Use Fig 8-36]
14.) Show the steps to find the value 7 [Use Fig 8-36]
1 Start at the root node
2 Does the value 7 = the root value (21)? No Then is the value 7 > the root value (21) No Move left child (19)
3 Does the value 7 = the root value (19)? No Then is the value 7 > the root value (19) No Move left child (10)
4 Does the value 7 = the root value (10)? No Then is the value 7 > the root value (10) No Move left child (7)
Trang 6
15.) Show the steps to find the value 17 [Use Fig 8-36]
1 Start at the root node
2 Does the value 17 = the root node 21? No Then is the value 17 > the root value (21)? No Move left child (19)
3 Does the value 17 = the root value 19? No Then is the value 17 > the root value (19)? No Move left child (10)
4 Does the value 17 = the root value 10? No Then is the value 17 > the root value (10)? Yes Move right Child (15)
5 Does the value 17 = the root value 15? No Then is the value 17 > the root value (15)? Yes Move right Child (17)
6 Does the value 17 = the root value 17? Yes Stop traversing the tree
Practice Exercises:
1.) A (n) array is a data structure consisting of contiguous memory locations
2.) A(n) index is used is access each element
3.) A single array can contain information of different types of data (integers, characters, decimals, and so on)
FALSE
4.) The statement char[ ] aAnswers = new char[5] declares an array that has memory locations of 1 through 5
FALSE
5.) The offset is used to specify the distance between memory locations
TRUE
6.) Arrays are a good data structure to use with dynamic data
TRUE
7.) A stack uses a LIFO structure
TRUE
8.) A queue uses a FIFO structure
TRUE
9.) LIFO is an acronym for:
Last In First Out
Trang 710.) FIFO is an acronym for:
First In First Out
Use Figure 8-37 to answer questions 11 - 15
11.) How many comparisons does it take to find the following numbers? [RESEARCH MORE]
a 8 3
b 2 4
c 23 2
d 30 3
e 17 5
12.) What is the number of nodes on level 3?
4
13.) What is the number of nodes on level 4?
2
14.) What is the maximum height of the tree?
4
15.) How many right and left child nodes are there?
Right: 1
Left: 1
Given the following numbers: 1, 2, 3, 4, 6, 7, 8, 9, 10,11 and 12 answer questions 16 through 20 16.) Draw a binary tree from these numbers Make sure binary tree rules are applied