Unit 4 (Computational thinking) Flashcards
If you want to solve a problem you must follow 5 steps
Information Ideifnicition Delvopment(epplore various alternatives, and develop solutions) Selection Implementation
Flowchart is used to:
Flowhcart is used to diagrammaticaly describe an alorigthim
Sub-procedures mean
Sub-procedures mean you
An algorithm is:
An algorithm: is a serious of instructions designed to solve a problem and achieve a certain goal.
An algorithm must have the following properties: Finitness, definiteness, input, output effectiveness
Finiteness: An algorithm must always terminate after a number of steps
Definiteness: Steps must be precisely defined
Input: quanntites which are given to it initially before algorithm begins (whats put into the alg)
Output: the result of the algorithm
An identifier:
An idenfitifer: is the name that is used by the programmer to uniquely idiefntiy a variable, an object, a sub procedure etc.
Iteration is:
Iteration: is the process of repeating a series of instructions
Condition statement:
Condition statement: prefroms different instructions depending on a boolean test
Pre-planning:
Pre planning: is the process of planning osmehting in advance
Prefechting:
Prefecthing: means getting data or instruction from memory into the cache before they are actually needed. Ex, when a program requests data that was previously prefetched, it can use the pre fetched data and continue with execution, instead of waiting for the data from RAM.
`
Gannt chart:
Gannt chart: is a type of bar chart that is used for project sceuhle and project management.
Pre-condition:
Pre condition: indicates what must be true before before the sub-procudre is called
Post-condition:
Post-condiiton: indnaites what will be true when the sub producide completes its task. Ex, when cooking a meal for dinner all the necessary ingredients should be available before cooking. This is a precondition of the algorithm cooking. Agter cooking a table is neeed to facilitate eating. This is ht epost-condition for a proper dinner.
Exception:
Exception: is an act or event that disrupts the anticipated flow of the program’s execution.
Concurrent: and Concurrent processing
Concurrent: means something that happens at the same time as something else.
: means the execution of different instructions simultaneous by mutliply processor to achieve the best performance.
Abstract thinking:
Abstract thinking: means reflecting on events, ideas, attributes and relationships in a manner that hies all unnecessary details of specific objects.
Object-orinted programming:
Object-orinted programming: uses abstraction and is based on the principle that all everyday taste can be considered as entities. These entities are either objects or events. So it desibres data (properoties) and behavior (methods) of real objects. he main ideas behind Java’s Object-Oriented Programming, OOP concepts include abstraction, encapsulation, inheritance and polymorphism. Object Oriented programming (OOP) is a programming paradigm that relies on the concept of classes and objects. It is used to structure a software program into simple, reusable pieces of code blueprints (usually called classes), which are used to create individual instances of objects. In functional programming, data cannot be stored in objects, and it can only be transformed by creating functions. In object-oriented programming, data is stored in objects
Object manipulation
Object manipulation: means storing information inside object
Object manipulation
Object manipulation: means storing information inside object
Modelling and simultion:
Modelling and simultion: mathicamoal modelling refers refers to a process where a system is understood well enough and scieintens describe it usng mathematical language
Variable:
variable: acts a storage location that be used to store a value.
Variable:
variable: acts a storage location that be used to store a value.
Array of objects:
Array of objects: is an array of reference variable. represent storing multiple objects in a single name.
Array of objects:
Array of objects: is an array of reference variable. represent storing multiple objects in a single name.
Sequential search
Binary search
Bubble sort
Sequential search: is a search algorithm to find a paricuplaur element in an array,
Binary search: only used in sorted array. It relies on divide and conquer strategy.
Bubble sort: is a a sorting althrotihim that compares values and exchanges them if they are not in the correct order.
What if a programmer wishes to store integers, arrays, objects, booeans and string in one data structure
What if a programmer wishes to store integers, arrays, objects, booeans and string in one data structure? The answer is to use collections because some collections allow custom spefificion of the collection item.As far as the IB is concerned, collections areUNORDERED lists usually of UNKNOWN length or size.
What are collections and what are there command (7)
Collections have an infinite amount of space in arrays.
a collection is a data structure that holds a group of elements. It provides a way to store and manage multiple different types of variables in a single array.
additems() it used to add an item in the collection
getNext(). It is used to return the first item in the collection
ddItem( data ) = add data item to the collection .
resetNext() = start at the beginning
hasNext()tells whether there is another item in the list
getNext() - retrieves a data item from the collection
isEmpty()- check whether collection is empty
Effienency:
Effeinecy:of an algorithm refers to the amount of the computer resources required to preform itd function
Correctness:
Correctness: of an algorithm refers to the exten to which the algorithm satisfies its specification
Correctness:
Correctness: of an algorithm refers to the exten to which the algorithm satisfies its specification
What does reliablity refer to?
Reliablity: referst to the capaiablity of the algorithm to maintain a predefined level of prefornce and preofm all required functions under stated conditions
Flexibity refers to:
Felxibility: of an algorithm refers to the effort require to modify the algorithm for other phrposes than those tor which it was initially developed
Fundamental operations:
The four most fundamental operations are:
ADD
COMPARE
RETRIEVE (sometimes called LOAD) STORE (sometimes called SAVE)
Compound operation: Compound operations are composed of very large numbers of fundamental operations. Compound operations are more complex than fundamental operations. For example, if we wanted to multiply, we would simply add groups of numbers until we had found our solution.
Fundamental operation vs compound operation
- A fundamental operation could be something like add two numbers, store a number, move a number to another location in RAM etc.
- These are operations that do not require the processor to go through a large number of sub operations to reach a result.
- A compound operation is a combination of compound operation
Semantic:
Semantic: a programming language is described as the combination of its senatics, whichrefers to the meaning of every construction that is possible in the language and its syntax.
Programmers write in high-level languages because they are easier to understand and are less complex than machine code.
Semantic:
Semantic: a programming language is described as the combination of its senatics, whichrefers to the meaning of every construction that is possible in the language and its syntax.
Programmers write in high-level languages because they are easier to understand and are less complex than machine code.
translation process from a higher level language to machine code
Assemblers: Translates low-level assembly code into machine code.
A compiler is a translator that executes the translation process only once. It normally translates the whole source program into the object program. The object program is saved and next time a programmer wants to use the object program no recompilation is necessary.
An interpreter is a translator that goes through the process of translation every time the program is run. Interpretation refers to the process of reading each line (instruction) of the source program, analyzing it, translating it into the corresponding line of the object program and executing the line.
Compilers:
Advantages:
Faster execution time compared to interpreters, since the code is already translated into machine language.
Can detect and report errors in the source code before the program is executed.
Can optimize the code for performance.
Produces a standalone executable file, which can be run without the need for the compiler to be present.
Disadvantages:
Compilation process can be slow, especially for large programs.
Code cannot be executed until it has been fully compiled.
Difficult to debug, as errors are reported only after the code has been compiled.
The compiled code is machine-specific and cannot be executed on other platforms without recompilation.
Interpreters:
Advantages:
Immediate feedback and easy to debug, as errors are reported line by line as the code is executed.
Easy to use, as the code can be executed immediately without the need for a separate compilation step.
Platform-independent, as the same source code can be executed on any platform with an interpreter.
Disadvantages:
Slow execution time, as the code must be translated every time it is run.
Limited optimization options, as the code is executed as it is written.
Requires the interpreter to be present on the target machine, which may not always be possible.
Assemblers:
Advantages:
Faster execution time, as the code is translated into machine language.
Low-level control over the target machine, as assembly code provides a direct representation of the machine’s instruction set.
Smaller code size compared to high-level languages, as assembly code is more concise.
Disadvantages:
Difficult to write and maintain, as the code is written in low-level assembly language.
Platform-specific, as the code must be written for a specific target machine.
Limited abstraction, as the code must be written in terms of the target machine’s instruction set.
Searches and Sorting + Time complexity
Linear Search: A linear search is a simple search algorithm that starts at the beginning of a data structure and iterates through it one item at a time until the item being searched for is found or the end of the data structure is reached.
Time Complexity: O(n), where n is the number of elements in the data structure.
Binary Search: A binary search is an efficient search algorithm that takes advantage of the sorted nature of a data structure by dividing the search space in half with each iteration. It can only be used on sorted data structures.
Time Complexity: O(log n), where n is the number of elements in the data structure.
Selection Sort: A selection sort is a simple sorting algorithm that repeatedly finds the minimum element from the unsorted part of the data structure and places it at the beginning of the unsorted part.
Time Complexity: O(n^2), where n is the number of elements in the data structure.
Bubble Sort: A bubble sort is a simple sorting algorithm that repeatedly compares adjacent elements and swaps them if they are in the wrong order. The largest elements “bubble” to the end of the data structure until the data structure is fully sorted.
Time Complexity: O(n^2), where n is the number of elements in the data structure.
Constant:
Constant: Constants represent things and quantities that don’t change.
Object:
Object: An object is a comprised of data and actions. Actions refer to the operations that can be performed by the object.
What is =, >=, >, <=.
What is div and MOD
= Defined as ”is equals to”. It is also used to assign a value to a variable. Min=6 means that the value of 6 is assigned to variable Min
a: Defined as ”not equal to”. Min#Max means that Min is not equal to Max > Defined as “is greater than”
>= Defined as ”is greater than or equal to”
< Defined as ”is less than”
<= Defined as “is less than or equal to”
Div is defined as “integar part of quotient” example. 22 div 3 =7
Mod: calculator the remainder of deivison of one number by another
Scope of a variable is:
A global variable:
The scope of a variable defines the visibility of that variable. It defines which parts of the algorithm can store, access and retrieve the data of the variable. Sometimes it is very useful to limit the scope of a variable.
A global variable is visible to all parts of your program while a local variable has a limited scope.