2.1 Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is Computational Thinking?

A

Computational thinking involves taking a complex problem and breaking it down into a series of small, more manageable problems. Each of these smaller problems can then be looked at individually.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are three main principles of computational thinking

A
  • Abstraction
  • Decomposition
  • Algorithmic thinking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Abstraction and give an example

A
  • *The process of removing unnecessary details and including only the**
  • *relevant details. It is a method of computational thinking that focusses**
  • *on what is important in problem solving.**

Example Sat Nav

We have to ask ourselves what is important and not important
Abstraction makes it clear to suggest a function or process in a simple and efficient manner.

One way to design an algorithm we could use flowcharts to represent the algorithm visually

Abstraction allows us to create a general idea of what the problem is and how to solve it. The process instructs us to remove all specific detail and any patterns that will not help us solve our problem. This helps us form our idea of the problem. This idea is known as a ‘model’.

Consider the problem of how a program might be required to calculate the area of any rectangle. All rectangles share general characteristics:

  • a width
  • a height
  • area = width × height

When abstracting, certain details are discarded but others are kept:

  • all rectangles have a width, but for the program design the actual rectangle width is not needed
  • all rectangles have a height, but for the program design the actual rectangle height is not needed
  • area is always width × height

To solve this problem, all the program needs to be able to do is input a width and a height, then calculate the area from those numbers. The actual numbers are irrelevant - they change with every rectangle - and so are discarded.

An example of abstraction is the London Underground map. It details tube and rail lines and the stations that are on them. That is all that is required for a passenger to be able to plan a journey from one station to another. Other details, such as real geographical location, distance between stations, depth underground and number of platforms are not included as they are irrelevant to journey planning on the Underground.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is decomposition?

A
  • *The process of breaking a complex problem down into smaller more**
  • *manageable parts. Dealing with many different stages of a problem at**
  • *once is much more difficult than breaking a problem down into a**
  • *number of smaller problems and solving each, one at time.**

e.g. Crossing a road.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the advantages of Decomposition?

A
  • Makes problems easier to solve as Different people can work on different parts of a problem at the same time.
  • Reducing Development time
  • Program components developed in one program can be used in other programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an Algorithm?

A

An algorithm is a logical, step-by-step process for solving a problem.

Algorithm production is part of algorithmic thinking, an important concept in computational thinking. This focuses on how a desired solution can be reached by identifying the steps needed to get there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is algorithmic thinking?

A
  • *A way of getting to a solution by identifying the individual steps needed.** By creating a set of rules, an algorithm that is followed
  • *precisely, leads to an answer.**

Algorithmic thinking allows solutions to be
automated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an input?

A
  • Anything which needs to be supplied to the program
  • Often input by the user
  • Consider an appropriate variable name and data type for the input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a process?

A
  • Consider what calculations need to be performed while the programming is running
  • Does data need to change formats or data types
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is outputs?

A
  • Consider what your program need to output
  • Consider what form this output need to take
  • Consider an appropriate variable name and data type for any output.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Draw the different types of flow diagrams

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the two types of error?

A

Syntax errors - errors which break the grammatical rules of the programming language. They stop it from being run/translated

Logic Errors - Produce an unexpected output. They will not stop the program from running.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Logic Errors?

A
  • Logic errors are errors which produce unexpected output
  • On their own they won’t stop the program running.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are Trace Tables used for?

A

Trace tables are a great way to spot logic errors

They show the input and the expected result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does a binary search work?

A

A binary search is an efficient method of searching an ordered list.

A binary search works like this:

  • *1. Start by setting the counter to the middle position in the list.**
  • *2. If the value held there is a match, the search ends.**
  • *3. If the value at the midpoint is less than the value to be found, the list is divided in half. The lower half of the list is ignored and the search keeps to the upper half of the list.**
  • *4. Otherwise, if the value at the midpoint is greater than the value to be found, the upper half of the list is ignored and the search keeps to the lower half of the list.**
  • *5. The search moves to the midpoint of the remaining items. Steps 2 through 4 continue until a match is made or there are no more items to be found.**
  • A binary search is a much more efficient **algorithm** than a linear search. In an ordered list of every number from 0 to 100, a linear search would take 99 steps to find the value 99.
  • A binary search would only require seven steps.
  • However, a binary search can only work if a list is ordered.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Pros and Cons of Binary search:

A
  • Can be done with letters as well as numbers
  • More efficient than a linear search on average and on large sets

• Requires the data set to be in order of a key field.

17
Q

What are structure diagrams used for?

A
  • Structure diagrams illustrate problem decomposition.
  • They can be used for developers to understand a problem to code and to share with users during systems analysis.
  • They are produced using a method known as step-wise refinement.
  • Break problem down using decomposition into ever smaller components.
  • Some areas of the program will needed breaking down more than others.
  • The lowest level nodes should achieve a single task.
  • These can then be coded as a single module or sub-program.
18
Q

How does a Linear Search Work

A

A linear search is the simplest method of searching a **data** set.

Starting at the beginning of the data set, each item of data is checked until a match is made. Once the item is found, the search ends.

A way to describe a linear search would be:

  • *1. Find out the length of the data set.**
  • *2. Set counter to 0.**
  • *3. Examine value held in the list at the counter position.**
  • *4. Check to see if the value at that position matches the value searched for.**
  • *5. If it matches, the value is found. End the search.**
  • *6. If not, increment the counter by 1 and go back to step 3 until there are no more items to search.**
19
Q

What are Pros and cons of Linear search:

A
  • Doesn’t require the data set to be in order.
  • Will work on any type of storage device.
  • efficient for small data sets.

• Is very inefficient for large data sets

20
Q

How does a bubble sort work

A
  • A bubble sort is the simplest of the sorting **algorithms**.

Bubble sorts work like this:

  • Start at the beginning
  • Compare the first value in the list with the next one. If first value is bigger, swap the positions of the two values.
  • Move to the second value in the list. Again, compare this value with the next and swap if the value is bigger.
  • Keep going until the there are no more items to compare
  • Once you have reached the end. Go back to the start of the list.
  • Each run through the list, from start to finish, is known as a pass. The bubble sort continues until a pass is made where no values have been swapped.
  • At this point, the list is sorted.
21
Q

Pros and Cons of Bubble sort?

A

Bubble sort is:

  • It is simple
  • It doesnt use much memory

But:

  • It is inefficient as sometimes it requires alot of passes
  • This means it does not cope well with big lists
22
Q

How does a merge sort work?
part 1

A
  • A merge sort uses a divide and conquer technique . The list is repeatedly divided into two until all the elements are separated individually.
  • Pairs of elements are then compared, placed into order and combined.
  • The process is then repeated until the list is recompiled as a whole.
23
Q

Pros and Cons of Merge Sort?

A
  • It is more efficient on large data sets
  • Has consistent running times

But :

  • Not suitable for small lists
  • uses lots of memory
24
Q

Insertion Sort Pros and Cons?

A
  • Copes well with small lists
  • It doesn’t require additional memory

But

  • It doesnt cope well with large lists
25
Q

How does Insertion Sort work?

A

An insertion sort is less complex and efficient than a merge sort, but more efficient than a bubble sort.

The insertion sort inserts each item into its correct position in a data set one at a time

An insertion sort compares values in turn, starting with the second value in the list.
If this value is greater than the value to the left of it, no changes are made. Otherwise this value is repeatedly moved left until it meets a value that is less than it. The sort process then starts again with the next value. This continues until the end of the list is reached.

26
Q

Advantages and Disadvantages of Psuedocode

A

Advantages and disadvantages of pseudocode

Designing an algorithm in pseudocode has benefits:

  • because pseudocode is similar to a programming language, it can be quickly and easily converted into an actual programming language
  • it is easy to understand
  • it does not matter if there are errors in the syntax - it is obvious what is intended
  • changes to the design can be incorporated quite easily

Pseudocode also has its disadvantages:

  • It can be hard to see how a program flows, for example, where does following one path as opposed to another take the program?
  • It can be time consuming to produce.
27
Q

What are all the different flowchart diagrams?

A
28
Q

How do you use sub programs in flowdiagrams?

A

Put the name of the function in the terminator

29
Q

Advangtages and Disadvantages of Flow diagrams?

A

Designing an algorithm using flow diagrams has benefits:

  • It is easy to see how a program flows. For example, where does following one path as opposed to another take the program?
  • Flow diagrams follow an international standard - it’s easy for any flow diagram user to pick up a diagram and understand it.

Flow diagrams also have their disadvantages:

  • with a large program, the diagrams can become huge in size and unwieldy to follow
  • any changes to the design may mean a lot of the diagram has to be redrawn