Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Arrays

Searching, sorting algorithms

Greedy algorithm

pseudo code

flow charts

2 complements

Convert code to use functions

Searching, sorting algorithm

A comparison operator on the items is used to reorder an array or list of elements using a sorting
algorithm. The new order of the items in the relevant date structure is determined using the
comparison operator.

An example of sorting algorithm

Searching algorithm

It is used to check for an element or retrieve an element from any data structure where it is stored.
There are 2 different types of searching algorithms which are;

1. Sequential search
 The list or array is traversed sequentially and every element is checked.
2. Interval search
 They serve only the purpose of searching sorted data structures. These types of
searching algorithms target the search structure's center repeatedly and divide the
search space in half, making them far more effective than linier search.

Pseudo code

It is an informal way to express the design of a computer program or an algorithm. An example for a
simple program that calculates the sum of two numbers:

1. Start
2. Input first number
3. Input Second number
4. Add 1st number to 2nd number and store the result
5. Display the result
6. End

Greedy algorithm

It is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece
that offers the most obvious and immediate benefit.
For example consider the Fractional Knapsack Problem. The local optimal strategy is to choose the
item that has maximum value vs weight ratio. This strategy also leads to a globally optimal solution
because we are allowed to take fractions of an item.

It is an approach for solving a problem by selecting the best option available at the moment

Flow charts

A flow chart is a picture of the separate steps of a process in sequential order. The figure below
shows an example of a system flowchart.
Complements

They are used digitally in computers in order to simplify the subtraction operation and for the logical
manipulations.

Binary system complements

Binary system has base r = 2. The 2 types of complements for the binary system are 2’s complement
and 1’s complement

1. 1’s complement
 The 1’s complement of a number is found by changing all 1’s to 0’s and all 0’s to 1’s.
this is also known as taking complement or 1’s complement. Eg.

2. 2’s complement
 It is a binary number that is obtained by adding 1 to the Least Significant Bit (LSB) of
1’s complement of the number
 2’s complement = 1’s complement + 1. Eg. Of 2’s complement;

You might also like