Ch 7: problem solving and algorithms
abstraction
a model of a complex system that includes only the details essential to the viewer.
computer problem-solving process
1. analysis and specification phase 2. algorithm development phase 3. implementation phase 4. maintenance phase
summary of methodology
1. analyze the problem 2. list the main tasks 3. write the remaining modules 4. re-sequence and revise as necessary
ways of collecting data items together
1. arrays 2. records
How to solve problems
1. ask questions 2. look for familiar things 3. divide and conquer 4. algorithm
recursion has 2 cases:
1. base case- have an answer 2. general case- solution to itself with a smaller version of the original problem
two types of loops
1. count controlled 2. event controlled
3 steps to loops
1. initialization 2. testing 3. updating
radix sort
a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value; similar to bucket sort but each bucket has to be sorted. O(n)
Bubble sort/ "sinking" sort
a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order; very slow sorting
control structure
a statement used to alter the normally sequential flow of control.
concrete step
a step for which the details are fully specified
nested structure
a structure in which one control structure is embedded within another.
abstract step
an algorithmic step for which some details remain unspecified
which search is faster? sequential search or binary search?
binary if the array is already sorted
selection sort
easiest; but requires space for two complete decks; O(n2) time complexity making it inefficient in large lists.
quicksort
is a popular sorting algorithm that is often faster in practice compared to other sorting algorithms. It utilizes a divide-and-conquer strategy to quickly sort data items by dividing a large array into two smaller arrays. It was developed by Charles Antony Richard Hoare (commonly known as C.A.R. O(nlgn)
insertion sort
is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. ... Efficient for (quite) small data sets. O(n^2)
merge sort
is an efficient, general-purpose, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. O(nlgn)
binary search
looking for an item in an already sorted list by eliminating larger portions of the data on each comparison. algorithm begins at the middle of the array --> if the item searching for is less than the item in the middle--> item searching for wont be in the second half of the array--> continue searching in first half of array. O(1)
event-controlled loops
loops in which the number of repetitions is controlled by an event that occurs within the body of the loop itself.
array
named collection of homogeneous items in which individual items are accessed by their place within the collection.
records
named heterogeneous group of items in which individual items are accessed by name. elements in the collection do not have to be the same
bucket sort
or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. O(n)
information hiding
practice of hiding the details of a module with the goal of controlling access to the details of the module
while loop
pretest loop, testing takes place before the loop is executed.
count controlled loop
repeats a process of a specified number of times.
sequential search (linear search)
searching exactly. begins at the beginning of the array and continues until the item is found or the entire array has been seared without find the item. O(n)
recursion
the ability of an algorithm to call itself.
index
the place within the collection (array)
control abstraction
the separation of the logical view of a control structure from its implementation
procedural abstraction
the separation of the logical view of an action from its implementation
data abstraction
the separation of the logical view of data from its implementation