0% found this document useful (0 votes)
123 views20 pages

Advanced CompSci Sample Pages Combined REDUCED

Uploaded by

dahjkdhsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views20 pages

Advanced CompSci Sample Pages Combined REDUCED

Uploaded by

dahjkdhsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

ADVANCED_COMPUT_SCIENCE_COVER.

qxp_COMPUTER_Science_COVER 10/10/16 4:32 PM Page 1

MARKOS HATZITASKOS, MSc


KOSTAS DIMITRIOU, Phd
ADVANCED COMPUTER SCIENCE
Advanced Computer Science: For the IB Diploma Program is a new educational resource
for all students who need to understand the High Level topics of Computer Science. This
book references all the assessment statements in the 2014 IB Computer Science subject
guide, while remaining flexible enough to be used in any educational setting, including
programming courses of moderate to advanced difficulty.
The book uses plain English allowing native and non-native young learners to master the IB
computer science High Level course. Advanced computer science for the IB Diploma
Program builds upon the successful Core Computer Science book and facilitates High Level
students to master the necessary topics.

Feature include:
• Plain English language
• Diagrams and illustrations for all key concepts
• Examination style questions with answers for all topics
• Use of IB style pseudocode, as well as actual working code in the Java
Programming Language
• A complete and efficient working Java solution that addresses a real life scenario
• One-to-one reference to the assessment statements in the IB Computer Science

For the IB Diploma Program


HIGH LEVEL COMPUTER SCIENCE
subject guide

This book allows both students and teachers to follow the wide-ranging IB Computer
Science syllabus in such a way that they can be confident that all aspects of theory and
practical exercises have been covered.
Further details about the book, including errata and programming code, can be obtained at
the following website: http://www.expresspublishing.co.uk/ibadvancedcomputerscience

ISBN 978-1-4715-5233-5
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 1
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 2

Published by Express Publishing

Liberty House, Greenham Business Park, Newbury,


Berkshire RG19 6HW, United Kingdom
Tel.: (0044) 1635 817 363
Fax: (0044) 1635 817 463
email: [email protected]
www.expresspublishing.co.uk

© Express Publishing, 2016

Design and Illustration © Express Publishing, 2016

First published 2016

Made in EU

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form, or by any means, electronic, photocopying, or otherwise, without the prior
written permission of the publishers.

This book is not meant to be changed in any way.

ISBN 978-1-4715-5233-5
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 3


 

  
    

   
    

Topic 5—Abstract data structures


5.1 Abstract data structures
Thinking recursively
5.1.1 Identify a situation that requires the use of recursive thinking.
5.1.2 Identify recursive thinking in a specified problem solution.
5.1.3 Trace a recursive algorithm to express a solution to a problem.
Abstract data structures
5.1.4 Describe the characteristics of a two-dimensional array.
5.1.5 Construct algorithms using two-dimensional arrays.
5.1.6 Describe the characteristics and applications of a stack.
5.1.7 Construct algorithms using the access methods of a stack.


5.1.8 Describe the characteristics and applications of a queue.


5.1.9 Construct algorithms using the access methods of a queue.
5.1.10 Explain the use of arrays as static stacks and queues.
Linked lists
Linked lists will be examined at the level of diagrams and descriptions. Stud dents are not expected to construct
linked list algorithms using pseudocode.
5 1.
5. 1 11 Describe the features and characterristics of a dynamic data structure e.
5.1.12 Describe how linked lists operate logically.
5.1.13 Sketch linked lists (single, double and circular).
Trees
Binary trees will be examined at the level ofo diagrams and descriptions. Students are not expected to construct
tree algorithms using pseudocode. Tracing and constructing algorithms aree not expected.
5.1.14 Describe how trees operate logically (both binary and non-binary).
5.1.15 Define the terms: parent, lefft-child, right-child, subtree, root and leaff.
e and preorder tree traversal.
5.1.16 State the result of inorder, postorder
5.1.17 Sketch binary trees.
Applications
5.1.18 Define the term dynamic data structure.
5.1.19 Compare the use of static and dynamic data structures.
5.1.20 Suggest a suitable structure for a given situation.

Topic 6—Resource management


6.1 Resource management
System resources
6.1.1 Identify the resources that need to be managed within a computer sysstem.
6.1.2 Evaluate the resources available in a variety of computer systems.
6.1.3 Identify the limitations of a range of resources in a specified computerr system.
6.1.4 Describe the possible problems result l ing from the limitations in the resources in a computer system.
Role of the operating system
6 1.5 EExplaiin the role of the operatting system in terms of managing memory, peripherals and hardware
6.1
interfaces.
6.1.7 Outline OS resource management techniques: scheduling, policies, multitasking, virtual memory, paging,
interrupt, polling.
6.1.8 Discuss the advantages of producing a dedicated operating system for a device.
6.1.9 Outline how an operating system hides the complexity of the hardware from users and applications.

Topic 7—Control
7.1 Control
Centralized control systems
7.1.1 Discuss a range of control systems.
7.1.2 Outline the uses of microprocessors aand sensor input in control system m s.
7.1.3 Evaluate different input devices for the collection of data in specified situations.
7.1.4 Explain the relationship between a se ensor, the processor and an output transducer.
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 4

7.1.5 Describe the role of feedback in a control system.


7.1.6 Discuss the social impacts and ethical considerations associated with the use of embedded systems.
Distributed systems
7.1.7 Compare a centrally controlled system with a distributed system.
7.1.8 Outline the role of autonomous agents acting within a larger system.

D—Object-oriented programming
D.4 Advanced program development
D.4.1 Define the term recursion.
D.4.2 Describe the application of recursive algorithms.
D.4.3 Construct algorithms that use recursion.
D.4.4 Trace recursive algorithms.
D.4.5 Define the term object reference.
D.4.6 Construct algorithms that use reference mechanisms.
D.4.7 Identify the features of the abstract data type (ADT) list.
D.4.8 Describe applications of lists.
D.4.9 Construct algorithms using a static implementation of a list.
D.4.10 Construct list algorithms using object references.
D.4.11 Construct algorithms using the standard library collections included in JETS.
D.4.12 Trace algorithms using the implementations described in assessment statements D.4.9–D.4.11.
D.4.13 Explain the advantages of using library collections.
D.4.14 Outline the features of ADT’s stack, queue and binary tree.
D.4.15 Explain the importance of style and naming conventions in code.
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 5
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 6
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 7

  
  

To my son DDiim
mitris andd m
my daughter Eli
Elliaanaa..
Never fo
f rget thhat I lovee youu..
!

     

TTo alll my friends


f that helped make
a this book a reality.
You knoww who
h you are.
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 8
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 9



  
        
       
   
 
    
    

  
 
 
   
               
        !      "          # 
    $% 
         &   
 '
  
())(      *  
   "  
   " 

 +     $ 
 '   ,  
-  .

        &  *


   
 
   

   

       /           $%0   # 
        &   
 '
   ()11 $    
     #     #        &    
' &   
  
  , -  .

+ 
  
     %       &    
   &   
 '
  /&'0         
   +  
  2  
  
#    %

  
   "     
     "  
# 
   
   +  3 


+ 
  
         
# 
    & 

&' $%         &   *
    
  #
 

#      
      + 
     
()14  

     #

+ 
   
            
 
  *

  
     + #  #   $% 
    #
 
   $% 
    #
 + 
       #     


  $ 
  
              
  + #
  #  #15 6  7 8 &    /())40 *
    6 # 
$  % 
     $%$   3  

1
6  7 8    & /())40 *
    6 #  $  % 
    
$%$   3  
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 10

+   $%9 


 

       #5

1 $  % 


 9  /())40 $% *
    :
 
( $  % 
 9  /()1(0 $% *
    :
 
; $  % 
 9  /()1(0 $% &   
  
  
4 $  % 
 9  /()1(0 $% 6 " +

# 
< $  % 
 9  /()1(0 $% 
   "
"
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 11

#$

%

! " # $%   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 


"& $%    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
+
  1
<11 = <1; 7
  1
&#    

 >
<14 = <1< +     >
<1? = <1>  1)
<1@ = <1A B

 1?
<11) &       C

 1A
D  ;)
<111 ' 
           

;)
<11( 9     ;1
<11;      ;(
+ ;>
<114 D       ;@
<11< % E   ;A
<11? +     41
<11>    #   4?
& <;
<11@         

<;
<11A *       

<;
<1() 
# 

 <4
   " C
   <?
'  (  
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& )*

! ) # (  
+ 
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ),
)& (  
+ 
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ),
  
 ?@
?11 $      
?@
?1( &#  
 >;
?1; D  
 >?
?14  #   
   
 >>
7      >A
?1< 7   9    /90>A
?1? = ?1> 9 
    C
 @(
?1@    9    @<
?1A 9   "  @>
   " C
   @A
'  (  
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& -

! * # 
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& -"
*& 
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& -"
*       A<
>11 &      A<
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 12

>1( +
           
      1 1)1
>1;   
            
 1 1);
>14 +  #             

  
1 1)4
>1< +    #        1 1)?
>1?             
  #  
1
1)?
 #
   1
1)A
>1> *           #
   1 1)A
>1@ +   

           1
111
   " C
    1 11<
'  (  
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 


!  . /%0 1


 +
+ &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 

!  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 

& $ 2
 + 2 
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&  
41 +   F
G 1 1((
4( &  
   1 1((


4; *
    

 1 1(@
44 +  
   1 1(A
4<      #!    1 1;)
4? *
   
     1 1;;
4> $    
   &#    + /&+0 1 1;>
4@   #      1 14)
4A *
  
         1 144
41) *
   
 #!     1 1<(
411 *
  
    #      
 6+ 1 1?1
41( +   
      #       
4AE411 1
1?>
41; "     
 #     1 1>1
414 9
   
  &+H   C

 #   1 1>;
41< "             1 1>;
   " C
    1 1>>
'  (  
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
,

$
 $ # 3 4 5   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
,"
&1     
  ArrayList  (
(@<
&( B

  
  ArrayList  ( (@>
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 13

'  
!/
  " . $ !($
! $!$ !(:!:(6

  $% # 
  "     #  #   
   2
      
 5
'== & % 


& ==*"-*-=% =  = &' 
+ "       #      
  + 
    " 
   
       
#
 


; /
#
 &$%%  % 




$%%  %
' $  
#( %

' ' ) ' '* %(


6 3& 
 ' % % 


7  
'  8  '    2 '
3
+&
7  2
'
3
+ 
   %  
& !   2 +'    

  % &


         


 
      +    9'
 
     
 
   9'   
 7
      #  #  
 C
     #      #    
 
# &     #     

    #       
     $   
  
      


 
$      
     #    
    
    "
+ "& !' !9   <
 +

1
$  % 
 9  /()1(0 $% *
    :
 
(
+    /()1< I # 1> >0
0 $ 
   7    145)
);
I # 1> ()14   5JJ    J J+ KK


Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 14

    
#        
+ 
                          
         $ <1 +    
       
             #    
 5

• &    #        


• 9         
• &    #            
• '            #
 

+   
         +     #   
 #
  
 
 L  #     
 
 #
   
  #  # #       

 
  
    

&
       & %  *        
#    / 
1 #          #        #0 &
 

  +    #       
  &   * 
 # 

•        &   %    


  &
•       &   *
•        %   *

+   # 


      
  #             &
         # C
    1           #

       &    *  
             
 
#   

&   "      "  '


<1
       /
   &  %   * 0     
             & +

      5

1       &  *
(       &  %
;       *  %
4       &  *
<       %  &
?       %  *
>       &  *

>+ "&     ' +



     
   +  
+
      #             '  
< (    

        
#E 
    
       


Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 15

 
  + 
#     /0        #    / 0 
         #   / 0         #
 
/
"0 +  
       
#E 
/     
" 0 
 

# 
       
  
 /& %  *0

    /      


"0

  


 M 1N

$

 


  /E1    


"0

  /  & % *0

          



  /E1 


"   0

   1
7 

    


>+ "& !' !9   <


 9 '



 
+         
    #    
    #
          

+   


  # 
 #     C
     

        
     5

1          


#E       
(   
   C
              
  /10   # 
;           #        
  

?
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 16

+     "   $% 


     4)) # 4?1     
     5

//hree curves that shape an equilateral triangle


//pen originally is heading at 90 degrees (x axis)
//the method pen.goForward is supposed to control
//a pen that plots line segments on the screen
//the method pen.turnLeft is supposed to change the original
//heading of the pen counter clockwise by the degrees given as a parameter.
//the method pen.turnRight is supposed to change the original
//heading of the pen clockwise by the degrees given as a parameter.
method Draw_Koch_fractal(N)
width = 400//width of the window
height = 2*width/Math.sqrt(3)//calculation of the height of the window
size = width/Math.pow(3.0, N)//size of each drawing step
initial_pen_position = pen.setposition(0, width*Math.sqrt(3)/2, 0)
//calculation of the initial pen position (0,114)
pen.setWindowSize(width, height)//initialization of the window
koch_fractal(N)//call of the Koch_fractal method
pen.turnrRight(120)//turn right by 120 degrees
koch_fractal(N)//call of the Koch_fractal method
pen.turnRight(120)
koch_fractal(N)
end method

method koch_fractal(n)
if (n == 0) then
pen.goForward(size)
else
koch_fractal(n-1)
pen.turnLeft(60)
koch_fractal(n-1)
pen.turnRight(120)
koch_fractal(n-1)
pen.turnLeft(60)
koch_fractal(n-1)
end if
end method
output Draw_Koch_fractal(N)

+   #        


#  #    IM)  <5

IM) IM1 IM(


Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 17

IM; IM4 IM<


!% "& @ 

+
+ 6    
.  
+ 
 + &

+     
 
      addIntUpTo(n)  n>0 
   
#      
 n    1 ' ""   addIntUpTo(4) 
   
 
 # 5 4 + 3 + 2 + 1 = 10


method
d addIntUpTo(n)
i
if (n == 1) then
return 1
e
else
return n + addIntUpTo(n-1)
end if
e
ethod
end me

+    
 
       9      
  

#  /    addIntUpTo      
   n-10 n-1   
 
    n = 1   

+
+ 6  6   
&

L    #  

      N

metho
od foo(n)
if (n <= 1) then
return 1
se
els
return foo(n-1) + foo(n-2)
d if
end
method
end m

ut foo(5)
outpu

& 5 8

+
+ 6 ? 6   
&

L    #  

      N

metho
od foo(n, m)
if (n <= 1) OR (m <= 1) then
return 2

"
Advanced_ComputerScience_001-150.qxp_Advanced_ComputerScience 10/10/16 3:58 PM Page 18

else
return foo(n-1, m) + foo(n, m-2)
end if
end method

output foo(5,4)

& 5 30

+
+ 6  6   
&

L    #  

      N

method foo(n, m)
output "value of n=", n, "value of m =", m
if (n <= 1) OR (m<=1) then
return 2
else
return foo(n-1, m-n)+foo(n, m-2)
end if
end method

output "Output is", foo(3,2)

& 5

value of n= 3 value of m = 2
value of n= 2 value of m = -1
value of n= 3 value of m = 0
Output is 4

+
+ 6 " 6   
&

L    #  

      N

method Foo(X,Y)
if X < Y then
return Foo(X+1,Y-2)
else if X = Y then
return 2*Foo(X+2,Y-3)-3
else
return 2*X+3*Y
end if
end method
output "Output is", Foo(3,12)

& 5

Output is 47

)
ADVANCED_COMPUT_SCIENCE_COVER.qxp_COMPUTER_Science_COVER 10/10/16 4:32 PM Page 1

MARKOS HATZITASKOS, MSc


KOSTAS DIMITRIOU, Phd
ADVANCED COMPUTER SCIENCE
Advanced Computer Science: For the IB Diploma Program is a new educational resource
for all students who need to understand the High Level topics of Computer Science. This
book references all the assessment statements in the 2014 IB Computer Science subject
guide, while remaining flexible enough to be used in any educational setting, including
programming courses of moderate to advanced difficulty.
The book uses plain English allowing native and non-native young learners to master the IB
computer science High Level course. Advanced computer science for the IB Diploma
Program builds upon the successful Core Computer Science book and facilitates High Level
students to master the necessary topics.

Feature include:
• Plain English language
• Diagrams and illustrations for all key concepts
• Examination style questions with answers for all topics
• Use of IB style pseudocode, as well as actual working code in the Java
Programming Language
• A complete and efficient working Java solution that addresses a real life scenario
• One-to-one reference to the assessment statements in the IB Computer Science

For the IB Diploma Program


HIGH LEVEL COMPUTER SCIENCE
subject guide

This book allows both students and teachers to follow the wide-ranging IB Computer
Science syllabus in such a way that they can be confident that all aspects of theory and
practical exercises have been covered.
Further details about the book, including errata and programming code, can be obtained at
the following website: http://www.expresspublishing.co.uk/ibadvancedcomputerscience

ISBN 978-1-4715-5233-5

You might also like