You are on page 1of 7

Connecting 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 unknown 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.

Key Terms:
Array: (280)
Binary Search Tree: (301)
Bubble Sort: (306)

Data Structure: (279)


Depth or Level: (300)
Dequeue: (297)
Element: (282)
Enqueue: (298)
First in First Out: (297)
Head Pointer: (292)
Height: (300)
Index (Subscript): (284)
Last in, First Out: (295)
Leaf Node: (300)
Left Child: (299)
Linked List: (290)
Lower Bound: (284)
Multi-Dim Array: (285)
Node (vertex): (299)
Null Value: (292)
Offset: (283)
Peeking: (295)
Pointer: (291)
Pop: (295)
Procedure: (296)
Push: (295)
Queue: (297)
Recursion: (310)
Right Child: (299)
Root: (300)
Selection Sort: (304)
Stack: (294)
Stack Pointer: (296)
Tail Pointer: (297)
Tree: (299)
Upper Bound: (284)

A set of contiguous memory cells used for storing the same type of data.
A binary tree in which the left child's data value is less than the parent node's, and the right child's data
value is greater than the parent node's
A sorting routine that compares each item in the list with the item next to it; if the first item is greater
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.
A way of organizing data in memory, such as: arrays, lists, stacks queues and stacks
The distance from the node to the root node. The root's depth or level is 0.
To remove an item from a queue.
A memory cell in an array.
To insert an item into a queue.
The last item placed on the stack is the last item removed from the stack, and the first item removed
from the stack is the first item placed onto the stack.
A pointer indicating the beginning of the first element in a data structure.
The longest path length in the tree.
How an array accesses each element stored in its data structure.
The last item placed on the stack is the first item removed from the stack
A node that has no child nodes.
The child node to the left of the parent node.
A data structure that uses noncontiguous memory locations to store data; each element in the linked
list points to the next element in line and does not have to be contiguous with the previous element.
The lowest position in an array.
An array consisting of two or more single dimensional arrays.
A position in a tree data structure.
The absence of a value, meaning there is no value stored; null is not the same as: blank or zero.
Used to specify the distance between memory locations.
Looking at the top item in the stack without removing it from the stack.
A memory variable containing the address of a memory cell as its data.
Remove an item from the stack.
A group of one or more related commands that perform a task.
Place an item on the stack.
A list in which the next item to be removed is the item that has been in the list the longest.
The process of a routine calling itself.
The child node to the right of the parent node.
The node that begins the tree.
A sorting routine that selects the smallest unsorted item remaining in the list and then swaps it with the
item in the next position to be filled.
A list in which the next item to be removed is the item most recently stored.
A pointer that keeps track of where to remove or add an item in a data structure.
Keeps track of the end or rear position of the data structure.
A data structure that represents a hierarchical structure, similar to that of organizational genealogical
charts.
The highest position in an array.

Test Yourself:
1.) Describe the uses of an array
Arrays are used for storing similar kinds of information in memory. This information can be sorted or left
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)?

int [ ][ ] aStudentId = new int [5] [5] ;

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
int aStudentId [ ] [ ] = { {32, 12, 18, 54, 22}, {10,11,12,13,14} } ;
4.) Describe in your own words how a stack works.
Stacks are similar to an all-you-can-eat buffet. Restaurants provide plates for customers. The plate holder
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.
Insertions are made at the end of the stack and deletions are made at the beginning. Similar to waiting for
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.
A binary tree is like a family tree. It represents data in an orderly fashion and is useful for list-like data
speeding up searches.
7.) Show each step to sort the data by using a bubble sort [Use Fig. 8-34]
0
1
2
3
4
5
0
1
2
3
4
5

2
32
4
7
10
25

32
4
7
2
10
25
0
1
2
3
4
5

0
1
2
3
4
5
2
32
4
7
10
25

32
4
7
2
10
25
0
1
2
3
4
5

0
1
2
3
4
5
2
32
4
7
10
25

32
4
2
7
10
25

0
1
2
3
4
5
0
1
2
3
4
5

2
4
32
7
10
25

32
2
4
7
10
25

0
1
2
3
4
5
0
1
2
3
4
5

2
32
4
7
10
25
2
4
32
7
10
25

0
1
2
3
4
5

2
4
32
7
10
25

0
1
2
3
4
5

2
4
32
7
10
25

0
1
2
3
4
5

2
4
7
32
10
25

0
1
2
3
4
5

2
4
7
32
10
25

0
1
2
3
4
5

2
4
32
7
10
25

0
1
2
3
4
5

2
4
32
7
10
25

0
1
2
3
4
5

2
4
32
7
10
25

0
1
2
3
4
5

2
4
7
32
10
25

0
1
2
3
4
5

2
4
7
32
10
25

0
1
2
3
4
5

2
4
7
32
10
25

0
1
2
3
4
5

2
4
7
32
10
25

0
1
2
3
4
5

2
4
7
10
32
25

0
1
2
3
4
5

2
4
7
10
32
25

0
1
2
3
4
5

2
4
7
10
32
25

0
1
2
3
4
5

2
4
7
10
32
25

0
1
2
3
4
5

2
4
7
10
25
32

8.) Show each step to sort the data by using a selection sort [Use Fig. 8-34]
0
1
2
3
4
5

2
4
7
32
25
10

0
1
2
3
4
5

2
4
7
10
25
32

9.) Show each step to sort the data by using a bubble sort [Use Fig. 8-35]
0
1
2
3
4
5

5
32
30
1
2
20

0
1
2
3
4
5

5
32
1
30
2
20

0
1
2
3
4
5

5
1
32
30
2
20

0
1
2
3
4
5

1
5
32
30
2
20

0
1
2
3
4
5

1
5
32
30
2
20

0
1
2
3
4
5

1
5
32
2
30
20

0
1
2
3
4
5

1
5
2
32
30
20

0
1
2
3
4
5

1
2
5
20
32
30

0
1
2
3
4
5

1
2
5
20
32
30

0
1
2
3
4
5

1
2
5
20
30
32

0
1
2
3
4
5

1
2
5
32
30
20

0
1
2
3
4
5

1
2
5
32
20
30

0
1
2
3
4
5

1
2
5
20
32
30

0
1
2
3
4
5

1
2
5
20
30
32

10.) Show each step to sort the data by using a selection sort [Use Fig. 8-35]
0
1
2
3
4
5

1
32
30
5
2
20

0
1
2
3
4
5

1
2
30
5
32
20

0
1
2
3
4
5

1
2
5
30
32
20

0
1
2
3
4
5

1
2
5
20
32
30

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]
The node with the value 15 is on level 3.
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).

5. Does the value 7 = the root value (10)? Yes. Stop traversing the tree.
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

10.) 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.

You might also like