computer science – ce -2013 - section b

Upload: sayyed-salman-mehdi-mosvi

Post on 14-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Computer Science CE -2013 - Section B

    1/23

    Structured and Object OrientedProgramming

    Data Structures and Algorithms Software Engineering

  • 7/29/2019 Computer Science CE -2013 - Section B

    2/23

    Computer programming (often shortened toprogramming, scripting, or coding) is the process ofdesigning, writing, testing, debugging, and maintainingthe source code of computer programs

    This source code is written in one or more programminglanguages (such as Java, C++, C#, Python, etc.)

    The purpose of programming is to create a set ofinstructions that computers use to perform specificoperations or to exhibit desired behaviors

    The process of writing source code often requiresexpertise in many different subjects, including knowledgeof the application domain, specialized algorithms andformal logic.

  • 7/29/2019 Computer Science CE -2013 - Section B

    3/23

    Structured programming is a programming paradigm aimed on improving the clarity,quality, and development time of a computer program by making extensive use ofsubroutines, block structures and for and while loops in contrast to using simpletests and jumps such as the goto statement which could lead to "spaghetti code"which is both difficult to follow and to maintain.

    Program flow follows a simple hierarchical model that employs looping constructs

    such as "for," "repeat," and "while." Use of the "Go To" statement is discouraged. Structured programming was first suggested by Corrado Bohm and Guiseppe Jacopini. The two

    mathematicians demonstrated that any computer program can be written with just threestructures: decisions, sequences, and loops.

    At a low level, structured programs are often composed of simple, hierarchical program flowstructures. These are sequence, selection, and repetition: "Sequence" refers to an ordered execution of statements.

    In "selection" one of a number of statements is executed depending on the state of the program. This isusually expressed with keywords such as if..then..else..endif, switch, or case. In some languages keywordscannot be written verbatim, but must be stropped.

    In "repetition" a statement is executed until the program reaches a certain state, or operations have beenapplied to every element of a collection. This is usually expressed with keywords such as while, repeat, for ordo..until. Often it is recommended that each loop should only have one entry point (and in the originalstructural programming, also only one exit point, and a few languages enforce this).

  • 7/29/2019 Computer Science CE -2013 - Section B

    4/23

    Non-structured programming is the historically earliestprogramming paradigm capable of creating Turing-complete algorithms. It has been followed historically byprocedural programming and then object-oriented

    programming, both of them considered as structuredprogramming.

    There are both high- and low-level programminglanguages that use non-structured programming.

    These include early versions of BASIC (such as MSX

    BASIC and GW-BASIC), JOSS, FOCAL, MUMPS,TELCOMP, COBOL, machine-level code, early assemblersystems (without procedural meta-operators),assembler debuggers and some scripting languages suchas MS-DOS batch file language.

  • 7/29/2019 Computer Science CE -2013 - Section B

    5/23

    "Modular Programming" is the act ofdesigning and writing programs as

    interactions among functions that eachperform a single well-defined function, andwhich have minimal side-effect interactionbetween them. Put differently, the content ofeach function is cohesive, and there is lowcoupling between functions.

    Modular Programming is not OO...

  • 7/29/2019 Computer Science CE -2013 - Section B

    6/23

    Object-oriented programming (OOP) is aprogramming language model organized around"objects" rather than "actions" and data rather

    than logic An object-oriented program may be viewed as a

    collection of interacting objects, as opposed tothe conventional model, in which a program isseen as a list of tasks (subroutines) to perform

    object-oriented programming that uses classesis sometimes called class-based programming,while prototype-based programming does nottypically use classes.

  • 7/29/2019 Computer Science CE -2013 - Section B

    7/23

    Encapsulation Enforces Modularity Encapsulation refers to the creation ofself-contained modules that bind processing

    functions to the data. These user-defined data types are called "classes," and one instance ofa class is an "object." For example, in a payroll system, a class could be Manager, and Pat andJan could be two instances (two objects) of the Manager class. Encapsulation ensures goodcode modularity, which keeps routines separate and less prone to conflict with each other.

    Inheritance Passes "Knowledge" Down Classes are created in hierarchies, and inheritance allows the structure and methods in one

    class to be passed down the hierarchy. That means less programming is required whenadding functions to complex systems. If a step is added at the bottom of a hierarchy, thenonly the processing and data associated with that unique step needs to be added. Everythingelse about that step is inherited. The ability to reuse existing objects is considered a majoradvantage of object technology.

    Polymorphism Takes any Shape

    Object-oriented programming allows procedures about objects to be created whose exacttype is not known until runtime. For example, a screen cursor may change its shape from anarrow to a line depending on the program mode. The routine to move the cursor on screen inresponse to mouse movement would be written for "cursor," and polymorphism allows thatcursor to take on whatever shape is required at runtime. It also allows new shapes to be easilyintegrated.

  • 7/29/2019 Computer Science CE -2013 - Section B

    8/23

    public abstract class LoggerBase{

    /// /// field is private, so it intend to use inside the class only/// private log4net.ILog logger = null;

    /// /// protected, so it only visible for inherited class/// protected LoggerBase(){

    // The private object is created inside the constructorlogger = log4net.LogManager.GetLogger(this.LogPrefix);// The additional initialization is done immediately afterlog4net.Config.DOMConfigurator.Configure();

    }///

    /// When you define the property as abstract,/// it forces the inherited class to override the LogPrefix/// So, with the help of this technique the log can be made,/// inside the abstract class itself, irrespective of it origin./// If you study carefully you will find a reason for not to have set method

    here.

    /// protected abstract System.Type LogPrefix

    {get;

    }

    /// /// Simple log method,/// which is only visible for inherited classes/// /// protected void LogError(string message){

    if (this.logger.IsErrorEnabled){

    this.logger.Error(message);}

    }///

    /// Public properties which exposes to inherited class/// and all other classes that have access to inherited class/// public bool IsThisLogError{

    get{

    return this.logger.IsErrorEnabled;}

    }}

  • 7/29/2019 Computer Science CE -2013 - Section B

    9/23

    In computer science, a data structure is aparticular way of storing and organizing data in acomputer so that it can be used efficiently

    Data structures provide a means to managehuge amounts of data efficiently

    such as: large databases

    internet indexing services

    designing efficient algorithms and

    formal design methods and programming languages

  • 7/29/2019 Computer Science CE -2013 - Section B

    10/23

    In computing, a hash table (alsohash map) is a data structureused to implement anassociative array, a structure that

    can map keys to values. A hash table uses a hash function

    to compute an index into anarray of buckets or slots, fromwhich the correct value can befound.

    Choosing a good hashfunction

    Perfect hash function

  • 7/29/2019 Computer Science CE -2013 - Section B

    11/23

    A compiler is a computerprogram (or set ofprograms) that transformssource code written in a

    programming language(the source language) intoanother computerlanguage (the targetlanguage, often having abinary form known asobject code)

    The most common reasonfor wanting to transformsource code is to create anexecutable program

  • 7/29/2019 Computer Science CE -2013 - Section B

    12/23

    In computer science, a B-tree is a tree datastructure that keeps data sorted and allowssearches, sequential access, insertions, and

    deletions in logarithmic time The B-tree is a generalization of a binary search

    tree in that a node can have more than twochildren

    (Comer 1979, p. 123) Unlike self-balancing binarysearch trees, the B-tree is optimized for systemsthat read and write large blocks of data. It iscommonly used in databases and filesystems.

  • 7/29/2019 Computer Science CE -2013 - Section B

    13/23

    In computer science, a tree is a widelyused data structure that simulates ahierarchical tree structure with a set oflinked nodes.

    A tree can be defined recursively (locally)as a collection of nodes (starting at a rootnode), where each node is a datastructure consisting of a value, togetherwith a list of nodes (the "children"), with

    the constraints that no node isduplicated. A tree can be definedabstractly as a whole (globally) as anordered tree, with a value assigned toeach node

    A simple unordered tree;in this diagram, the node

    labeled 7 has two children,labeled 2 and 6, and oneparent, labeled 2. The rootnode, at the top, has noparent.

  • 7/29/2019 Computer Science CE -2013 - Section B

    14/23

    List of data structures Plain old data structure

    Concurrent data structure Data model Dynamization Linked data structure Persistent data structure

  • 7/29/2019 Computer Science CE -2013 - Section B

    15/23

    In computer science, a concurrent data structure is aparticular way of storing and organizing data foraccess by multiple computing threads (or processes)

    on a computer. Historically, such data structures were used on

    uniprocessor machines with operating systems thatsupported multiple computing threads (or processes)

    The term concurrency captured themultiplexing/interleaving of the threads' operationson the data by the operating system, even though theprocessors never issued two operations that accessedthe data simultaneously.

  • 7/29/2019 Computer Science CE -2013 - Section B

    16/23

    (POD) is a data structure that is representedonly as passive collections of field values,

    without using encapsulation or other object-oriented features

  • 7/29/2019 Computer Science CE -2013 - Section B

    17/23

    A high-level data model in business or forany functional area is an abstract modelthat documents and organizes the businessdata for communication betweenfunctional and technical people. It is usedto show the data needed and created bybusiness processes.

    A data model in software engineering is anabstract model that documents andorganizes the business data forcommunication between team membersand is used as a plan for developingapplications, specifically how data arestored and accessed.

    According to Hoberman (2009), "A datamodel is a wayfinding tool for both

    business and IT professionals, which uses aset of symbols and text to precisely explaina subset of real information to improvecommunication within the organizationand thereby lead to a more flexible andstable application environment."

  • 7/29/2019 Computer Science CE -2013 - Section B

    18/23

    In computer science, a linkedlist is a data structureconsisting of a group ofnodes which togetherrepresent a sequence. Underthe simplest form, each nodeis composed of a datum anda reference (in other words, alink) to the next node in thesequence; more complexvariants add additional links.This structure allows forefficient insertion or removalof elements from anyposition in the sequence.

    The following program shows how asimple, linear linked list can beconstructed in C, using dynamic memoryallocation and pointers.

    #include#includestruct list_el {

    int val;struct list_el * next;

    };

    typedef struct list_el item;void main() {

    item * curr, * head;int i;head = NULL;for(i=1;ival = i

  • 7/29/2019 Computer Science CE -2013 - Section B

    19/23

    Singly linked list

    Singly linked lists contain nodes which have a data field as well as a next field,which points to the next node in the linked list

    Doubly linked list In a doubly linked list, each node contains, besides the next-node link, a second

    link field pointing to the previous node in the sequence. The two links may becalled forward(s) and backwards, or next and prev(ious).

    Multiply linked list n a multiply linked list, each node contains two or more link fields, each field being

    used to connect the same set of data records in a different order (e.g., by name, bydepartment, by date of birth, etc.). While doubly linked lists can be seen as specialcases of multiply linked list, the fact that the two orders are opposite to each otherleads to simpler and more efficient algorithms, so they are usually treated as aseparate case.

  • 7/29/2019 Computer Science CE -2013 - Section B

    20/23

    Circular list

    In the last node of a list, the link field often contains a null reference, a special value

    used to indicate the lack of further nodes. A less common convention is to make it point

    to the first node of the list; in that case the list is said to be circular or circularly linked;

    otherwise it is said to be open or linear.

    In the case of a circular doubly linked list, the only change that occurs is that end, or"tail", of the said list is linked back to the front, or "head", of the list and vice versa.

  • 7/29/2019 Computer Science CE -2013 - Section B

    21/23

    Bubble sort sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that

    works by repeatedly stepping through the list to be sorted, comparing each pair of

    adjacent items and swapping them if they are in the wrong order. The pass through the

    list is repeated until no swaps are needed, which indicates that the list is sorted. Thealgorithm gets its name from the way smaller elements "bubble" to the top of the list.

    Because it only uses comparisons to operate on elements, it is a comparison sort.

    Although the algorithm is simple, most of the other sorting algorithms are more

    efficient for large lists.

  • 7/29/2019 Computer Science CE -2013 - Section B

    22/23

    All notes available from below link.

  • 7/29/2019 Computer Science CE -2013 - Section B

    23/23

    An XOR linked list is a data structure used in computerprogramming. It takes advantage of the bitwise XORoperation, here denoted by, to decrease storagerequirements for doubly linked lists. An ordinarydoubly linked list stores addresses of the previous andnext list items in each list node, requiring two addressfields:

    The key is the first operation, and the properties ofXOR:

    XX=O XO=X XY=YX (XY)Z=X(YZ)