SLIDE 1
CISC4080 Review of sorting and searching algorithms, recursive algorithms Spring 2019
- 1. Algorithm and pseudocode
- A. Problem: input/output
- B. instance (a particular input)
- C. Pseudocode: language-neutral, specific data type-neural (sort an array of int,
double…), an array/vector of ints, … A few terms:
- a list: a[1…n] refers to a data structure (ADT) that stores a collection of
elements (of some type), in which accessing a[i] (i-th element) takes constant amount
- f time (i.e., accessing a[1], a[2], …a[1000] takes same amount of time)
- can be a C++ array, C++ STL vector
- in Pseudocode, index to list usually starts from 1. (careful when
translating into C or java, or python).
- in general a sublist a[i…j] where i>=1, j<=n, is a contiguous part of a list a[1…n]
- e.g., a[1…8] is a sublist of a[1…9]
- a[1…1] is a sublist of a[1…9] of length 1
- a[3…2] is a null list (length is 0)
- for i=1 to n // repeat do something for i=1, i=2, … i=n
- do something
- repeat until some_condition //as long as some_condition is false, do something
- do something
- 2. Searching Problem
sorting a list (arrange list elements in ascending or descending order) | ^ | helps | helps (in insertion sort) v | searching a list for a value: linear search and binary search Search Problem 1: searching for a value in a list input: a[1…n], value
- utput: index/location in a if value is found; -1 if not found