A string parameter and returns new string with all the letters of the alphabet that are not in the argument string. The letters in the returned string should be in alphabetical order. The implementation should uses a histogram from the histogram function
Explanation:
The below code is written in python :
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
def has_duplicates(s):
for v in histogram(s).values():
if v > 1:
return True
return False
def test_dups_loop():
for s in test_dups:
print(s + ':', has_duplicates(s))
def missing_letters(s):
r = list('abcdefghijklmnopqrstuvwxyz')
s = s.lower()
for c in s.lower():
if c in r:
r.remove(c) # the first matching instance
return ''.join(r)
def test_miss_loop():
for s in test_miss:
print(s + ':', missing_letters(s))
def main():
test_dups_loop()
test_miss_loop()
if __name__ == '__main__':
main()
Answer:
Sequential
Explanation:
Based on the information provided within the question it can be said that the search algorithm that is being described in this scenario is a Sequential algorithm. This is because sequential programming focuses on programming (or in this case searching for) a result by doing one step at a time as opposed to various functions running simultaneously.
Answer:
The correct usage is a NOR gate which is indicated in the explanation.
Explanation:
The truth table for the given two signals, namely
p=unplugged signal
q=low battery signal
can form a truth table of following form
Here p has 2 states
1 if the power supply is connected
0 otherwise
Similarly q has 2 states
0 if the battery has reached almost zero state
1 otherwise
As the condition for the Hibernate Signal is given as to only activate when the battery is low and the power supply is not connected. This indicate that the value of Hibernate signal should be 1 when both p and q are 0.
Using this condition, the truth table is formed as
unplugged signal | low battery signal | Hibernate Signal
0 | 0 | 1
0 | 1 | 0
1 | 0 | 0
1 | 1 | 0
Now the truth table of NOR is given as
a | b | a or b | ~(a or b)
0 | 0 | 0 | 1
0 | 1 | 1 | 0
1 | 0 | 1 | 0
1 | 1 | 1 | 0
This indicates that the both truth tables are same thus the NOR gate is to be used for this purpose.