Algorithms Study Guide PDF
Document Details
![DetachableWatermelonTourmaline](https://quizgecko.com/images/avatars/avatar-17.webp)
Uploaded by DetachableWatermelonTourmaline
Tags
Summary
This document is an introductory guide to algorithms and programming, including decomposition, pattern identification, and abstraction. It covers different techniques, like object-oriented decomposition and methods, including attributes and classes.
Full Transcript
LESSON 1 Algorithms o Object-Oriented Decomposition: Divides a 1. Algorithm: A series of steps for problem into logical and...
LESSON 1 Algorithms o Object-Oriented Decomposition: Divides a 1. Algorithm: A series of steps for problem into logical and solving a problem or carrying out a physical objects. task. o Modules: The cohesive, 2. Programming Algorithm: Steps that structural units of an specify the underlying logic and algorithm. structure for statements in a computer program. o Objects: Specific instances of a class, such as Rover being a 3. Computer Program: A collection of specific object of the class statements written in a programming Dog. language that performs a specific task when executed by a digital device. 2. Pattern Identification: Finding patterns in procedures and tasks to Characteristics of a Good Algorithm: create reusable algorithms. Input: Applies to a set of specified o Classification Patterns: inputs. Patterns of attributes and Output: Produces one or more methods that apply to a outputs. collection of objects. Finite: Terminates after a finite o Classes: Blueprints number of steps. containing attributes and methods describing a Precise: Each step is clear and collection of objects. unambiguous. 3. Abstraction: Hiding details or Effective: Successfully produces the substituting a generalization for correct output. something specific. Techniques for Algorithm Creation: o Attributes: Characteristics Use Standard Algorithms: Known that describe an object effective algorithms for tasks like (nouns). E.g., a node can sorting, searching, text manipulation, contain a list of attributes. data encryption, and shortest path o Methods: Actions that an finding. object can perform (verb Perform Task Manually: Record and phrases). E.g., an algorithm for analyze steps manually when a each method. standard algorithm is not available. o Level of Abstraction: The Apply Computational Thinking degree to which details of an Techniques: Use decomposition, object or concept are hidden. pattern identification, and abstraction. Computational Thinking Techniques : A set of techniques, such as decomposition, pattern identification, and abstraction, designed to formulate problems and their solutions. LESSON 2 Programming Tools 1. Decomposition: Breaking a task into Hello World! Program: The most smaller parts. famous computer program of all time. o Structural Decomposition: Identifies structural units of a Programming Language: A formal task. language with semantics and syntax for instructing a computer to perform a o Functional Decomposition: specific task (e.g., C++, Java, Python). Divides modules into smaller actions. High-Level Programming Languages: Systems for issuing instructions to a CPU, abstracting away the details of Machine Code: Binary instructions low-level machine language. executable by a computer. Statement: Each instruction written in a Executable File: A file compiled into high-level programming language. machine code. Program Code: The set of statements Source Code: Statements written in a written in a programming language. high-level programming language. Semantics: The meaning and validity of Object Code: Binary program code program statements. produced by a compiler. Keywords: Words in a programming Preprocessor Directives: Instructions language with special meaning (e.g., for the preprocessor before compilation. print, cout). Linker: Converts object files into a Reserved Words: Words reserved by a binary executable file. programming language to specify commands and actions. Bytecode: Intermediate code executed by a virtual machine. Syntax: Grammar rules for word order and punctuation in programming Virtual Machine: Software that languages. executes bytecode on specific hardware. Programming Tools and Components Interpreter: Preprocesses and executes program statements one by one. Coding Tools: Tools to codify an algorithm. Debugging: The process of finding and correcting program errors. Build Tools: Transform code into a binary format executable by a computer. Syntax Error: Incorrect use of punctuation or word sequencing. Debugging Tools: Help test programs and track down errors. Runtime Error: Program failure during execution due to issues like division by Visual Platform: Tools for arranging zero or memory exhaustion. visual elements representing various statements. Semantic Error: Logical flaws causing incorrect program results. Word Processor: Typically embeds formatting codes unsuitable for high- Breakpoint: A location in program code level code. that triggers the debugging utility to halt execution for error identification. Text Editor: Produces plain ASCII text without programming-specific features. Program Animation: A debugging feature that steps through code one Code Editor: Text editor designed for statement at a time. entering high-level programming code, assists with punctuation, indents, and Integrated Development Environment keyword validation. (IDE): Software that includes all tools needed to code, compile, link, and debug Comments: Explanations within the programs. code for documentation purposes. Directives: Instructions for the computer on handling the program (e.g., #include, import). main() Function: Denotes the entry point for program execution. 3. Changeable Data: Data can be modified. Constant: A named memory location holding unchangeable data. Once assigned, the value of a constant cannot be altered.(PI = 3.14) or configuration values. Reserved Words: Specific words used by programming languages for particular purposes (e.g., print). Naming Conventions: Camel Case: First word lowercase, subsequent words capitalized (e.g., totalRings). Snake Case: All lowercase, words separated by underscores (e.g., total_rings). Declaring Variables: Specifying a name and type (e.g., int total_rings;). Useful even if the value is unknown initially. Initializing Variables: Assigning a value (e.g., total_rings = 20). Python does not require type specification. Assignment Statements: Set or change a variable's value. Null Variables: Variables with no value, different from zero. undefined variable A variable that has not LESSON 3 been specified by the programmer. Reviewer on Variables, Literals, and Constants User Input: Prompting the user for data entry. Literal: A value specified directly in a type inference A programming language program. Types include: feature that deduces the data type based on the presence or absence of a decimal point. Numeric Literal: One or more digits, representing integers or floating-point statically typed A programming language numbers. feature that requires a variable to hold only the type of data that was specified when the Character Literal: A single letter or variable was declared or initialized. symbol. String Literal: One or more prompt A message that specifies what a user characters, typically enclosed in should enter when a program is running. double quotes. Boolean Literal: True or False, not enclosed in quotes. Variable: A named memory location that holds data. Characteristics: 1. Name: Unique identifier. 2. Memory Location: Stores data. LESSON 4 Arithmetic Operators: Mathematical Numeric Data Types and Expressions symbols (+, -, *, /, %). Data Type: A way of categorizing data. Integer Division: May exclude fractional parts (7 / 2 might result in Primitive Data Types: Built into programming 3). languages. Modulo Division: Produces the Character (char): Single letter, remainder (11 % 3 results in 2). symbol, or numeral ('a', '@'). Order of Operations: Sequence of Integer (int): Whole number without mathematical operations. decimal places (1, 128, 3056, -2). Compound Operators: Shortcuts for basic Floating Point (float): Number with assignment operations. decimal places (12.99, 0.26, -3.56). Type Casting: Converting a variable of one Double Floating Point (double): Very type into another type. large number with decimal places (3.84147098480789672). Formatting Parameters: Alter the appearance of numeric and text output. Boolean (bool): Logical value (True, False). Width: Number of spaces allocated. Valueless (void): No value. Fill: Pad with spaces or zeros. Wide Character (wchar_t): Unicode Alignment: Left or right alignment. character (€, ®, ¥). Decimal Point Display: Presence or Function: Named procedure performing a absence of a decimal point. specific task (e.g., abs() returns the absolute Precision: Number of places after the value of an integer). decimal point. Key Characteristics of Primitive Data Type: Integer, floating point, decimal, Types: binary, hexadecimal, character, or E 1. The programming language knows notation. how much memory to allocate. Sign: Inclusion of + or - sign. 2. The programming language knows Coercion: Automatic conversion of a literal how to manipulate that type of data. into a different data type. Composite Data Types: Constructed from primitive data types, not built into the language (e.g., data representing time). Integer Data Types: Whole numbers without decimal places or fractions. Signed: Can be positive or negative (+363, -40). Representation: Decimal, binary (0b00000101), hexadecimal (0x6C). Floating-Point Data Types: Numbers with decimal places. E Notation: Similar to scientific notation (459.67 as 4.5967E2). Single Precision: Stored in 4 bytes of memory. Double Precision: Stored in 8 bytes of memory. Expression: A statement with a value, usually including arithmetic operators and operands. LESSON 5 Character and String Example: String fullName = firstName + " " + Data Types lastName;. Character Data Type: The Common String Operations classification for variables that hold a single letter of the alphabet, a symbol, or Find the length of a string: int a numeral from 0 to 9. length = myString.length(); Example: In most programming Change the case of a string: String languages, you assign a character lower = myString.toLowerCase();, to a variable using single quotes, String upper = such as char letter = 'A';. myString.toUpperCase(); ASCII (American Standard Code for Check if a string contains a specific Information Interchange): A method character: boolean contains = for encoding letters, symbols, and myString.contains("a"); numerals using seven or eight bits. Retrieve a substring from a longer Example: The ASCII value for string: String sub = the uppercase letter 'A' is 65. myString.substring(0, 5); String: A sequence of characters. Example: String greeting = "Hello, World!"; String Data Type: The classification for variables that hold a sequence of characters. Example: Strings are often initialized with double quotes, such as String name = "John";. Escape Sequence: Embedded characters beginning with a backslash (\) to insert special symbols into a string. Example: To include a quotation mark in a string, use \" like this: String quote = "She said, \"Hello!\"";. Index: The position of a character in a string, starting at position. Example: In the string "Hello", the index of 'H' is 0, 'e' is 1, and so on. Case Sensitivity: The differentiation that makes a lowercase letter different from its uppercase version. Example: In many programming languages, 'a' and 'A' are considered different characters. Concatenation: Combining data using the + concatenation operator.