1 / 32

5.1 and 5.4 through 5.6

5.1 and 5.4 through 5.6. Various Things. Terminology. Identifiers: a name representing a variable, class name, method name, etc. Operand: a named memory location or object manipulated by the program. Variables are operands and identifiers

marilu
Download Presentation

5.1 and 5.4 through 5.6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 5.1 and 5.4 through 5.6 Various Things

  2. Terminology • Identifiers: a name representing a variable, class name, method name, etc. • Operand: a named memory location or object manipulated by the program. Variables are operands and identifiers • Ex: In “var1 + 45”, var1 is an identifier and operand, while 45 is only an operand. • Operator: Indicate action to be applied to operands • i.e. +, -, /, and, or, xor, not, etc.

  3. Terminology (Continued) • Unary Operator: An operator that requires only one operand. • Ex: Negation in boolean expressions, or x++ in Java. • Binary Operator: An operator that requires 2 operands, like + in x + y

  4. Terminology (Continued) (Continued) • Actual Parameter, or argument: The variable names that a method calls for • In DoStuff(x), the actual parameter/argument is x. • Formal Parameter: The variables sent to a method. Parameters get their values from arguments.

  5. Passing By-Value and By-Reference • By-Value: The value is sent, not a reference to the original variable. It’s a “copy”. • By-Reference: The original variable is used. If the parameter is manipulated, the original will be, too. • Most things in Java are sent by-value. Arrays, java classes, and user-defined objects are passed by reference. • Java doesn’t allow primitive data types (int, char, etc.) to be passed by-reference.

  6. Data Structures • The way data is organized • LIST data structures store a sequence of the same data type • Stacks, Queues, and Binary Trees are examples of lists

  7. Stacks • A stack is simple. Think of objects being stacked on top of each other. • When an object is added to the stack, it always goes on top. This is called PUSHing. • When an object is removed from the stack, it is always the top one, and it is removed. This is called POPping. • You cannot PUSH into a full stack, or POP from an empty stack. • However, a stack can be implemented as a linked list, giving it no maximum except available memory.

  8. Queues • Queue: noun: a file or line, esp. of people waiting their turn. • A queue in Java is the programming equivalent to this. • Items are taken from the front of the queue, but they’re not added to the front (like in stacks). Instead, they’re added to the back. • Called a First-In-First-Out (FIFO) Data Structure

  9. Parity CheckingSimple error detection • Uses “parity bits” to check that data is communicated properly. • A parity bit is a bit added to binary data to ensure that the number of 1s is even or odd. • Ex: for odd parity checking, 100101 is changed to 0100101, to keep the number of 1s odd. • Ex: for even parity checking, 100101 is changed to 1100101, to make the number of 1s even.

  10. Parity Checking (continued) • When the data is received, the receiving program checks to see if there are an even or odd number of 1s in binary information (depending on if it’s even or odd parity checking). • If not, then an error in data transmission has occurred. • NOTE: Odd parity checking and even parity checking are the same, except for the number of 1s.

  11. Object Oriented Program

  12. Object Oriented Programming • The kind of programming you’ve been doing (Java is object-oriented) • Object Oriented Programming is the use of objects (classes) to make programming modular. • This way, programs can be better organized, and specific parts of programs can be more easily reused.

  13. Features of an Object • Functions – return values • Procedures – perform a task, but don’t return a value • Object – a combination of data and operations • Objects can be modified • Data Items – pretty much data • Can be made private or public

  14. Object Class • Object is the root of the class hierarchy. • Every class has Object as a superclass. • All objects, including arrays, implement the methods of this class. • Object class rules everything

  15. Encapsulation • Basically this is the ability to hide variable information from other parts of the program • I.E. private variables

  16. Advantages of encapsulation • Less variables to manage; the programmer only has to know what a method does in order to use it • Less prone to errors • Large applications are easier to maintain since objects may be updated and recompiled as necessary

  17. Polymorphism • Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon • Examples • Overwriting • Concatenation • Overloading • Applets

  18. Inheritance • The ability to derive new classes from existing classes • New methods have the same name as the superclass, but override them • I.E. Automobile class • Subclass car • Subclass truck • Subclass motorcycle

  19. Advantages of Objects • Faster development • Increased quality of software, more robust • Easier maintenance • Implementation details are hidden • Enhances reusability and modification

  20. desventajes • Private variables can cause programmers to have difficulty debugging • Many computer languages do not support objects, transferring them would be costly • Simple programs take longer to make • Lack of standardized approach on how to implement objects

  21. Recursion

  22. What is recursion? • Recursion is the process of repeatedly calling a function from within the definition of the function itself. • The function must be able to terminate (aka loop that ends) • After the process is terminated the solutions and calculations are processed

  23. Advantages • Less variables • Fewer lines of code

  24. Disadvantages • Can take longer than other methods • Slower than iterative equivalent • Tricky to follow • Clear documentation is required • Difficult to maintain

  25. Algorithm Evaluation

  26. Efficiency of Algorithms • Time required depends on processor speed and algorithm design • Example: Linear Search • List has a size of n • Best case scenario time required is 1 • Worst case scenario time required is n • Depends a lot on how program is written

  27. What’s Necessary to Know • Single loops are O(N) • A nested loop is O(N2) • More than that is different, but probably not necessary for IB tests. However…

  28. Various Sorts and their Efficiency

  29. Big O Notation • Big O “lives in the land of theory and doesn’t care very much about the real world” • Big O describes how the algorithm scales (performs) in the worst case scenario as it is is run with more input • Big-O can also be used to describe other behavior such as memory consumption • O(N), N = number of elements aka time required

  30. What Big O is not • The Big-O is not concerned with factors that do not change as the input increases. • Big O does not care about extra RAM or anything done to the computer to make it faster. • The only thing Big-O is concerned with is the speed relative to other algorithms (instead of actual speed).

  31. What Big O is • Good indicator of what algorithm to use once you take your individual circumstances into consideration • Works great for optimization • Big-O of a given algorithm combined with the specific problem knowledge is a great way to choose the best algorithm for your situation

  32. Remember These • Big-O means worst-case • Big-O gives an upper-bound • Big-Omega means best-case • Big-Omega gives an lower-bound. • Big-Theta means average-case The above are oversimplifications, but it’s a good way to remember things.

More Related