9618 Computer Science
AS Content
Chpater 1 Information representation
1.1 Data representation
1.2 Multimedia
1.3 Compression
Chapter 2 Communication
2.1 Networking
2.2 The internet
Chpater 3 Hardware
3.1 Computers and their components
3.2 Logic Gates and Logic Circuits
Chapter 4 Processor Fundamentals
4.1 Central Processing Unit (CPU) Architecture
4.2 Assembly Language
4.3 Bit manipulation
Chapter 5 System Software
5.1 Operating Systems
5.2 Language Translators
Chapter 6 Security, privacy and data integrity
6.1 Data Security
6.2 Data Integrity
Chpater 7 Ethics and Ownership
7.1 Ethics and Ownership
Chapter 8 Databases
8.1 Database Concepts
8.2 Database Management Systems (DBMS)
8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
Chapter 9 Algorithm Design and Problem-solving
9.1 Computational Thinking Skills
9.2 Algorithms
Chapter 10 Data Types and Records
10.1 Data Types and Records
10.2 Arrays
10.3 Files
10.4 Introduction to Abstract Data Types (ADT)
Chapter 11 Programming
11.1 Programming Basics
11.2 Constructs
11.3 Structured Programming
Chapter 12 Software Development
12.1 Program Development Life cycle
12.2 Program Design
12.3 Program Testing and Maintenance
A2 Content
Chapter 13 Data Representation
13.1 User-defined data types
13.2 File organisation and access
13.3 Floating-point numbers, representation and manipulation
Chpater 14 Communication and internet technologies
14.1 Protocols
14.2 Circuit switching, packet switching
Chpater 15 Hardware
15.1 Processors, Parallel Processing and Virtual Machines
15.2 Boolean Algebra and Logic Circuits
Chapter 16 Operating System
16.1 Purposes of an Operating System (OS)
16.2 Translation Software
Chpater 17 Security
17.1 Encryption, Encryption Protocols and Digital certificates
Chpater 18 Artificial intelligence (AI)
18.1 Artificial Intelligence (AI)
Chapter 19 Computational thinking and problem solving
19.1 Algorithms
19.2 Recursion
Chapter 20 Further programming
20.1 Programming Paradigms
20.2 File Processing and Exception Handling
Mr. Theo
-
+
首页
19.1 Algorithms
# Linear search ```Pseudocode DECLARE myList : ARRAY[0:9] OF INTEGER DECLARE upperBound : INTEGER DECLARE lowerBound : INTEGER DECLARE index : INTEGER DECLARE item : INTEGER DECLARE found : BOOLEAN upperBound ← 9 lowerBound ← 0 OUTPUT "Please enter item to be found" INPUT item found ← FALSE index ← lowerBound REPEAT IF item = myList[index] THEN found ← TRUE ENDIF index ← index + 1 UNTIL (found = TRUE) OR (index > upperBound) ``` ```Python #Python program for Linear Search #create array to store all the numbers myList = [4, 2, 8, 17, 9, 3, 7, 12, 34, 21] #enter item to search for item = int(input("Please enter item to be found ")) found = False for index in range(len(myList)): if(myList[index] == item): found = True if(found): print("Item found") else: print("Item not found") ``` # Binary search ``` DECLARE myList : ARRAY[0:9] OF INTEGER DECLARE upperBound : INTEGER DECLARE lowerBound : INTEGER DECLARE index : INTEGER DECLARE item : INTEGER DECLARE found : BOOLEAN upperBound ← 9 lowerBound ← 0 OUTPUT "Please enter item to be found" INPUT item found ← FALSE REPEAT index ← INT ( (upperBound + lowerBound) / 2 ) IF item = myList[index] THEN found ← TRUE ENDIF IF item > myList[index] THEN lowerBound ← index + 1 ENDIF IF item < myList[index] THEN upperBound ← index - 1 ENDIF UNTIL (found = TRUE) OR (lowerBound = upperBound) IF found THEN OUTPUT "Item found" ELSE OUTPUT "Item not found" ENDIF ``` # Bubble sort ``` DECLARE myList : ARRAY[0:8] OF INTEGER DECLARE upperBound : INTEGER DECLARE lowerBound : INTEGER DECLARE index : INTEGER DECLARE swap : BOOLEAN DECLARE temp : INTEGER DECLARE top : INTEGER upperBound ← 8 lowerBound ← 0 top ← upperBound REPEAT FOR index ← lowerBound TO top - 1 Swap ← FALSE IF myList[index] > myList[index + 1] THEN temp ← myList[index] myList[index] ← myList[index + 1] myList[index + 1] ← temp swap ← TRUE ENDIF NEXT index top ← top -1 UNTIL (NOT swap) OR (top = 0) ``` ##### two factors that may affect the performance of a sorting algorithm. - The initial order of the data - The number of data items to be sorted - The efficiency of the sorting algorithm ##### the necessary condition for a binary search - The list to be searched must be ordered/sorted ##### how to perform a binary search - Find the middle item / index - Check the value of middle item in the list to be searched - If equal item searched for is found - If this is not equal/greater/less than the item searched for - … discard the half of the list that does not contain the search item - Repeat the above steps until the item searched for is found - … or there is only one item left in the list and it is not the item searched for // lower bound > / = upper bound ##### how the performance of a binary search varies according to the number of values in the array - As the number of items in the list increases the time to search the list increases ##### Compare the performance of the algorithms for a binary search and a linear search using Big O notation for order of time complexity - Linear search O(n) and Binary search O(log<sub>2</sub><sup>n</sup>) / O(Log n) - time to search increases linearly in relation to the number of items in the list for a linear search and logarithmically for a Binary search - time to search increases less rapidly for a binary search and time to search increases more rapidly for a linear search ##### Big O notation for time complexity of a linear search - O(n) ##### Describe the meaning of O(log n) as it applies to a binary search algorit - O(log n) is a time complexity that uses logarithmic time. - The time taken goes up linearly as the number of items rises exponentially - O(log n) is the worst case scenario (time complexity for a binary search) ##### how you could improve the simplified linked list structure. - Include a free list pointer - …to reuse the unused space - …as a linked list of free space. ##### how a new element can be added to the queue if it is implemented using two stacks - (Two stacks are required) so that the second stack can reverse the order of the first stack. - Stack 1 operates as the queue with the newest elements at the bottom. Stack 2 is empty. - To add an element, pop all the elements from stack 1 and push onto stack 2. - Push the new element onto either stack. - Pop all the elements of stack 2 back onto stack 1.
Theo
2025年5月30日 13:36
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
Word文件
PDF文档
PDF文档(打印)
分享
链接
类型
密码
更新密码
有效期