• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 5 páginas
Resumen

Summary Programming Logic and Design Ch 8

Document preview thumbnail
Vista previa 2 fuera de 5 páginas

This document provides an in depth and thorough summary of chapter 8 of Programming Logic and Design. It is ready for exam and tests. Everything is laid out as it is in the textbook. All needed information is provided in short. It is written in an easy to study format and reads easy. I got distinctions in exams and tests.

Vista previa del contenido

Chapter 8
Explain the need for storing data
 Sequential order
 Placed in order based on the value of some field
 Alphabetical or numerical
 Ascending order (arranging records from A to Z or lowest to highest)
 Descending order (arranging records from Z to A or highest to lowest)
 The median value in a list is the value of the middle item when the values are listed in order
 not the same as the arithmetic average, or mean

 When computers sort data
 Always use numeric values when making comparisons between values
 Letters are translated into numbers using coding schemes such as ASCII, Unicode, or
EBCDIC
 “B” is numerically one greater than “A”
 “y” is numerically one less than “z”
 Whether “A” is represented by a number that is greater or smaller than the number
representing “a” depends on your system
 Professional programmers might never have to write a program that sorts data
 Organizations can purchase prewritten sorting programs
 Many popular language compilers come with built-in methods that can sort data for you
 Beneficial to understand the sorting process


Describe the bubble sort algorithm
 An algorithm is a list of instructions that accomplish a task, such as a sort
 Bubble sort
 Items in a list are compared with each other in pairs
 Items are then swapped based on which is larger or smaller
 Sometimes called a sinking sort
 Ascending sorts put the smaller item on top, so the largest item sinks to the bottom
 Descending sorts put the larger item on top, so the smallest item sinks to the bottom
 An algorithm contains instructions for swapping values
 To swap values stored in two variables:
 Exchange their values
 Set the first variable equal to the value of the second
 Set the second variable equal to the value of the first
 There is a trick to swapping any two values
 Example
 num score1 = 90
 num score2 = 85
 This is what could go wrong

,  If you first assign score1 to score2 using a statement such as score2 = score1
 Both score1 and score2 hold 90, and the value 85 is lost
 Must create a temporary variable to hold one of the scores
 temp = score2 (temp and score2 both contain 85)
 score2 = score1 (score2 contains 90)
 score1 = temp (score1 contains 85)


 Nested loops
 Inner loop swaps out-of-order pairs
 Outer loop goes through the list multiple times
 General rules
 Greatest number of pair comparisons is one less than the number of elements in the array
 Number of times you need to process the list of values is one less than the number of
elements in the array


Sort records on multiple field values
 Might not know how many array elements will hold valid values
 Keep track of the number of elements stored in an array
 Store number of elements
 Compute comparisons as number of elements – 1


 If you are performing an ascending sort
 After you have made one pass through the list, the largest value is guaranteed to be in its
correct final position

1. Compare every element pair in the list on every pass through the list
2. Comparing elements that are already guaranteed to be in their final correct position
3. On each pass through the array, stop your pair comparisons one element sooner
4. Create a new variable pairsToCompare
5. Set it equal to the value of numberOfEls – 1
6. On each subsequent pass through the list, reduce pairsToCompare by 1
7. Create a new variable didSwap
8. Set it equal to the value of “No”
9. Each time the swap () module executes, change the value to “Yes”

Class
 Sorting data stored in parallel arrays
 Each array must stay in sync StudentRecord

 Sorting records as a whole string name

 Create groups called record structures or classes num score

 Defining a class allows you to sort by either name or scoreendClass

Libro relacionado
 image
Editorial: 2023 ISBN: 9780357880876 Edición: Desconocido

Información del documento

¿Un libro?
No
¿Qué capítulos están resumidos?
8
Subido en
15 de noviembre de 2025
Número de páginas
5
Escrito en
2025/2026
Tipo
Resumen
$3.76

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
tanjanel1303
5.0
(2)
Vendido
11
Seguidores
2
Artículos
47
Última venta
1 mes hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes