1.4 data types, structures and algorithms(unfin) Flashcards
(28 cards)
primitive data types
complete item, cannot be broken to parts
examples:
integer
real/floating point
character
string
Boolean
abstract data types
type/class whose behaviour is defined by a set of value and a set of operations
ABSTRACTION - concerned for what it is representing, not how it is constructed
examples:
list (depends)
stack
queue
composite data types
one or more fields dynamically linked to fields in another data type
examples:
class
array
list (depends)
static vs dynamic
if it can grow during run time
static: fixed in size, cannot grow
dynamic: flexibility to grow
binary
types:
-positive integers
-sign and magnitude
-twos complement
-floating points
operations:
-addition, subtraction
-shifting: AND, OR, XOR
ASCII
-aka American Standard Code for Information Interchange
-2^7= 128 different characters
-capital letters A-Z : 65-90
-lower case letters a-z : 97-122
-there are also codes for numbers and symbols
dis: limited character set
Unicode
uses a varying number of bits allowing for over 1 million different characters
stores different languages, symbols and emoji
arrays
definitions:
(1)composite data type
(2)ordered, (3)finite set of elements of a (4)single type
(5)data are stored in contiguous block of memory
(6)static
notes:
quick searches (binary/ direct access)
slow sort and moving order
records
Collection of related fields(of fixed numbers) with mixture of data types
used in database
lists
definition: (and diff with array)
abstract data type
list of ORDERED items where items can occur more than once
values are stored NON-CONTIGUOUSLY
more than one data type
dynamic
tuples
composite data type
list of ordered items
immutable and static
linked list
dynamic data structure
each node has data and pointer
graphs
what is a graph?
-arcs/edges
-nodes/vertices
(-weights -> forms a network)
types:
-connected: every node can be reached
-simple: no loops or double connection
-simply connected: simple + connected
-complete: mesh - all nodes connected
-directed: only one direct to travel btw the nodes
-undirected
-bidirectional
stack
-ADT
-holds an ordered, linear sequence of items
-LIFO
-recursion (subroutine calls)
-overflow/underflow
-pointers: head and next_free
operations:
push
pop
peek
isEmpty
isFull
tree
-simple connected graph with no cycles
-top level is called root
-parent is unique to the children (one to many relationship)
binary search tree
each parent has max 2 children
leaf nodes are the bottom level, with no children
hash table
-stored as array, with a key map to a unique index
-position of data is determined by hashed value of the key
(position can be called buckets)
collision: when two keys produce the same hash value, the item will be placed in the next available space
(solution to collision: LINEAR PROBING AND CHAINING)
-> rehashing can be done as table grows
use: DBMS- indexing, as it allows quick access
sign and magnitude vs twos complement
sign and magnitude: first binary is only the sign
twos complement: first binary is positive/negative number
floating point
mantissa is the value, exponent is the power
- the decimal must be place in the most significant numbers
- positive mantissa: make binary bigger
- negative mantissa: make binary smaller
- addition and subtraction: convert to mantissa to the bigger value, then change exponent
-> ignore the overflow
logical bitwise operator
mask: binary string that is used to identify the bit you want to operate on
operations:
clear: make the bit 0 (AND 0, XOR 1 mask)
check : return the bit (0/1) (OR 0 mask)
set : make the bit 1 (OR 1 mask)
toggle: flip the bit (XOR 0 mask)
practice: 8 bit binary, check the 7th digit
binary shifting
-logical: only applicable to the unsigned (meaning positive and negative numbers are ignored)
-arithmetic: keep the sign (leave the sign bit and shift); negatives: keep negative (two’s complement)
-cyclic: the bit that is floated out goes back at the other end
K-map
to simplify Boolean expressions
used for truth tables
written in gray code
Boolean expressions with logical operators
what does the CIRCUITS and SYMBOLS look like?
AND
OR
XOR
NOR
XNOR
rules to simplify boolean expressions
De Morgan’s Laws: breaking a negation AND changing the operator
NOT(X or Y)-> NOT X n NOT Y
distribution:
A n (B or C) =(A n B) or (A n C)
A OR (B n C) =(A or B) n (A or C)
association: reordering
A n (B n C) = (A n B) n C
commutation: AnB = BnA
absorption: X n (X or Y) = X
double negation: NOT NOT A = A