Computer Science Lecturer Test Preparation (Part-1)

Computer Science Lecturer Test Preparation (Part-I)

Computer Science Lecturer Test Preparation Part-1

Computer Science Lecturer Test Preparation Part-2

Computer Science Lecturer Test Preparation Part-3

Computer Science Lecturer Test Preparation Part-4

Computer Languages

Two Basic Types of Computer Language

  • Low-Level Languages:A language that corresponds directly to a specific machine

Low-level computer languages are either machine codes or are very close them. A computer cannot understand instructions given to it in high-level languages or in English. It can only understand and execute instructions given in the form of machine language i.e. binary. There are two types of low-level languages:

  • Machine Language: a language that is directly interpreted into the hardware
  • First type of programming language to be developed Machine language is basically the only language that a computer can understand and it is usually written in hex.
  • Machine language makes fast and efficient use of the computer. 0s and 1s
  • Assembly Language: a slightly more user-friendly language that directly
  • Assembly language is also known as ‘Symbolic Programming Language.’
  • This is another low-level but very important language in which operation codes and operands are given in the form of alphanumeric symbols instead of 0’s and l’s.
  • High-Level Languages:Any language that is independent of the machine
  • High-level computer languages use formats that are similar to English. The purpose of developing high-level languages was to enable people to write programs easily, in their own native language environment (English).
  • High-level languages are basically symbolic languages that use English words and/or mathematical symbols rather than mnemonic codes. Each instruction in the high-level language is translated into many machine language instructions that the computer can understand.

Types of High-Level Languages

Many languages have been developed for achieving a variety of different tasks. Some are fairly specialized, and others are quite general.

These languages, categorized according to their use, are:

1) Algebraic Formula-Type Processing

These languages are oriented towards the computational procedures for solving mathematical and statistical problems.

Examples include:

  • BASIC (Beginners All Purpose Symbolic Instruction Code)
  • FORTRAN (Formula Translation)
  • PL/I (Programming Language, Version 1)
  • ALGOL (Algorithmic Language)
  • APL (A Programming Language)

2. Business Data Processing

These languages are best able to maintain data processing procedures and problems involved in handling files. Some examples include:

  • COBOL (Common Business Oriented Language)
  • RPG (Report Program Generator)

3. String and List Processing

These are used for string manipulation, including search patterns and inserting and deleting characters. Examples are:

  • LISP (List Processing)
  • Prolog (Program in Logic)

4. Object-Oriented Programming Language

In OOP, the computer program is divided into objects. Examples are:

  • C++
  • Java

5. Visual Programming Language

These programming languages are designed for building Windows-based applications.Examples are:

  • Visual Basic
  • Visual Java
  • Visual C

Inheritance

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. Such an inherited class is called a subclass of its parent class or super class base class. It is a mechanism for code reuse and to allow independent extensions of the original software via public classes and interfaces. Still, inheritance is a commonly used mechanism for establishing subtype relationships. There are various types of inheritance, based on paradigm and specific language.

Types of Inheritance

Single inheritance

where one class can have more than one superclass and inherit features from all parent classes.

Multilevel inheritance

where a subclass is inherited from another subclass

Hierarchical inheritance

where one class serves as a superclass (base class) for more than one sub class.

Hybrid inheritance

a mix of two or more of the above types of inheritance.

Encapsulation

  1. An information-hiding mechanism
  2. Encapsulation can be used to hide data members and members function.Under this definition, encapsulation means that the internal representation of an object is generally hidden from view outside of the object’s definition.
  3. typically via keywords like public and private
  4. It should be noted that the ISO C++ standard refers to protected, private and public as “access specifiers” and that they do not “hide any information”.
  5. Information hiding is accomplished by furnishing a compiled version of the source code that is interfaced via a header file.
  6. A supposed benefit of encapsulation is that it can reduce system complexity, and thus increase robustness, by allowing the developer to limit the inter-dependencies between software components [citation needed].
  7. Encapsulation is used to hide the values or state of a structured data object inside a class
  8. Publicly accessible methods are generally provided in the class (so-called getters and setters) to access the values, and other client classes call these methods to retrieve and modify the values within the object.
  9. Because inheritance exposes a subclass to details of its parent’s implementation, it’s often said that “inheritance breaks encapsulation”

Composition

Composition is again specialize form of Aggregation.

Child object dose not have it’s own life cycle and if parent object gets deleted, then all of it’s child objects will also be deleted. Compositions are a critical building block of many basic data structures, including the tagged union, the linked list, and the binary tree, as well as the object used in object-oriented programming. an object of a composite type (e.g. car) “has an” object of a simpler type (e.g. wheel). Composition is usually implemented such that an object contains another object. containing object has a member object and the member object cannot survive or exist without the enclosing or containing class. A Person is a supervisor. A Person is a husband. Supervisor and husband are the roles played by a single person. The husband role without the person has no meaning or cannot exist and similarly for the supervisor also.

Aggregation

Aggregation is also known as a ‘has a’ relationship because the containing object has a member object and the member object can survive or exist without the enclosing or containing class. Room has a table and the table can exist without the room. The table can have meaning without the room also. It is a specialize form of Association where all object have their own life cycle but there is a ownership like parent and child. Child object can not belong to another parent object at the same time. We can think of it as “has-a” relationship.

Association

A relationship where all objects have their own life cycle and there is no owner. Multiple students can associate with a single Department and single student can associate with multiple Departments, but there is no ownership between the objects and both have their own life cycle. Both can create and delete independently.

Polymorphism

polymorphic type is one whose operations can also be applied to values of some other type, or types. corresponding forms of polymorphism are accordingly called static polymorphism and dynamic polymorphism

Pointer and its types

A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer. A pointer is a abstract reference data type.

In computer science, a pointer is a kind of reference. Pointers can be used to pass variables by their address, allowing their value to be changed.  Pointers are used to store and manage the addresses of dynamically allocated blocks of memory

Null pointer

Null pointers are routinely used such as the end of a list of unknown length or the failure to perform some action;

Stack vs.  Heap Allocation

When a program is loaded into memory, it is organized into three areas of memory, called segments:

the text segmentstack segment, and  heap segment.

The text segment (sometimes also called the code segment) is where the compiled code of the program itself resides. This is the machine language representation of the program steps to be carried out, including all functions making up the program, both user defined and system. The remaining two areas of system memory is where storage may be allocated by the compiler for data storage.  The stack is where memory is allocated for automatic variables within functions. A stack is a Last In First Out (LIFO) storage device where new storage is allocated and deallocated at only one “end”, called the Top of the stack. When a program begins executing in the function main(), space is allocated on the stack for all variables declared within main(), If main() calls a function, func1(), additional storage is allocated for the variables in func1() at the top of the stack. Notice that the parameters passed by main() to func1() are also stored on the stack. If func1() were to call any additional functions, storage would be allocated at the new Top. When func1() returns, storage for its local variables is deallocated, and the Top of the stack returns to to position If main() were to call another function, storage would be allocated for that function at the Top. As can be seen, the memory allocated in the stack area is used and reused during program execution. It should be clear that memory allocated in this area will contain garbage values left over from previous usage. The heap segment provides more stable storage of data for a program; memory allocated in the heap remains in existence for the duration of a program. Therefore, global variables (storage class external), and static variables are allocated on the heap. The memory allocated in the heap area, if initialized to zero at program start, remains zero until the program makes use of it. Thus, the heap area need not contain garbage.

We can make our program more flexible if, during execution, it could allocate additional memory when needed and free memory when not needed. Allocation of memory during execution is called dynamic memory allocation. C provides library functions to allocate and free memory dynamically during program execution. Dynamic memory is allocated on the heap by the system.

Operators in C/C++ Language

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Misc Operators
  • Increment and Decrement Operators
  • Conditional Operators
  • Bitwise Operators
  • Special Operators

What is Array in C

Arrays in C act to store related data under a single variable name. Array as a collection of variables of the same type.

A specific element in an array is accessed by an index. Arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array .

The array Size must be an integer constant greater than zero and type can be any valid C data type
Multi-dimensional arrays. 

C supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.

C allows a function to return an array.

You can generate a pointer to the first element of an array by simply specifying the array name, without any index.

Passing arrays to functions

You can pass to the function a pointer to an array by specifying the array’s name without an index.

array of six integers

int numbers[6];

char letters[6];

Pointer in C/C++ Language

Pointer is a computer’s memory which can be accessed by their identifier (their name)

This way, the program does not need to care about the physical address of the data in memory; it simply uses the identifier whenever it needs to refer to the variable.

pointer is a variable whose value is the address of another variable.The asterisk you used to declare a pointer is the same asterisk that you use for multiplication, pointers of different data type’s integer, float, character, or otherwise, is the same, a long hexadecimal number that represents a memory address.

For a C++ program, the memory of a computer is like a succession of memory cells, each one byte in size, and each with a unique address. When a variable is declared, the memory needed to store its value is assigned a specific location in memory. Pointers can be used to access a variable by its address,

The void type of pointer is a special type of pointer. In C++, void represents the absence of type. Therefore, void pointers are pointers that point to a value that has no type .

Pointers can be used to access a variable by its address,.C++ allows operations with pointers to functions. The typical use of this is for passing a function as an argument to another function. Pointers to functions are declared with the same syntax as a regular function declaration, except that the name of the function is enclosed between parentheses () and an asterisk (*) is inserted before the name

Operating System Basics

Operating system manages all other programs on the machine

An Operating system is basically a intermediary agent between the user and the computer hardware.

  • Manages the computer’s resources (hardware, abstract resources, software)
  • It’s a resource allocator.
  • It is also used to control programs to prevent errors and improper computer use.
  • It is interrupt driven.

Types of Operating Systems

Single- and multi-tasking operating system

A single-tasking system can only run one program at a time, while a multi-tasking operating system allows more than one program to be running in concurrency. This is achieved by time-sharing, dividing the available processor time between multiple processes

Multi-tasking may be characterized in preemptive and co-operative types. In preemptive multitasking, the operating system slices the CPU time and dedicates a slot to each of the programs.

Single- and multi-user operating system

Single-user operating systems have no facilities to distinguish users, but may allow multiple programs to run in tandem. A multi-user operating system extends the basic concept of multi-tasking with facilities that identify processes and resources, such as disk space, belonging to multiple users, and the system permits multiple users to interact with the system at the same time. Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting software for cost allocation of processor time, mass storage, printing, and other resources to multiple users.

Distributed operating system

A distributed operating system manages a group of distinct computers and makes them appear to be a single computer

Real-time operating system

A real-time operating system is an operating system that guarantees to process events or data by a specific moment in time. A real-time operating system may be single- or multi-tasking, but when multitasking, it uses specialized scheduling algorithms so that a deterministic nature of behavior is achieved. An event-driven system switches between tasks based on their priorities or external events while time-sharing operating systems switch tasks based on clock interrupts

Library operating system

A library operating system is one in which the services that a typical operating system provides, such as networking, are provided in the form of libraries. These libraries are composed with the application and configuration code to construct unikernels – which are specialized, single address space, machine images that can be deployed to cloud or embedded environments.

Key Differences between Serial and Parallel Transmission

  1. Serial transmission requires a single line to communicate and transfer data whereas, parallel transmission requires multiple lines.
  2. Serial transmission used for long distance communication whereas, the parallel transmission used for shorter distance.
  3. Error and noise are least in serial as compared to parallel transmission. Since one bit follows another in Serial Transmission whereas, in Parallel Transmission multiple bits are sent together.
  4. Parallel transmission is faster as the data is transmitted using multiples lines whereas, in Serial transmission data flows through a single wire.
  5. Serial Transmission is full duplex as the sender can send as well as receive the data whereas, Parallel Transmission is half duplex since the data is either sent or received.
  6. Serial transmission cables are thinner, longer and economical in comparison with the Parallel Transmission cables.
  7. Serial Transmission is reliable and straightforward whereas, Parallel Transmission is unreliable and complicated.

Link List in C++

A linked list is a sequence of data structures, which are connected together via links.

  • Link− Each link of a linked list can store a data called an element.
  • Next− Each link of a linked list contains a link to the next link called Next.
  • Linked List− A Linked List contains the connection link to the first link called First.

Types of Linked Lists

  • Singly Linked List :Singly linked lists contain nodes which have a data part as well as an address part i.e. next, which points to the next node in sequence of nodes. The operations we can perform on singly linked lists are insertion, deletion and traversal.
  • Doubly Linked List : In a doubly linked list, each node contains two links the first link points to the previous node and the next link points to the next node in the sequence.

Linked List Representation

Linked list can be visualized as a chain of nodes, where every node points to the next node.

Basic Operations

Following are the basic operations supported by a list.

  • Insertion− Adds an element at the beginning of the list.
  • Deletion− Deletes an element at the beginning of the list.
  • Display− Displays the complete list.
  • Search− Searches an element using the given key.
  • Delete− Deletes an element using the given key.

 

LAN: Local Area Network

A LAN connects network devices over a relatively short distance. A networked office building, school, or home usually contains a single LAN, though sometimes one building will contain a few small LANs (perhaps one per room), and occasionally a LAN will span a group of nearby buildings. In TCP/IP networking, a LAN is often but not always implemented as a single IP subnet.

In addition to operating in a limited space, LANs are also typically owned, controlled, and managed by a single person or organization.

They also tend to use certain connectivity technologies, primarily Ethernet and Token Ring.

WAN: Wide Area Network

As the term implies, a WAN spans a large physical distance. The Internet is the largest WAN, spanning the Earth.

A WAN is a geographically-dispersed collection of LANs. A network device called a router connects LANs to a WAN.

In IP networking, the router maintains both a LAN address and a WAN address.

A WAN differs from a LAN in several important ways. Most WANs (like the Internet) are not owned by any one organization but rather exist under collective or distributed ownership and management. WANs tend to use technology like ATM, Frame Relay and X.25 for connectivity over the longer distances.

Other Types of Area Networks

While LAN and WAN are by far the most popular network types mentioned, you may also commonly see references to these others:

  • Wireless Local Area Network – A LAN based on Wi-Fi wireless network technology
  • Metropolitan Area Network – A network spanning a physical area larger than a LAN but smaller than a WAN, such as a city. A MAN is typically owned and operated by a single entity such as a government body or large corporation.
  • Campus Area Network – A network spanning multiple LANs but smaller than a MAN, such as on a university or local business campus.
  • Storage Area Network – Connects servers to data storage devices through a technology like Fibre Channel.
  • System Area Network (also known as Cluster Area Network) – Links high-performance computers with high-speed connections in a cluster configuration.

Topologies

In computer networking, topology refers to the layout of connected devices. This article introduces the standard topologies of networking.

Topology in Network Design

Think of a topology as a network’s virtual shape or structure. This shape does not necessarily correspond to the actual physical layout of the devices on the network. For example, the computers on a home network may be arranged in a circle in a family room, but it would be highly unlikely to find a ring topology there.

Network topologies are categorized into the following basic types:

  • bus
  • ring
  • star
  • tree
  • mesh

More complex networks can be built as hybrids of two or more of the above basic topologies.

Bus Topology

Bus networks (not to be confused with the system bus of a computer) use a common backbone to connect all devices. A single cable, the backbone functions as a shared communication medium that devices attach or tap into with an interface connector. A device wanting to communicate with another device on the network sends a broadcast message onto the wire that all other devices see, but only the intended recipient actually accepts and processes the message.

Ethernet bus topologies are relatively easy to install and don’t require much cabling compared to the alternatives. 10Base-2 (“ThinNet”) and 10Base-5 (“ThickNet”) both were popular Ethernet cabling options many years ago for bus topologies. However, bus networks work best with a limited number of devices.

If more than a few dozen computers are added to a network bus, performance problems will likely result. In addition, if the backbone cable fails, the entire network effectively becomes unusable.

Ring Topology

In a ring network, every device has exactly two neighbors for communication purposes.

All messages travel through a ring in the same direction (either “clockwise” or “counterclockwise”). A failure in any cable or device breaks the loop and can take down the entire network.

To implement a ring network, one typically uses FDDI, SONET, or Token Ringtechnology. Ring topologies are found in some office buildings or school campuses.

Star Topology

Many home networks use the star topology. A star network features a central connection point called a “hub node” that may be a network hub, switch or router. Devices typically connect to the hub with Unshielded Twisted Pair (UTP) Ethernet.

Compared to the bus topology, a star network generally requires more cable, but a failure in any star network cable will only take down one computer’s network access and not the entire LAN. (If the hub fails, however, the entire network also fails.)

Tree Topology

A tree topology joins multiple star topologies together onto a bus. In its simplest form, only hub devices connect directly to the tree bus, and each hub functions as the root of a tree of devices. This bus/star hybrid approach supports future expansion of the network much better than a bus (limited in the number of devices due to the broadcast traffic it generates) or a star (limited by the number of hub connection points) alone.

Mesh Topology

Mesh topology introduces the concept of routes. Unlike each of the previous topologies, messages sent on a mesh network can take any of several possible paths from source to destination. (Recall that even in a ring, although two cable paths exist, messages can only travel in one direction.) Some WANs, most notably the Internet, employ mesh routing.

A mesh network in which every device connects to every other is called a full mesh. As shown in the illustration below, partial mesh networks also exist in which some devices connect only indirectly to others.