Docsity

Data Abstraction and Algorithms, Exams of Computer Science

Toggle sidebar
bg1
OCR A Level Computer Science Paper 2
What is computational thinking? - ANS The ability to think logically about a problem in a way a computer
can execute it and apply techniques for solving it using a set of problem solving methods.
Why is computational thinking important? - ANS As many overarching problems are very difficult to
understand
What is the aim of computational thinking? - ANS To be able to make an overarching problem
understood and then formally represented and solved
What does computational thinking require? - ANS Computational thinking requires algorithmic thinking
What stages does algorithmic thinking require? - ANS - Understanding the problem
- Formulate the problem
- Design an algorithm
- Implement the algorithm
- Run the code and solve the original problem
What does formulating the problem entail? - ANS Producing a concise representation of the problem
using abstraction and/or mathematical notation
What is abstraction? - ANS Abstraction is the process of removing the unnecessary details and leaving
only the key elements of a problem to allow focus on the essential features making an overarching
problem easier and potentially faster to solve giving an alternate representation of reality
Give examples of abstraction - ANS - Variables
- Objects
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Partial preview of the text

Download Data Abstraction and Algorithms and more Exams Computer Science in PDF only on Docsity!

OCR A Level Computer Science Paper 2

What is computational thinking? - ANS The ability to think logically about a problem in a way a computer can execute it and apply techniques for solving it using a set of problem solving methods. Why is computational thinking important? - ANS As many overarching problems are very difficult to understand What is the aim of computational thinking? - ANS To be able to make an overarching problem understood and then formally represented and solved What does computational thinking require? - ANS Computational thinking requires algorithmic thinking What stages does algorithmic thinking require? - ANS - Understanding the problem

  • Formulate the problem
  • Design an algorithm
  • Implement the algorithm
  • Run the code and solve the original problem What does formulating the problem entail? - ANS Producing a concise representation of the problem using abstraction and/or mathematical notation What is abstraction? - ANS Abstraction is the process of removing the unnecessary details and leaving only the key elements of a problem to allow focus on the essential features making an overarching problem easier and potentially faster to solve giving an alternate representation of reality Give examples of abstraction - ANS - Variables
  • Objects
  • Layers
  • Data models
  • Data structures
  • entity-relationship diagrams What is data abstraction? - ANS Data abstraction is using a data structure without being concerned how it's implemented Give an example of data abstraction - ANS creating a stack in a subroutine without having to know how they will be implemented What is generalisation? - ANS Generalisation is a part of the abstraction process by grouping together items with similar features that are relevant to the problem (i.e. ignoring irrelevant features). What can sometimes be deduced from generalisation? - ANS From generalisation a common approach that may already exist or can be created can be discovered which can then be reused to solve similar problems Why is all high level coding an abstraction? - ANS All high level coding is an abstraction because one high level command may required several machine code instructions to complete. The programmer does not need to know how this high level command is implemented into the computer at a machine code level What are layers? - ANS Layers is the practice of organising programs into separator functional components that interact in a hierarchical manner with each layer usually only having an interface to the layer above and the layer below it What is a data model? - ANS A data model is an abstract model that organises elements of data and how they relate to one another and to real world entities

If problem the abstract model is representing can be solved using a computer program what must you then need to consider? - ANS - What are the key features of the problem

  • How will it be used
  • Who will be using it
  • What is the skill set of the target user group
  • What are the features required by the target audience and stake holders for the program By applying the considerations before developing an abstract program what does it allow for? - ANS By considering all the factors before creating an abstraction model, only the relevant features are included and unnecessary detail not required by the target user group can be omitted What is thinking ahead? - ANS Identifying the preconditions of a system, the inputs, outputs and reusable components. What may you consider when outlining a solution's outputs? - ANS - on screen information
  • Printed data
  • Data to be stored
  • Actions for the computer to complete In order to produce the necessary outputs what does a program require? - ANS In order to produce the necessary outputs, the program must have the necessary inputs. At this stage, the source of those inputs and the order and format in which they are supplied is an important consideration What about the data must be considered when designed a proposed solution to the problem? - ANS The designer must decide upon data and structures required for the proposed solution to the problem What are preconditions? - ANS Preconditions are requirements which must be met before a program can be executed.

Give examples of preconditions that can be specified within documentation - ANS - Requirements for the specification specification the device to be able to run the program

  • the operating system required to run the program
  • any additional software or hardware Give examples of preconditions when planning the development of a program or routine - ANS - Sub programs will need the correct data passed to them
  • Input data should be validated to ensure it meets essential criteria
  • actions need to be validated to ensure they will not crash the program if erroneous results are returned Give example of the preconditions that need to be applied for an algorithm traversing a binary tree? - ANS - what type of tree it is, for example binary
  • if it is ordered
  • traversal order What is cache? - ANS Cache is very fast memory with L1 found on the CPU and cats as a temporary store for the most frequently used instructions and data. How is the contents of what's stored in cache determined? - ANS An algorithm anticipates what instructions and data will need to be stored there ready for fast access to improve efficiency and is vital component of thinking ahead Why is cached data important? - ANS Cached data can replace the need for recalculations or the need to transfer data from slow to access storage online or on a disk Give an example for how caching is used for web access - ANS Caching is used extensively for web access where frequently used pages are stored for future use

What are the advantages of reusing pre-written components - ANS The advantages of reusing pre- written components:

  • They are reliable and bug free having been tested and used many times
  • they save time for the programmer
  • they saves on development cots for a project
  • mathematical techniques and other expert processes can be optimized by experts for computational efficiency Sometimes why may it be more appropriate to start from scratch rather than use pre-written components? - ANS There may be some compatibility issues when using prewritten code What is decomposition? - ANS Decomposition is the process of breaking down problems into smaller and more manageable sub problems so each one is self contained can be solved and recognised individually and effectively in order to make the overarching problem easier to solve Describe how top level hierarchal structure diagrams are good visualisations for problems, their solutions and decomposition - ANS Top down design is used to make complex problems easier to understand and solve as each branch is repeatedly sub divided until the problem is broken down into tasks that are able to be solved at the lowest level What types of solutions may be inappropriate for top level diagrams? - ANS Event driven programs do not easily fit into the model of hierarchal structure as there are parallel strands for linked objects but the top down design can be used for the processes within these linked objects After decomposition has occurred what should then take place? - ANS Following decomposition, development for each individual solution should take place What could each solution for a decomposed subproblem be? - ANS - A pre existing function or subprogram
  • An existing solution that can't be modified
  • An individual task that can be allocated to a programmer What would each decomposed sub problem represent? - ANS Each decomposed subproblem should represent a single self contained solution model estate can be developed and tested independently from the rest of the code and then integrated into the main solution Why is it important to identify the order in which individual modules must be developed and tested? - ANS As some modules required data passed from a previous component as an input What must happen as data is passed between modules? - ANS As data is passed between modules, the validity of the data should be checked before it is passed on What is a sub procedure? - ANS A sub procedure/procedure is a named part of a larger process that may be used several times but does not return any values to the calling code What does thinking logically involve? - ANS Thinking logically involves inferring things from what is known and requires understanding where decisions need to take place and their consequences What are the two approaches to thinking logically? - ANS Induction proposing a hypothesis based on observations and can be done by observing and collecting evidence of existing systems in order to propose a solution when designing one for a stake holder. Useful for real world systems Deduction using underlying rules to determine how a system should work such as developing a simulation or model for a scientific or mathematical problem which have known rules that will be applied to produce the required output What is a paradigm? - ANS A programming paradigm is an approach to programming (not a particular type of language)

Give an example of how a choice of loop can drastically change the output of a program? - ANS A repeat loop always executes at least once while a while loop may never have to run if the initial condition isn't met What user involved decisions may need to be considered when developing software? - ANS - Identify where the user will need to make decisions

  • identify and provide for all the possible outcomes for those decisions
  • prepare routes through the program for all possible outcomes form decisions
  • validate any inputs Give examples on how thinking concurrently can be applied to solution design - ANS Sometimes resources can be shared by parallel processing and during development, a large team of programmers could be working on modules simultaneously if modules are not interdependent What does a designer look for in a concurrent approach to a program? - ANS In a concurrent approach to a program, the designer will look for tasks that can be completed simultaneously What are the benefits to concurrent processing? - ANS + More tasks can be completed in the same time frame which is particularly useful for graphics processing
  • processor time is used more effectively as the program can execute other tasks while it waits for a process to complete (e.g. user input or data retrieval) What are the trade-offs that must be considered with concurrent processing? - ANS - in more complex programs there may be delays while other parts of the programs complete
  • organisation of the separate tasks and switching between processors can cause delays in processes starting and actually slow down the program
  • some problems just cannot be broken down into tasks that can be completed simultaneously
  • problems with large sections that need to be sequentially completed will not benefit from other parts being processed simultaneously

What does genuine parallel processing require? - ANS Multi core processors. Parallel processing can have significant benefits if problem is suited to being broken down into modules that can be processed simultaneously though time and processing power may be taken up in deciding which tasks can be split up and the reassembly of multiple threads In a single core processor, how the may the illusion of parallel processing be given? - ANS Giving a small time slice to each tasks int he processor meaning that tasks are being completed sequentially but appear simultaneously What is an algorithm? - ANS An algorithm is a sequence of unambiguous rules and instruction used for solving or completing a specific task What type of representation is an algorithm and what is the advantage of this? - ANS An algorithm is a generalised representation so can be used for similar problems and a wide range of inputs What must occur to combat the fact that many different algorithms can solve the same problem? - ANS Algorithms must be compared too determine which is most suitable by looking at the best and worst case scenarios for both types of complexity What are the two complexities algorithms differ in? - ANS Algorithms differ in:

  • Execution time
  • Execution space What do space and time complexity together make up? - ANS An algorithm's efficiency is made up of space and time complexity Define an algorithm's efficiency - ANS An algorithm's efficiency is a reflection on the amount of CPU time or memory space an algorithm require to execute
  • Logarithmic
  • Linear
  • Linearithmic
  • Polynomial
  • Exponential What is the Big O notation for constant complexity? - ANS O(1) What is the Big O notation for logarithmic complexity? - ANS O(log n) What is the big O notation for Linear complexity? - ANS O(n) What is the big O notation for linearithmic complexity? - ANS O(n log n) What is the big O notation for polynomial complexity? - ANS O(n^k) [where k is a constant greater or equal to 0] What is the Big O notation for exponential complexity? - ANS O(k^n) [where K is a constant greater than 1] What can Big O can examine? - ANS Big O can examine both space (RAM) and time (CPU execution time) complexities What is constant complexity and give an example? - ANS Constant complexity is where the complexity remains constant regardless of data set size and is the most efficient. Used for simple statements (no loops) and can encompass tasks such as pushing/popping from stacks) Gives a horizontal line on a time/data set graphq

What is logarithmic complexity and give an example? - ANS Logarithmic complexity involves the rate of complexity increase decreasing as the data set increases and has a good efficiency as very scalable Can be seen in divide and conquer techniques such as binary search (quick and merge sort are divide and conquer but are linearithmic) Give a log graph What is linear complexity? - ANS Linear complexity is where complexity is directly proportional to data set size Has a fair efficiency Seen in standalone loops such as linear search Gives a diagonal straight line graph passing through origin (direct proportion) What is polynomial complexity? - ANS Polynomial complexity is when complexity is proportional to the size of the data set rated to the exponent (usually 2) --> Usually when nested loops occur (n^loops) such as bubble and insertion sorts

  • Poor efficiency You can have quadratic complexities O(n^2) as well as Cubic O(n^3) for example What are two values of k as an exponent that do not give a polynomial complexity? - ANS When k is 0 it is constant complexity as n^0 = 1 When k is 1 it is linear complexity as n^1 = n What is exponential complexity? - ANS Exponential complexity O(k^n) --> K is usually 2 due to boolean decisions with a binary outcome Normally seen in recursive algorithms with K being number of recursive calls

if found == true then print("Item found at position " + count) else print("item not found") What are the advantages of linear searches? - ANS + Simple to code and implement

  • Suitable for small and unsorted data sets
  • Suitable for use on any type of data structure What are the disadvantages of linear searches? - ANS - inefficient for large data sets
  • not as suitable for sorted data sets (binary can do it quicker) What is the best case time complexity for a linear search but what condition must the algorithm include for this to be the case - ANS O(1) As long as the algorithm terminates as soon as search item found This is because the best case is the first item in the list What is the average time complexity for a linear search? - ANS O(n) for each extra item in the data set, an extra iteration is required in the loop What is the worst case time complexity for a linear search? - ANS O(n) as worst case is the last item in the list so for every extra piece of data in a data set, an extra iteration of the loop is required What is the space complexity of a linear search and why? - ANS O(1) as linear search has the same working values no matter the size of the data set

What is a binary search? - ANS A binary search is a searching algorithm utilising a divide and technique for ordered data sets by repeatedly dividing the data se tin two and eliminating the half in which the search item is not located until it is found. Give the code for a binary search - ANS items.Sort // any appropriate sorting algorithm found = false Lbound = 0 UBound = items.length- input(searchItem) While Lbound <= Ubound AND found == false mid = (LBound + Ubound) DIV 2 if items[mid] == searchItem then found = true else if items[mid]<searchItem then Lbound = mid + else UBound = mid - End If End If End While If found == true print ("Item found at position " + midpoint) else

What is the space complexity for a binary search and why? - ANS O(1) as same working values What is another important factor to include when examining and comparing complexities with binary search? - ANS The sorting algorithm used will also have its own complexity What is a bubble sort? - ANS A bubble sort is a method of sorting data by comparing consecutive items in a data set and swapping them if necessary. Once the algorithm reaches the end of the data set, it returns to the beginning and repeats the process until a pass through the data set is completed without a swap being made Carry out a bubble sort upon the following data set leaving a space between each pass {Goofy, Pluto, Donald, Minnie, Mickey} using brackets to show comparisons - ANS [Goofy Pluto] Donald Minnie Mickey Goofy [Pluto Donald] Minnie Mickey Goofy Donald [Pluto Minnie] Mickey Goofy Donald Minnie [Pluto Mickey] Goofy Donald Minnie Mickey Pluto // Result at end of Pass 1 [Goofy Donald] Minnie Mickey Pluto Donald [Goofy Minnie] Mickey Pluto Donald Goofy [Minnie Mickey] Pluto Donald Goofy Mickey [Minnie Pluto] Donald Goofy Mickey Minnie Pluto//Result at end of Pass 2 [Donald Goofy] Mickey Minnie Pluto Donald [Goofy Mickey] Minnie Pluto Donald Goofy [Mickey Minnie] Pluto

Donald Goofy Mickey [Minnie Pluto] Donald Goofy Mickey Minnie Pluto // No swaps made in Pass 3 so sorted list returned What can be said about the bubble sort at the end of each pass? - ANS At the end of each pass, the largest unsorted item will be sorted in its appropriate place at the end of the data set. Give the code for a bubble sort? - ANS swapped = true while swapped == true swapped = false for count = 0 to items.Length - if items[count] > items[count+1] temp = items[count] items[count] = items[count+1] items[count+1] = temp swapped = true End if Next count End while What are the advantages of bubble sort? - ANS + Good on small data sets

  • simple to code and implement What are the disadvantages of bubble sort? - ANS - inefficient for large data sets
  • requires multiple passes Describe and explain the best case complexity of a bubble sort - ANS O(n)