Saturday, 9 November 2019

C-programming problem

Let R be a sequence. The inverse sequence of R is the sequence by reading the symbols in R backwards. For example, the inverse of 0113 is 3110. If the inverse of R is identical to R, then R is called a palindrome sequence. For example, R[9] = 011303110 is a palindrome sequence. Given a sequence S, if R is a subsequence of S and R is palindrome, then R is called a palindrome subsequence of S. One can then similarly define what a longest palindrome subsequence (LPS for short) of S is.
Problem:
Write a program that reads in a sequence of max length = 10,000. Then compute the LPS of a sequence input by the user. Output will print the LPS and its length.
Sample run:
Enter a sequence: 13112301728031631251841324
# an LPS (length = 13) for the second sequence is:
3112136312113

Solution:

/* C program to find the the longest palindromic substring */

#include <stdio.h> //for standard I/O
#include <stdbool.h> //for boolean variable
#include <string.h> //for string functions strlen
// function to find the longest palindromic substring and
//print the substring & its length
int longestPalinStr(char str[])
{
// find the length of the input string
int n = strlen(str);
//array for memoization
bool array[n][n];

//declare array as false(0) initially
memset(array, 0, sizeof(array));
//length of 1 character substring
int maxLen = 1;
//for length 1 substring set true(1)
for (int k = 0; k < n; k++)
array[k][k] = true;
//checking for substring of length 2.
int start = 0;
for (int i = 0; i < n-1; i++)
{
if (str[i] == str[i+1])
{
array[i][i+1] = true;
start = i;
maxLen = 2;
}
}
//loop for substrings of lengths > 2
for (int k = 3; k <= n; k++)
{
for (int i = 0; i < n-k+1 ; i++)
{
//for last index
int j = i + k - 1;
//check for the contained substring to be palindrome
//using array[i+1][j-1] and boundary characters using str[i] and str[j]
if (array[i+1][j-1] && str[i] == str[j])
{
//if above 'if' is true then set position of array[i][j] to be true
array[i][j] = true;
//to set position of start
//and update maxLen
if (k > maxLen)
{
maxLen = k;
start = i;
}
}
}
}
printf(" The longest palindromic substring is: ");
int last = start + maxLen - 1;
//print the substring from start index to last index
for( int i = start; i <= last; i++ )
printf("%c",str[i]);

printf("\nLength is: %d" , maxLen);
}
//main function
int main()
{
//decalre a character array of size 10000
char ch[10000];
//read the string from console
scanf("%s",&ch);
//call thelongestPalinStr() to find the longest palindromic substring of ch[]
longestPalinStr(ch);
return 0;
}


Scheduling, Synchronization and Deadlock (Quiz)

Question 1
Which of the following scheduling algorithms must be nonpreemptive?
  1. Shortest Job First
  2. Round Robin
  3. First Come, First Served
  4. Priority Algorithms
Solution: First Come, First Served

Question 2
____ scheduling is approximated by predicting the next CPU burst with an exponential average of the measured lengths of previous CPU bursts. 
  1. Shortest Job First
  2. Round Robin
  3. Multilevel queue
  4. First Come, First Served 
 Solution: Shortest Job First

Question 3
With the following process list, what is the Average Turnaround Time for the Round Robin scheduling algorithm with a time quantum of 5ms? 

Submission Time Process Run Time
0ms 10ms
5ms 20ms
15ms 10ms
30ms 20ms
40ms 10ms
60ms 10ms
  1.  20
  2. 23
  3. 25
  4. 27
Solution: 27

Question 4
____ is the number of processes that are completed per time unit.
  1. Response time
  2. Turnaround time
  3. Throughput
  4. CPU utilization 
 Solution: Throughput

Question 5
Which of the following is true of cooperative scheduling?
  1.  A process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state.
  2. A process switches from the running state to the ready state when an interrupt occurs.
  3. It requires a timer.
  4. It incurs a cost associated with access to shared data. 
Solution: A process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state.

Question 6
A significant problem with priority scheduling algorithms is _____.
  1. determining the length of the time quantum
  2. complexity
  3. determining the length of the next CPU burst
  4. starvation
Solution: starvation

Question 7
______ allows a thread to run on only one processor.
  1. Load balancing
  2. Processor affinity
  3. Processor set
  4. NUMA
Solution: Processor affinity

Question 8
With the following process list, what is the Average Response Time for the First Come, First Served scheduling algorithm? 
 

Submission Time Process Run Time
0ms 10ms
5ms 20ms
15ms 10ms
30ms 20ms
40ms 10ms
60ms 10ms
  1. 10ms
  2. 7.5ms
  3. 12.5ms
  4. 5ms
Solution: 10ms

Question 9
The ______ occurs in First Come, First Served scheduling when a process with a long CPU burst occupies the CPU. 
  1. waiting time
  2. convoy effect
  3. systemcontention scope
  4. dispatch latency 
 Solution: convoy effect

 

Stored procedures and functions are available in the current database

Q: Which of the following commands is the best way to generate an overview of what stored procedures and functions are available in the current database and what each does? Assume that the developer(s) of the database have followed the good coding guidelines laid out in this unit.


1.
SHOW PROCEDURES;
2.
SHOW PROCEDURE STATUS WHERE db = DATABASE();
3.
SELECT * FROM INFORMATION_SCHEMA.ROUTINES;
4.
SELECT name, comment, type FROM mysql.proc WHERE db = DATABASE();

Solution:
 
2.SHOW PROCEDURE STATUS WHERE db = DATABASE();
This is the ideal statement to list the procedures stored in the database mentioned in the search condition.
Only SHOW PROCEDURES is not a valid statement as it also needs STATUS
SELECT * FROM INFORMATION_SCHEMA.ROUTINES; this statement selects all the rows from the table ROUTINES and displays the result.
SELECT name, comment, type FROM mysql.proc WHERE db = DATABASE(); This is the selective display of certain columns from the table mysql.proc from the database db.

Saturday, 24 August 2019

Processes and Threads (Quiz)

Question 1
The list of processes waiting for a particular I/O device is called a(n) ____.
  1. standby queue
  2. device queue
  3. ready queue
  4. interrupt queue
Solution: device queue

Question 2
A _________________ saves the state of the currently running process and restores the state of the next process to run.
  1. save-and-restore
  2. state switch
  3. context switch
  4. process control block
Solution: context switch

Question 3
The ____ of a process contains temporary data such as function parameters, return addresses, and local variables. 
  1. text section
  2. data section
  3. program counter
  4. stack 
 Solution: stack

Question 4
A process that has terminated, but whose parent has not yet called wait(), is known as a ________ process. 
  1. zombie
  2. orphan
  3. terminated
  4. init 
 Solution: zombie

Question 5
The _______ process is assigned as the parent to orphan processes.
  1. zombie
  2. init
  3. main
  4. renderer 
 Solution: init

Question 6
Which of the following statements is true?
  1.  Shared memory is typically faster than message passing.
  2. Message passing is typically faster than shared memory.
  3. Message passing is most useful for exchanging large amounts of data.
  4. Shared memory is far more common in operating systems than message passing. 
Solution: Shared memory is typically faster than message passing.

Question 7
A process control block ____.
  1. includes information on the process's state
  2. stores the address of the next instruction to be processed by a different process
  3. determines which process is to be executed next
  4. is an example of a process queue 
 Solution: includes information on the process's state

 Question 8
All processes in UNIX first translate to a zombie process upon termination.
  1. True
  2. False 
 Solution: True

Question 9
Child processes inherit UNIX ordinary pipes from their parent process because:
  1.  The pipe is part of the code and children inherit code from their parents.
  2. A pipe is treated as a file descriptor and child processes inherit open file descriptors from their parents.
  3. The STARTUPINFO structure establishes this sharing.
  4. All IPC facilities are shared between the parent and child processes. 
Solution: A pipe is treated as a file descriptor and child processes inherit open file descriptors from their parents.

Question 10
The _____________ refers to the number of processes in memory.
  1. process count
  2. long-term scheduler
  3. degree of multiprogramming
  4. CPU scheduler
Solution: degree of multiprogramming

Question 11
_____ is not considered a challenge when designing applications for multicore systems.
  1. Deciding which activities can be run in parallel
  2. Ensuring there is a sufficient number of cores
  3. Determining if data can be separated so that it is accessed on separate cores
  4. Identifying data dependencies between tasks.

Solution: Ensuring there is a sufficient number of cores

Question 12
Which of the following would not be an acceptable signal handling scheme for a
multithreaded program?
  1. Deliver the signal to the thread to which the signal applies.
  2. Deliver the signal to every thread in the process.
  3. Deliver the signal to only certain threads in the process.
  4. Do not deliver the signal to any of the threads in the process.
Solution: Do not deliver the signal to any of the threads in the process.

Question 13
The ____ multithreading model multiplexes many user-level threads to a smaller or equal number of kernel threads.
  1. many-to-one model
  2. one-to-one model
  3. many-to-many model
  4. many-to-some model
Solution: many-to-many model

Question 14
A _____ uses an existing thread — rather than creating a new one — to complete a task.
  1. lightweight process
  2. thread pool
  3. scheduler activation
  4. asynchronous procedure call
Solution: thread pool

Question 15
_________ involves distributing tasks across multiple computing cores.
  1. Concurrency
  2. Task parallelism
  3. Data parallelism
  4. Parallelism
Solution: Task parallelism

Question 16
A ____ provides an API for creating and managing threads.
  1. set of system calls
  2. multicore system
  3. thread library
  4. multithreading model
Solution: thread library

Question 17
Thread-local storage is data that ____.
  1. is not associated with any process
  2. has been modified by the thread, but not yet updated to the parent process
  3. is generated by the thread independent of the thread's process
  4. is unique to each thread
Solution: is unique to each thread

Question 18
Signals can be emulated in windows through ____.
  1. asynchronous procedure calls
  2. local procedure calls
  3. remote procedure calls
  4. synchronous procedure calls 
 Solution: asynchronous procedure calls

Question 19
Pthreads refers to ____.
  1. the POSIX standard.
  2. an implementation for thread behavior. 
  3. a specification for thread behavior.
  4. an API for process creation and synchronization. 
 Solution: a specification for thread behavior.

Question 20
According to Amdahl's Law, what is the speedup gain for an application that is 60% parallel and we run it on a machine with 4 processing cores? 
  1. 1.82
  2. 0.7
  3. 0.55
  4. 1.43 
 Solution: 1.43 

Open Source Development Tools and Overview (Quiz)

Question 1
________ is the proper filename for the file that contains targets, dependencies and rules which are used to define how your source code should be built into a binary executable.
  1. compiler
  2. make
  3. gcc
  4. Makefile
Solution:  Makefile

Question 2
What editor are you required to use in order to write source code on Linux?
  1. nano
  2. vim
  3. Any editor you are comfortable with
  4. emacs
Solution:  Any editor you are comfortable with

Question 3
Which gcc compiler option should you use in order to include symbols for debugging?
  1. -Wextra
  2. -o
  3. -Wall
  4. -g  
Solution: -g

Question 4
Before committing changes, what git command is used in order to include updates made to files that already exist in a local git repository? 
  1. update
  2. pull
  3. add
  4. push  
Solution: add

Question 5
When working with a remote git repository, what command should be used in order to synchronize changes from the the remote repository into the local repository? 
  1. update
  2. add
  3. push
  4. pull  
Solution: pull

Question 6
Which is not another term for kernel mode?
  1. system mode
  2. operating mode
  3. privileged mode 
  4. supervisor mode 
Solution: operating mode

Question 7
A(n) ________ is the unit of work in a system
  1. timer
  2. process
  3. operating system
  4. mode bit  
Solution: process

Question 8
What statement concerning privileged instructions is considered false?
  1. They can be executed in user mode.
  2. They are used to manage interrupts.
  3. They can be executed in kernel mode.
  4. They may cause harm to the system. 
Solution: They can be executed in user mode.

Question 9
A(n) ____ is a custom build of the Linux operating system
  1. installation
  2. LiveCD
  3. distribution
  4. VMWare Player
 Solution: distribution

Question 10
The most common secondary storage device is ____.
  1. magnetic disk
  2. tape drives
  3. random access memory
  4. solid state disks
 Solution: magnetic disk

Question 11
The two separate modes of operating in a system are
  1. user mode and kernel mode
  2. supervisor mode and system mode
  3. physical mode and logical mode
  4. kernel mode and privileged mode  
Solution: user mode and kernel mode

Question 12
Embedded computers typically run ____ operating system
  1. a clustered
  2. a network
  3. the Windows XP
  4. a real-time
Solution: a real-time

Question 13
Which of the following operating systems is not open source?
  1. PCLinuxOS
  2. BSD UNIX
  3. Linux
  4. Windows 
Solution:  Windows

Question 14
Microkernels use _____ for communication.
  1. virtualization
  2. message passing
  3. shared memory
  4. system calls 
Solution: message passing

Question 15
If a program terminates abnormally, a dump of memory may be examined by a ____ to determine the cause of the problem. 
  1. module
  2. control card
  3. debugger
  4. shell 
 Solution: debugger

Question 16
_____ allow operating system services to be loaded dynamically.
  1. Virtual machines
  2. Modules
  3. File systems
  4. Graphical user interfaces
Solution: Modules

Question 17
_____ provide(s) an interface to the services provided by an operating system.
  1. System calls
  2. Communication
  3. Simulators
  4. Shared memory
Solution: System calls

Question 18
A microkernel is a kernel ____.
  1. that is compressed before loading in order to reduce its resident memory size
  2. that is compiled to produce the smallest size possible when stored to disk
  3. containing many components that are optimized to reduce resident memory size
  4. that is stripped of all nonessential components 
 Solution: that is stripped of all nonessential components

Question 19
A _____ is an example of a systems program.
  1.  text formatter
  2. database system
  3. command interpreter
  4. Web browser 
Solution: command interpreter

Question 20
A boot block ____.
  1. typically only knows the location and length of the rest of the bootstrap program
  2. is composed of multiple disk blocks
  3. typically is sophisticated enough to load the operating system and begin its execution
  4. is composed of multiple disk cylinders 
Solution:
typically only knows the location and length of the rest of the bootstrap program

Tuesday, 14 August 2018

How to setup Wallet for Bitcoins

Coinpot is what is called a mircowallet and could be used through a browser.  You do not have to download any software to begin using it.

If you would like to decide to try this, only follow these steps.

Step 1:  Set Up a Coinpot Account

Make an account on coinpot.co that links to your email. Coinpot will allow you to have 5  different cryptocurrenies: Bitcoin, Bitcoin Income, Litecoin, Dash, and Dogecoin. I have properly used it to have most of these.  Here is how it seems like:

Step 2: Connect to Faucets
Faucets are websites that enable you to collect cryptocurrency free of charge (although you can find advertisements on these sites). You have to be cautious since there are a lot of fraud faucets websites on the market! 

Here are a few the the faucets that I've tried and made sure work. You will only have to login using the same mail as your Coinpot account. Many of these faucets should go straight to your Coinpot whenever you claim your coins. They are able to be claimed every 5-15 minutes.  As you do this you can develop a regular loyalty benefit if you do it everyday.

MoonDoge

Step 3: Monitor Your Coinpot
It's enjoyment to view the faucets start to grow up as you claim them.  You can even track the value of the currencies as they go up and down each day. Because I've started I have seen them move way up, way down, and then up again!
 

What are Bitcoin Faucets?

When you are new to the concept of Bitcoins the first question that pops into your mind is that where can I get Bitcoins and possibly for free! So, here the Bitcoin Faucets come to play.

Bitcoin faucets, as the name implies are like dripping sinks (taps)… but in this instance, it is cryptocurrency items rather than water. Just while the dripping water takes time to become right into a droplet before it drips, users have to attend for a specific time before they might obtain the accumulated coins.


What are bitcoin faucets?



Bitcoin faucets (it can be for just about any cryptocurrency) are incentive programs that dispenses benefits in the shape of a small fraction of bitcoin for guests to claim. These benefits are dispensed at specific times of time.

Why bitcoin faucets?

Returns have been in place to attract readers to the faucet's webpage. These faucet web sites frequently include advertisements. Advertisers spend the faucet owner to show these ads on his site. Promotion expenses are calculated on Cost per Thousand impression (CPM) basis. This implies, if the site gets more readers and if each visitor uses additional time on the site, then the site owner gets additional money from shown ads. These rewards attract more readers and they return regularly their rewards. The visitor typically eventually ends up spending additional time on the faucet.

In easy phrases — faucets get more recurring visitors to the site; subsequently, the dog owner additional money from the advertisers.

Faucets play an important position in the bitcoin ecosystem. It encourages more people to understand and follow bitcoin.

Who uses bitcoin faucets?

Using a bitcoin faucet is very simple. After you visit the faucet website, you have to enter your bitcoin wallet handle or the e-mail id associated with your CoinPot wallet and hit enter.  A timer begins checking the total amount of time you spend on the site. After you spend a certain amount of time on the site, you are able to claim your reward by clicking the “Claim Now” or similar button. You will have to demonstrate that you're a human by filling out a Captcha or by sloving a simple mathematical issue, (this prevents any computerized program from claiming rewards at standard intervals).  That's it…! You've claimed your reward. Your reward is likely to be awarded possibly straight away or on a selected regular payout day to your wallet.

Typically, faucet have a minimum time span limit between claims by each visitor, in order to prevent one individual from claiming all the available bitcoin from faucet's wallet. This length varies from five minutes to twenty four hours, based upon the faucet.

Where can I find bitcoin faucets?


You'll find them just by looking for Bitcoin faucet on Google or some other search engine of one's choice. The amount of results you get may surprise you. You may find a huge selection of bitcoin faucet to pick from, go ahead, discover and generate several satoshis while at it. (1 Satoshi = 0.00000001 BTC i.e. hundredth of a millionth BTC)

Here are several bitcoin faucet you should check out:


Conclusion

faucet are the most popular sites to help new customers understand bitcoins while making some bitcoins.