Ask a question from expert

Ask now

Algorithm and Programming Overview | Characteristics and IDE Analysis

33 Pages6268 Words63 Views
   

Added on  2020-06-04

Algorithm and Programming Overview | Characteristics and IDE Analysis

   Added on 2020-06-04

BookmarkShareRelated Documents
Programming algorithms
Page 1 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_1
CONTENTS
Table of Contents
1.0 INTRODUCTION...................................................................................................................... 3
2.0 Table of Contents:....................................................................................................................... 2
3.0 Difference between Algorithm and Code........................................................................................... 7
4.0 Characteristics of code................................................................................................................. 8
5.0 Implementation........................................................................................................................ 12
6.0 Review and reflection:............................................................................................................... 18
7.0 Conclusion............................................................................................................................. 33
Introduction
Page 2 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_2
An algorithm specifies a series of steps that perform a particular
computation or task. Algorithms were originally born as part of mathematics
– the word “algorithm” comes from the Arabic writer Muḥammad ibn Mūsā
al-Khwārizmī, – but currently the word is strongly associated with computer
science.
LO1
Define basic algorithms to carry out an operation and outline the
process of programming an application
Algorithm definition:
A sorting algorithm is an algorithm made up of a series of instructions that
takes an array as input, performs specified operations on the array,
sometimes called a list, and outputs a sorted array. Sorting algorithms are
often taught early in computer science classes as they provide a
straightforward way to introduce other key computer science topics like Big-
O notation, divide-and-conquer methods, and data structures such as binary
trees, and heaps. There are many factors to consider when choosing a
sorting algorithm to use.
Heap Sort is a popular and efficient sorting algorithm in computer
programming. Learning how to write the heap sort algorithm requires
knowledge of two types of data structures - arrays and trees.
The initial set of numbers that we want to sort is stored in an array e.g. [10,
3, 76, 34, 23, 32] and after sorting, we get a sorted array [3,10,23,32,34,76]
Heap sort works by visualizing the elements of the array as a special kind of
complete binary tree called heap.
Procedures to follow for Heapsort
Since the tree satisfies Max-Heap property, then the largest item is stored at
the root node.
Remove the root element and put at the end of the array (nth position) Put
the last item of the tree (heap) at the vacant place.
Page 3 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_3
Reduce the size of the heap by 1 and heapify the root element again so that
we have highest element at root.
The process is repeated until all the items of the list is sorted.
// Java program for implementation of Heap Sort
public class HeapSort
{
public void sort(int arr[])
{
int n = arr.length;
// Build max heap
for (int i = n / 2 - 1; i >= 0; i--) {
heapify(arr, n, i);
}
// Heap sort
for (int i=n-1; i>=0; i--)
{
int temp = arr[0];
arr[0] = arr[i];
arr[i] = temp;
Page 4 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_4
// Heapify root element
heapify(arr, i, 0);
}
}
void heapify(int arr[], int n, int i)
{
// Find largest among root, left child and right child
int largest = i;
int l = 2*i + 1;
int r = 2*i + 2;
if (l < n && arr[l] > arr[largest])
largest = l;
if (r < n && arr[r] > arr[largest])
largest = r;
// Swap and continue heapifying if root is not largest
if (largest != i)
{
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;
Page 5 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_5
heapify(arr, n, largest);
}
}
static void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i < n; ++i)
System.out.print(arr[i]+" ");
System.out.println();
}
public static void main(String args[])
{
int arr[] = {1,12,9,5,6,10};
HeapSort hs = new HeapSort();
hs.sort(arr);
System.out.println("Sorted array is");
printArray(arr);
}
}
Difference between Algorithm and Code
Page 6 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_6
An algorithm is a well defined sequence of steps that provides a solution for
a given problem, while a code is one of the methods that can be used to
represent an algorithm. While algorithms can be written in natural language,
code is written in a format that is closely related to high level programming
language structures. But code does not use specific programming language
syntax and therefore could be understood by programmers who are familiar
with different programming languages. Additionally, transforming an
algorithm presented in code to programming code could be much easier
than converting an algorithm written in natural language.
Preprocessor is a program that processes its input data to produce output
that is used as input to another program. The output is said to be a
preprocessed form of the input data, which is often used by some
subsequent programs like compilers. The amount and kind of processing
done depends on the nature of the preprocessor; some preprocessors are
only capable of performing relatively simple textual substitutions and macro
expansions, while others have the power of full-fledged programming
languages.
A compiler is a special program that processes statements written in a
particular programming language and turns them into machine language or
"code" that a computer's processor uses. Typically, a programmer writes
language statements in a language such as Pascal or C one line at a time
using an editor. The file that is created contains what are called the source
statements. The programmer then runs the appropriate language compiler,
specifying the name of the file that contains the source statements.
Linker is a program that makes executable files. The linker resolves linkage
issues, such as the use of symbols or identifiers which are defined in one
translation unit and are needed from other translation units. Symbols or
identifiers which are needed outside a single translation unit have external
linkage. In short, the linker's job is to resolve references to undefined
symbols by finding out which other object defines a symbol in question, and
replacing placeholders with the symbol's address. Of course, the process is
more complicated than this; but the basic ideas apply.
An interpreter translates high-level instructions into an intermediate form,
which it then executes. In contrast, a compiler translates high-level
instructions directly into machine language. Compiled programs generally
run faster than interpreted programs. The advantage of an interpreter,
however, is that it does not need to go through the compilation stage during
Page 7 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_7
which machine instructions are generated. This process can be time-
consuming if the program is long. The interpreter, on the other hand, can
immediately execute high-level programs. For this reason, interpreters are
sometimes used during the development of a program, when a programmer
wants to add small sections at a time and test them quickly. In addition,
interpreters are often used in education because they allow students to
program interactively.
LO2 Explain the characteristics of procedural, object-orientated and
event driven programming. Conduct an analysis of a suitable
Integrated Development Environment (IDE)
Characteristics of code:
A data type defines what kind of value a column can hold: integer data,
character data, monetary data, date and time data, binary strings, and so
on. Such as Boolean, Numbers, String values, Arrays, Objects, NULL,
MISSING, Collation, Date, Binary.
A constant is an identifier (name) for a simple value. As the name suggests,
that value cannot change during the execution of the script (except for
magic constants, which aren't actually constants). A constant is case-
sensitive by default. By convention, constant identifiers are always
uppercase.
A variable is any factor, trait, or condition that can exist in differing amounts
or types. An experiment usually has three kinds of variables: independent,
dependent, and controlled. The independent variable is the one that is
changed by the scientist.
Page 8 of 35
Algorithm and Programming Overview | Characteristics and IDE Analysis_8

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Algorithms for Searching, Sorting, and Matrix Operations
|8
|1756
|131

Quick Short Assignment 2022
|16
|1651
|15

Data Structure and Algorithms - Desklib Online Library
|16
|1240
|91

Sorting Algorithms Assignment 2022
|17
|1992
|18

Data Structure & Algorithms
|10
|2062
|432

Quick Sort Assignment 2022
|16
|1682
|22