Docsity

ITM207 Computer-Enabled Problem Solving Notes (exam prep solution) Toronto Metropolitan Un, Exams of Advanced Education

Partial preview of the text

Download ITM207 Computer-Enabled Problem Solving Notes (exam prep solution) Toronto Metropolitan Un and more Exams Advanced Education in PDF only on Docsity!

ITM207 Computer-Enabled Problem

Solving Notes (exam prep solution)

Toronto Metropolitan University

l Week 1 Living and Working with Computers ● Computers are used in all industries, including (but not limited to) ○ Education, healthcare, energy, communication, government, transportation, commerce, manufacturing, entertainment

● We live in an increasingly complex world ○ Population growth ○ Scarcity of resources ○ Climate change ○ Urbanization ○ Socio-political challenges ○ Globalization ○ Diversity Business Problem Space ● The business problem space is increasing in complexity. ○ Global competition ■ Market share ■ Resources ■ Quantified labor ○ Global operation ■ Across distinct cultural and regulatory environments ○ Big-data deluge about customers ● Challenges human abilities to make efficient and effective business decisions ICT and Business Management ● Information and Communication Technologies (ICT) and associated analytical tools have proven to be critical enables or efficient and effective practices vis-a-vis: ○ Cost ○ Product & service quality ○ Customer satisfaction ● Business management can be categorized along the following general functions: ○ Operations Management (Day to day) ex. Maintaining the effective management of a large store chain distributed across multiple geographic locations ○ Strategic Management ex. Expanding the market for a company’s products and services ● ICT is enabling business management: ○ gather/store/track/organize/retrieve business data and information and use it at will ○ Codify business intelligence and apply it to the relevant data/information - make decisions (operations & strategic) ○ Globally networked infrastructure for production, distribution, and marketing of products and service marketing and provision ● What is the infrastructure underlying ICT? ○ Software:

○ n is the number of digits in the number ○ R is the base ○ Di is the i-th digit Base Representation of Numbers ● Decimal numbers are represented using 10 digits. Therefore, we say that decimal numbers are in base 10. ● Binary numbers only use 2 digits (0 and 1), and so are in base 2. ● Octal (base 8) ● Hexadecimal (base 16) ● A number expressed in base n may include digits up to but not including n. Converting Binary to Decimal ● Given the general formula for positional notation, one can convert a binary number to decimal as follows: 01010 = 02^4 + 12^3 + 02^2 + 12^1 + 0*2^0 = 0 + 8 + 0 + 2 + 0 = 10 Converting Binary to Hexadecimal ● Group the binary digits into groups of 4 from right to left, then convert each group into their hex value. Converting Decimal to Binary ● Repeat the division of the decimal number by 2 as long as the quotient is not zero ● After each division, take the remainder as a new digit in the binary number starting from the right to the left ● Repeat the division of step 1 using the new quotient instead of the previous number ● The resulting binary number is represented with bits which can either be 1 or 0. A group of 8 bits is called a byte. Week 3 Computers & Data ● Computers are devices that can deal with multimedia content covering a wide spectrum of data and information types including: ○ Numbers ○ Text ○ Graphics ○ Images ○ Audio ○ Video ○ Sensor acquired signals Data Categories

● Analog Data refers to a continuous representation, analogous to the actual information is represents such as air temperature ● Digital Data refers to a discrete representation of the actual information into levels, each representing a range of continuous values. Binary Representation ● n bits can represent 2 n^ things Representing Text ● Text is a string of characters belonging to a finite character set comprising the letters of the alphabet, the numerals, and other special characters such as @ ● A phrase can be represented by assigning a binary string to each character in the sentence, including the space. ● Universal standard representation is needed. ● Accomplished by ASCII (American Standard Code for Information Interchange) ○ ASCII - 7 bits ○ Extended ASCII - 8 bits ○ Unicode - 16 bits (superset of ASCII) Representing Real Numbers ● Real numbers such as 10.45 have a whole part and a fractional part. ● We can use positional notation on the right of the decimal ● The point separating the two parts is called the radix point. Signed Representation of Negative Numbers ● To represent negative numbers in binary, we use the most significant bit (the leftmost). If it is 1, the number is negative. 10s Complements ● We could, as a solution, represent the numbers 0, 1, …, 48, and 49 in the usual manner. ● We then use the numbers 50, 51, …, 98, 99 to represent -1, -2, …, -50. ● Negative (x) = 10 N^ - x ○ N is the number of digits being used. 2s Complement ● The two’s complement for binary numbers is used in the same way as the 10s complement ● Use Negative (x) = 2 N^ - x, where N is the number of digits of bits being used 2s Complement - Quick Technique

  1. Write down the binary sequence of the positive counterpart. For the case of the number -64, it would be the binary representation of 64 in 8 bits, which is 01000000.
  2. Start from the LSB and move leftwards applying the following rule: keep the zeroes as zeroes until you find the first 1, keep it as 1, and for all the bits that follow, flip the 0s into 1s and vice versa. Floating Point Representation for Binary ● Sign * mantissa * 2 exp ○ Bit 31: sign (1 = -) ○ Bits 23-30: exponent ○ Bits 0-22: mantissa ● +11.1001 = 111001 * 2 -

Truth Tables ● Describe the input-output relationship between a boolean expression and its boolean variables ● Maps out the step-by-step outputs of a boolean expression for each possible combination of inputs Boolean Logic ● Computer representation of data consists of 2 states: 1 and 0 ● Physically implemented using electrical signals processed by basic electronic devices called gates ● Gates are made of one or more transistors (electronic switches that can be turned on or off by an electrical control signal)

● Multiplexers ○ A circuit that uses a few input control signals to determine which of several output data lines is routed to its output ● Circuits as memory (sequential circuit) ○ An S-R latch stores a single binary digit (1 or 0) ○ The design of this circuit guarantees that the two outputs X and Y are always complements of each other ○ The value of X at any point in time is considered to be the current state of the circuit ○ Therefore, if X is 1, the circuit is storing a 1 ● Integrated Circuit (chip) ○ A piece of silicon on which multiple gates have been embedded. ○ Silicon pieces are mounted on a plastic or ceramic package with packages with pins along the edges that can be soldered onto circuit boards or inserted into appropriate sockets ○ Types: ■ SSI: Small-scale integration. 100 - 101 gates ■ MSI: Medium-Scale Integration. 101 - 102 gates

■ LSI: Large-Scale Integration. 102 - 105 gates ■ VLSI: Very-Large-Scale Integration. 105 + gates ● CPU Chips ○ Central Processing Unit ○ CPU chips have a large number of pins through which essentially all communication in a computer system occurs. Week 5 Problem Solving ● Understand the Problem ○ What do I know, what information do I have to process to find the solution, what does the information look like? Special cases? How will I recognize that I have found the solution? ● Devise a plan ● Carry out the plan ● Reflect Algorithms ● An algorithm is a collection of processing tasks to be executed in a specific order as a solution to a given problem. ● Finite duration ● Three core elements: ○ Input ○ Processing ○ Output ● Unambiguous statement of the solution ● Deterministic ○ For the same input, the algorithm generates the same output.

Boolean Expression ● These are expressions that evaluate to true or false ● Using logical and relational operators ○ eg evaluates IF x>y ○ Conditional statement ● We need complex boolean expressions, requiring the use of a combination of relational and logical operators ● Relational operators ○ = equal to ○ < less than ○ > greater than ○ !, / not ● Logical operators ○ And ○ Not ○ Or ○ Xor Rules of Precedence ● Order of operations 1. ()

  1. Not
    • / %
  2. < <= > >= =
  3. !=
  4. And
  5. Or Infinite Loops ● Loops that will never meet the exit condition Week 7 Arrays ● Indexed collection of numbers or strings of characters ● Each array element is referred to by its position/index ● Formatted arrayName[position], where position is numeric ● Marks[8] creates an array named marks of 8 elements ○ Sets 8th element to 80 ○ All positions below the highest defined position are undefined and set to 0, all positions over are undefined and not registered in the array until created ○ Declaring a higher position in the array increases the size ● length_of(arrayName) returns an integer equal to the length of the array ○ If the highest declared position is [12], then length_of() = 12 ○ Can be used to find the mean of an array

● Unlike many other languages, the first position in a raptor array is name[1], not name[0] Strings ● An array of characters ● Assignment: firstName = “ben’s” lastName = “notes” ● Concatenation: docName = firstName +” “ + lastName ● Length_of ● Indexing: docName[2] = e File Output/Input ● Data input for algorithms/programs is either ○ read/written using user interactive consoles ○ read/written from/to files (text files) ● Write an algorithm to read the content of the file “mymarks.txt” and write it to the array marks ○ Redirect_input(“mymarks.txt”) ○ i = 1 ○ Start loop - condition: end_of_input ■ Get marks[i] ■ i = i + 1 ● Use is_number and is_string to discern between input types Subcharts ● Complex problems are difficult to solve without dividing them into a set of simpler sub- problems ● Raptor provides the ability to create an algorithm as a main flowchart (main method) that coordinates the execution of submethods ● Makes a structure for the solution, making it easier to understand, maintain, modify, and evolve ● Useful for large algorithms where subcharts may be needed multiple times - efficient ● Subcharts are equivalent to the concept of subprograms found in programming languages (Java, C++, C#, etc) ● Subprograms are called by different names: subroutines, procedures, methods, etc ● Variables are consistent across all charts and subcharts Week 8 Sorting ● Sorting an array of numbers or strings means putting them in some order. ● Sorting a large number of records is time consuming, effective sorting strategies are needed ● Focus on three sorting algorithms, namely: selection, bubble, insertion ● Each have their own advantages and shortcomings. The focus will be on the nature of the strategies at hand Selection Sorting Algorithm ● Start from the smallest index and find the smallest elements ● Select/swap the smallest element next to the last smallest one

Week 9 Searching ● Searching for an element in an array is looking for its position (index) in the array
● Strategies ○ Randomly pick one element and check if it's the one (bad idea) ○ Start from the left/right and check one element at a time (slow) ○ Design an efficient algorithm that takes advantage of what we might know about the organization of the elements within the data structure ● Searching for an element in an array - ex: looking for the element containing the number 78 ○ Consider each element starting from the 1st and compare it to what we are looking for ○ If the two values match, we have found the item. Otherwise we consider the next element. ○ The search is stopped as soon as we find out item or the array ends Sequential search

  1. Start
  2. Set found to false
  3. Set i to 1
  4. If array[i] = searchTerm then found = true and end
  5. Else increment i by 1
  6. If i = length_of() go to 7 else go to 4

● Search is stopped when the mark we are looking for is found or the end of the array is reached ● How would we change the sequential search if the array was sorted? ○ In terms of searching numbers, assuming the array is sorted ascending, stop search when the term being evaluated is greater than the search term Binary search ● Sequential search: Search starts at the first element and keeps going until found or fully searched ● Binary search: start the search from the exact middle of the sorted array ( array must be sorted ). If parameters of one half do not include the search term, then exclude that half and check the other half. Continue to halve the array and check parameters until term found.

● Java explicitly specifies procedural steps such as incrementing the loop counter i. For Lisp on the other hand we don’t, we specify the result that factorial of 1 is 1 and factorial of n is factorial of n-1 times n Summary ● Programming languages ○ Imperative ■ Procedural (C, FORTRAN) ■ Object-oriented (C++, C#, Java) ○ Declarative ■ Logic (PROLOG, ASP) ■ Functional (LISP, Haskell) Source Code, Compilation, Executable ● Creator writes code and later initiates compilation ○ Source code file is run through a compiler which outputs an executable (binary) file ○ Source code files are editable text Object Oriented Programming (OOP) ● Consider the business requirements for the development of a computer program to manage loan accounts of bank clients. In its simplest form, the program holds for each client: the name, the account balance, the negotiated interest rate. Objects and Classes ● An object is a person, a thing, or an event ● Consider the account data of the previous example: each person is a distinct object ● Each account holder is an object, belonging to the client class. ○ Classes contain objects ● Using OOP, we can encapsulate the data attributes for each account within a separate client object, leading to a significant ease in the maintainability and future improvements of the software

○ Minimizes program-data dependence Class & Properties ● No, this doesn’t mean the land-owning bourgeoisie ● We define a class as an abstract entity that represents a group of objects. All the objects of the client class have the attributes: name, balance, rate ○ These attributes are called class properties ○ The class properties may take different values for different objects as was shown in the table of the previous slide. However, nothing prevents distinct objects from having similar property values. Two clients could have the same interest rate, for example. Data Representation ● Procedural: ○ The clients’ data are kept in shared arrays dedicated to the different fields (properties) of the accounts ○ We used flowcharts to specify algorithms that read client account records from a file, search for the requested client by name, display the relevant information ● Object-oriented: ○ Each account is represented by a distinct object that encapsulates its own data (name, balance, rate) ○ Now that each account is represented by an object holding its data, how do we specify the algorithms required to do the same tasks (read, search, display) Object Oriented Methodology for Software Development ● Now that each account is represented by an object (holding its data), how do we specify the algorithms required to do the same tasks (read, search, display) ● How do we develop the executable computer programs that embody these algorithms ● Identification of objects/classes ● Allocation of class responsibilities ● Realization of object collaborations necessary for the system to exhibit functional behavior specified by the requirements Object/Class Identification ● Filtering (Noun filtering): highlighting nouns and noun phrases as potential classes or attributes, while verbs are tagged as potential methods ● Applying this technique to business requirements for the management of client bank accounts leads to the following list of identified objects, attributes, methods ○ Client ; class ○ Name ; attribute of the client class ○ Account balance ; attribute ○ Interest rate ; attribute ○ Teller ; class ○ Display ; method of the client class Object Attributes and Behavior (Using UML - Unified Modeling Language) ● Attributes: hold object data