end of year exam Flashcards

(56 cards)

1
Q

What are the characteristics of Binary search?

A
  • Requires the data to be sorted
  • keeps dividing the data in halves til the target is found or when the minimum more than the maximum
  • Efficent for large data sets as dividing is alot quicker than going through each value in the data set
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What structures are used in bubble sort

A

Nested loop

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

What is sequential search

A

iterates through a set of data until the target is found

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

What are the characteristics of sequential search

A
  • works by iterating through a set of data sequentially till the target is found
  • it is the simplest search al;gorithm
  • data does not need to be sorted
  • might need to go through the whole array or most of it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the code for sequential search

A

N = [ 2, 9, 5, 6, 7, 8] // Array of unsorted elements
X = 7 // Search value
FOUND = false //

loop COUNTER from 0 to 5
if N[COUNTER] = X then
FOUND = true
output N[COUNTER], “found at position” , COUNTER
end if
end loop

if FOUND = false then
output X, “ not found “
end if

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

What is binary search

A

divides a range of valyes into halves and continues that process narrowing it down till the target is found

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

code for binary search

A

ARR =
X = // target
MIN = 0
HIGH = 12 // number of elements in the array - 1
FOUND = false
MID = 0

loop while FOUND != true AND MIN <= HIGH
MID = ((MIN + HIGH) div 2)
if ARR[MID] = X then
FOUND = true
else if X > ARR[MID] then
MIN = MID + 1
else
HIGH = MID - 1
end if
end while loop

if FOUND = true then
Output X, “FOUND AT THE ARRAY INDEX” , MID
else
Output X, “ was not found”
end if

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

Advantages and disadvantages of binary search

A

Advantages

-Fewer Comparisons as it eliminates half each time
-Efficient for Large Datasets

Disadvantages

  • requires a sorted list of data
  • harder to implement
  • Not as efficent for constantly changing lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Advantages and disadvantages for sequential search

A

Advantages

  • Works on Unsorted Data
  • simple to implement
  • Effective on Small Datasets

Disadvantages

  • Inefficient for Large Datasets
  • might have to go thorugh the whole data set to find the target or worst case scenario iterate through the entire array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is bubble sort

A

compares adjacent elements and exchanges them if they are not in the right order. after each loop one less element needs to be compared

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

characteristics of bubble sort

A

After each loop, one less element needs to be compared
The algorithm is very slow and impractical for most cases
Repeatedly steps through the array to be sorted
Simple sorting algorithm

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

code for bubble sort

A

Temp = 0
ARR = [. . . . .]
loop M from 0 to ARR .length-1
Loop N from 0 to ARR.length - M
If ARR[N] > ARR [ N + 1] then
Temp = ARR[N+1]
ARR[N+1] = ARR[N]
ARR[N] = Temp
end if
end loop

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

What is selection sort

A

divides the array into two sections, the first section is already sorted elements and the second section is unsorted elements. it finds the smallest element in the unsorted section and replaces it with the leftmost element in the unsorted section

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

Characteristics of selection sort

A

Simple and inefficient sorting algorithm
Divides array into two sections
First section contains already sorted elements
The second contains the unsorted elements
At the beginning the section that contains the sorted elements is empty
And the section with the unsorted elements is the entire array
The algorithm finds the smallest element ( or largest depending on sorting order) in the unsorted section and exchanges it with the leftmost element in the unsorted section

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

Code for selection sort

A

ARR = [1, 663,8,2,4,3]
N = 0
TEMP = 0
loop MIN from 0 - ARR.length - 2
N = MIN
loop UNSORTED from MIN + 1 to ARR.length -1
if ARR[UNSORTED] < ARR[N] then
N = UNSORTED
end if
end loop
TEMP = ARR[N]
ARR[N] = ARR[MIN]
ARR[MIN] = TEMP
end loop

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

Suggest a suitable algorithm to solve a specific problem what do u need to look at

A

Efficiency: amount of the computer resources required to perform its functions. Minimizing the use of various resources such as the CPU and memory is important.
Correctness: the extent to which the algorithm satisfies its specification, free from fault, and fulfills all objectives set during the design and implementation.
Reliability: refers to the capability of the algorithm to maintain a predefined level of performance
Flexibility: effort required to modify the algorithm for other purposes

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

Need for Pre-Conditions

A

describes the starting state before the execution of an algorithm, indicates what needs to be true before the sub-procedure is called

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

Need for post conditions

A

indicates what will be true when the sub-procedure completes its task,describes the final states after the execution of an algorithm

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

What is a collection

A

a data structure that stores a group of elements of the same or different data types. Collections have a set of methods that can be called on to help access data and iterate through

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

what are the collection operations

A

add.item()
get.Next()
resetNext()
hasNext()
isEmpty()

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

what is a sub program

A

A sub-program is a unit that contains a sequence of computer instructions that perform a specific and predefined task.

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

Advantages of breaking a program into sub programs

A

-breaking complex programming jobs into smaller simpler jobs
- enables code reuse
-reduces programming code duplication

23
Q

characteristics of a collection

A

Resizeable
stores different data types
has a set of methods that can be called upon to help iterate through the data and access it

24
Fundamental operations of a computer
Add Compare Retrieve And store
25
Distinguish between fundamental and compound operations of a computer
fundamental operations are the basic operations a computer can perform directly which are add compare retrieve and store. Compound operations are a combination of multiple fundamental operations
26
Outline what is meant by concurrent processing
execution of different instructions simultaneously by processors
27
advantages of concurrent processing
Better planning and coordination of resources
28
What does the term concurrent mean
something happening the same time as something else
29
How can u transfer data from a collection to an array * CODE
COL = (. . . . . . . .) * collection of data ARR = new Array() X = 0 Y = 0 loop while COL.hasNext X = COL.getNext ARR[Y] = X Y=Y+1 end loop
30
How can u transfer data from an array to a collection
COL = new Collection() ARR = (. . . . . . . . ) loop N from 0 to Arr.length -1 Col.addItem(ARR[N] end loop
31
Define abstraction
process of simplifying your scenario to only consider relevant info hiding the rest
32
what are the benefits of abstraction
-helps create modular code by breaking down complex systems into smaller manageable units making the code more organized - simplifies code comprehension by hiding irrelevant info making it easier for developers to understand
33
Define inheritance
when a sub-class inherits the data and actions of a superclass
34
what are the benefits of inheritance
-child classes may add new functionality extending the parents actions and data or redefining them - child classes that inherit data from the parent class will not need to be altered in the event that an inherited action needs to be upgraded
35
what does the term super mean
super calls the constructor of the parent class to initialize the variables
36
what does the term "this" mean
this is used to diffrentiate between the parameters and the instance variables
37
what does the term final mean
final is used to create a constant in java
38
what does the term static mean
static means that all instances of the class share the same value for that data, if its altered, its altered for all instances
39
What are access modifiers
essential tools that define how members of a class can be accessed from other parts of the program
40
what does private mean
it means that it can only be accessed by the class that defines it
41
what does protected mean
it means that it can only be accessed by the class that defines it and its sub classes
42
what does public mean
it means that it can be accessed by all classes
43
what is the benefit of access modifiers
allow you to encapsulate your code and define clear visibility for classes and members
44
What are primitive data types
a predefined identifier provided by the programming language as a basic building block
45
what is String class
an object part of the java language that has methods to manipulate the data
46
what does encapsulation mean
inclusion of both data and actions into a single component
47
what are the benefits of encapsulation
-complexity hiding -changes to internal implementations of a class dont affect other parts of the code that use it making update the code simpler -as a programmer you dont need to know or care about how a class stores its name field
48
what is polymorphism
when a method can take multiple forms
49
What is over-riding
overriding is when a child class uses the same method from the parent class but redefining it to better suit the sub-class
50
Benefits of overriding
- allows sub class to customize behavior defined in the super class making ode more flexible and extensible
51
What is overloading
over loading is when a method with the same name in the same class takes different parameters
52
Benefits of polymorphism
-objects can have same name, different signatures, reducing complexity - sub classes can have their own unique actions as well as override or improve parent actions
53
Benefits of overloading
- allows to use the same method name for different purposes reducing code duplication - using same method name makes code easier to understand as it helps convey methods that perform similar tasks
54
what does the term Extends mean
used by a subclass to identify which superclass it belongs to.
55