Programming Contrstucts Flashcards
(29 cards)
Define a Variable
A named location in computer memory used to hold data when a program is running. The value of the variable can change while the program is running
Define a Constant
A named location in computer memory used to hold data when a program is running. The value of the variable cant change while the program is running and remains constant
Define a Boolean operator
An operator that allows conditions to be combined then evaluated , the outcome is a Boolean variable
Define a Arithmetic Operator
Enables arithmetic operations to be carried out using variable
+,-,*
Define an Input Statement
A statement used to capture data which is to be used in the program
Define an Output Statement
A statement used to output data and information from the program
Define an Assignment Statement
A statement that assigns a value to a variable, constant or other data structure
A= b+c
What are the three program control structures
Sequence
Selection
Iteration
Define Sequence
denotes the order in which the instructions are carried out by the computer
Describe Selection
In selection a condition is used to decide which piece of code should be executed.
This is acheived through the use of IF statements and BOOLEAN operateors
Describe Iteration
another word for reptation
Repetitions is used when a section of code is to be carried out more than once
This can be acheived through loops
What is an Array?
An array is a data structure that holds a set of data items of the same data type
The arrays assigned a name, a size and a data type by the program
Define a Bubble Sort
Bubble sort is a simple sort that compares adjacent elements, which are compared and swapped if in the wrong order
Define an Insertion Sort
builds a sorted sub list one item at a time, the sub list become the new sorted list
How does bubble sort work?
Compare the first and second items, swap if needed. Then compare the second and third,
and so on. Repeat the whole process until no swaps are needed.
How does insertion sort work?
Start with the second item, compare it to the first, and insert it in the correct place. Then take
the third, compare to the sorted part, and insert again — like sorting playing cards in your
hand
Define Linear Search
A simple search that compares every data item in a list to the target value
Define a Binary Search
Binary Search is a fast way to find a value in a sorted list by repeatedly dividing the list in
half.
How does a linear search work
Go through each item in the list, one at a time, and check if it matches the target.
How does a Binary Search Work?
Start in the middle of the list. If the middle value is the target, you’re done. If the target is
smaller, search the left half. If it’s larger, search the right half. Repeat this process.
What is a string?
data containing text, letters or a mixtures of letter and numbers
What are the 4 string manipulation functions?
Splitting
concatenating
character searching
substring searching
Explain the string manipulation function concatenating
appending strings together relevant function of symbol
example:
string1 + “” + string 2
Explain the string manipulation function Substring Searching
using a start position and a length, it returns a substring
example:
string2 = award-winning-performance
string2.substring(6:13)
result= winning